MessageHandler.c 847 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566
  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. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1132. if(strstr((char*)start, ".") != NULL)
  1133. {
  1134. // Original data with mini second
  1135. if(strstr((char*)start, "Z") != NULL)
  1136. {
  1137. // Original data with Z
  1138. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1139. &parsingResult.year,
  1140. &parsingResult.month,
  1141. &parsingResult.mday,
  1142. &parsingResult.hour,
  1143. &parsingResult.min,
  1144. &parsingResult.sec,
  1145. &parsingResult.minSec);
  1146. }
  1147. else
  1148. {
  1149. // Original data without Z
  1150. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1151. &parsingResult.year,
  1152. &parsingResult.month,
  1153. &parsingResult.mday,
  1154. &parsingResult.hour,
  1155. &parsingResult.min,
  1156. &parsingResult.sec,
  1157. &parsingResult.minSec,
  1158. &parsingResult.tz_hour,
  1159. &parsingResult.tz_min);
  1160. }
  1161. }
  1162. else
  1163. {
  1164. // Original data without mini second
  1165. if(strstr((char*)start, "Z") != NULL)
  1166. {
  1167. // Original data with Z
  1168. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1169. &parsingResult.year,
  1170. &parsingResult.month,
  1171. &parsingResult.mday,
  1172. &parsingResult.hour,
  1173. &parsingResult.min,
  1174. &parsingResult.sec);
  1175. }
  1176. else
  1177. {
  1178. // Original data without Z
  1179. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1180. &parsingResult.year,
  1181. &parsingResult.month,
  1182. &parsingResult.mday,
  1183. &parsingResult.hour,
  1184. &parsingResult.min,
  1185. &parsingResult.sec,
  1186. &parsingResult.tz_hour,
  1187. &parsingResult.tz_min);
  1188. }
  1189. }
  1190. if(parsingResult.scanedElement >= 6)
  1191. {
  1192. tmStart.tm_year = parsingResult.year - 1900;
  1193. tmStart.tm_mon = parsingResult.month - 1;
  1194. tmStart.tm_mday = parsingResult.mday;
  1195. tmStart.tm_hour = parsingResult.hour;
  1196. tmStart.tm_min = parsingResult.min;
  1197. tmStart.tm_sec = parsingResult.sec;
  1198. tmStart.tm_gmtoff = 0;
  1199. tbStart.time = mktime(&tmStart);
  1200. tbStart.timezone = 0;
  1201. tbStart.millitm = 0;
  1202. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1203. if(DiffTimebWithNowSec(tbStart) <= 0)
  1204. result = NO;
  1205. else
  1206. result = YES;
  1207. }
  1208. else
  1209. {
  1210. DEBUG_WARN("Start date parsing error.\n");
  1211. }
  1212. return result;
  1213. }
  1214. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1215. {
  1216. int result = -1;
  1217. struct tm tmStart;
  1218. struct timeb tbStart;
  1219. struct tm tmStop;
  1220. struct timeb tbStop;
  1221. 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) &&
  1222. (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))
  1223. {
  1224. tmStart.tm_year -= 1900;
  1225. tmStart.tm_mon -= 1;
  1226. tbStart.time = mktime(&tmStart);
  1227. tbStart.millitm = 0;
  1228. tmStop.tm_year -= 1900;
  1229. tmStop.tm_mon -= 1;
  1230. tbStop.time = mktime(&tmStop);
  1231. tbStop.millitm = 0;
  1232. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1233. }
  1234. return result;
  1235. }
  1236. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1237. {
  1238. FILE *fp;
  1239. char profileFileName[128];
  1240. char *line = NULL;
  1241. size_t len = 0;
  1242. time_t CurrentTime;
  1243. struct tm *tmComposite;
  1244. struct StructChargingProfile maxProfile;
  1245. uint8_t limitMax=0;
  1246. int compositePeriodIdx = 0;
  1247. CurrentTime = time(NULL);
  1248. tmComposite=localtime(&CurrentTime);
  1249. 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);
  1250. if(isUnitA)
  1251. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1252. else
  1253. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1254. compositeProfile->ChargingSchedule.Duration = durationReq;
  1255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1256. {
  1257. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1258. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1259. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1260. }
  1261. compositeProfile->ChargingProfileId = 0;
  1262. compositeProfile->StackLevel = 99 ;
  1263. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1264. maxProfile.ChargingProfileId = -1;
  1265. maxProfile.ChargingSchedule.Duration = -1;
  1266. system("rm -f /tmp/*.json");
  1267. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1268. // Search max profile
  1269. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1270. if((access(profileFileName, F_OK))!=-1)
  1271. {
  1272. fp = fopen(profileFileName, "r");
  1273. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1274. {
  1275. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1277. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1278. }
  1279. maxProfile.ChargingProfileId = -1;
  1280. maxProfile.StackLevel = -1;
  1281. while(getline(&line, &len, fp) != -1)
  1282. {
  1283. json_object *obj = NULL;
  1284. obj = json_tokener_parse(line);
  1285. if(is_error(obj))
  1286. {
  1287. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1288. }
  1289. else
  1290. {
  1291. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1292. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1293. )
  1294. {
  1295. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1296. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1297. )
  1298. {
  1299. struct tm tmFrom, tmTo;
  1300. struct timeb tbFrom, tbTo;
  1301. 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) &&
  1302. (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))
  1303. {
  1304. tmFrom.tm_year -= 1900;
  1305. tmFrom.tm_mon -= 1;
  1306. tbFrom.time = mktime(&tmFrom);
  1307. tmTo.tm_year -= 1900;
  1308. tmTo.tm_mon -= 1;
  1309. tbTo.time = mktime(&tmTo);
  1310. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1311. {
  1312. if(maxProfile.ChargingProfileId == -1)
  1313. DEBUG_INFO("MaxProfile found.\n");
  1314. else
  1315. DEBUG_INFO("MaxProfile updated.\n");
  1316. // Required item
  1317. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1318. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1319. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1320. if(isUnitA)
  1321. {
  1322. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1323. 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++)
  1324. {
  1325. 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"));
  1326. 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?
  1327. 3:
  1328. 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")));
  1329. 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")));
  1330. }
  1331. }
  1332. else
  1333. {
  1334. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1335. 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++)
  1336. {
  1337. 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"));
  1338. 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?
  1339. 3:
  1340. 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")));
  1341. 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));
  1342. }
  1343. }
  1344. // Optional item
  1345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1346. {
  1347. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1348. }
  1349. else
  1350. {
  1351. sprintf((char*)maxProfile.ValidFrom, " ");
  1352. }
  1353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1354. {
  1355. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1356. }
  1357. else
  1358. {
  1359. sprintf((char*)maxProfile.ValidTo, " ");
  1360. }
  1361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1362. {
  1363. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1364. }
  1365. else
  1366. {
  1367. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1368. }
  1369. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1370. {
  1371. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1372. }
  1373. else
  1374. {
  1375. maxProfile.TransactionId = -1;
  1376. }
  1377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1378. {
  1379. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1380. }
  1381. else
  1382. {
  1383. maxProfile.ChargingSchedule.Duration = 86400;
  1384. }
  1385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1386. {
  1387. 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")));
  1388. }
  1389. else
  1390. {
  1391. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1392. }
  1393. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1394. {
  1395. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1396. }
  1397. else
  1398. {
  1399. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1400. }
  1401. }
  1402. }
  1403. }
  1404. else
  1405. {
  1406. if(maxProfile.ChargingProfileId == -1)
  1407. DEBUG_INFO("MaxProfile found.\n");
  1408. else
  1409. DEBUG_INFO("MaxProfile updated.\n");
  1410. // Required item
  1411. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1412. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1413. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1414. if(isUnitA)
  1415. {
  1416. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1417. 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++)
  1418. {
  1419. 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"));
  1420. 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?
  1421. 3:
  1422. 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")));
  1423. 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")));
  1424. }
  1425. }
  1426. else
  1427. {
  1428. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1429. 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++)
  1430. {
  1431. 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"));
  1432. 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?
  1433. 3:
  1434. 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")));
  1435. 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));
  1436. }
  1437. }
  1438. // Optional item
  1439. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1440. {
  1441. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1442. }
  1443. else
  1444. {
  1445. sprintf((char*)maxProfile.ValidFrom, " ");
  1446. }
  1447. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1448. {
  1449. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1450. }
  1451. else
  1452. {
  1453. sprintf((char*)maxProfile.ValidTo, " ");
  1454. }
  1455. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1456. {
  1457. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1462. }
  1463. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1464. {
  1465. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1466. }
  1467. else
  1468. {
  1469. maxProfile.TransactionId = -1;
  1470. }
  1471. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1472. {
  1473. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1474. }
  1475. else
  1476. {
  1477. maxProfile.ChargingSchedule.Duration = 86400;
  1478. }
  1479. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1480. {
  1481. 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")));
  1482. }
  1483. else
  1484. {
  1485. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1486. }
  1487. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1488. {
  1489. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1490. }
  1491. else
  1492. {
  1493. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1494. }
  1495. }
  1496. }
  1497. }
  1498. json_object_put(obj);
  1499. }
  1500. fclose(fp);
  1501. /*
  1502. if(maxProfile.ChargingProfileId !=-1)
  1503. {
  1504. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1505. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1506. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1507. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1508. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1509. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1510. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1511. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1512. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1513. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1514. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1516. {
  1517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1518. {
  1519. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1520. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1521. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1522. }
  1523. }
  1524. }
  1525. else
  1526. DEBUG_INFO("MaxProfile not found.\n");
  1527. DEBUG_INFO("------------------------------------\n");*/
  1528. }
  1529. if(maxProfile.ChargingProfileId != -1)
  1530. {
  1531. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1532. {
  1533. if(maxProfile.ChargingSchedule.Duration != -1)
  1534. {
  1535. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1536. 0:
  1537. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1538. }
  1539. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1540. {
  1541. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1542. {
  1543. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1544. 0:
  1545. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1546. if(idxPeriod > 0)
  1547. {
  1548. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1549. {
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1551. }
  1552. }
  1553. }
  1554. }
  1555. }
  1556. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1557. {
  1558. if(maxProfile.ChargingSchedule.Duration != -1)
  1559. {
  1560. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1561. }
  1562. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1563. {
  1564. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1565. {
  1566. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1567. if(idxPeriod > 0)
  1568. {
  1569. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1570. {
  1571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577. else
  1578. {
  1579. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1580. {
  1581. if(maxProfile.ChargingSchedule.Duration != -1)
  1582. {
  1583. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1584. 0:
  1585. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1586. }
  1587. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1588. {
  1589. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1590. {
  1591. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1592. 0:
  1593. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1594. if(idxPeriod > 0)
  1595. {
  1596. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1597. {
  1598. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1599. }
  1600. }
  1601. }
  1602. }
  1603. }
  1604. else
  1605. {
  1606. if(maxProfile.ChargingSchedule.Duration != -1)
  1607. {
  1608. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1609. 0:
  1610. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1611. }
  1612. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1613. {
  1614. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1615. {
  1616. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1617. 0:
  1618. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1619. if(idxPeriod > 0)
  1620. {
  1621. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1622. {
  1623. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
  1629. }
  1630. /*
  1631. DEBUG_INFO("MaxProfile after align.\n");
  1632. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1633. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1634. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1635. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1636. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1637. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1638. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1639. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1640. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1641. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1642. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1643. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1644. {
  1645. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1646. {
  1647. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1648. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1649. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1650. }
  1651. }
  1652. DEBUG_INFO("------------------------------------\n");*/
  1653. }
  1654. // Find each profile period quantity
  1655. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1656. {
  1657. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1658. limitMax = idx+1;
  1659. }
  1660. if(maxProfile.ChargingProfileId != -1)
  1661. {
  1662. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1663. {
  1664. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1665. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1666. (maxProfile.ChargingSchedule.Duration > 0))
  1667. {
  1668. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1669. {
  1670. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1671. compositePeriodIdx++;
  1672. }
  1673. else
  1674. {
  1675. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1676. }
  1677. }
  1678. }
  1679. }
  1680. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1681. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1682. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1683. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1684. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1685. {
  1686. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1687. {
  1688. compositeProfile->ChargingProfileId = 1;
  1689. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1690. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1691. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1692. }
  1693. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1694. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1695. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1696. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1697. }
  1698. if(line)
  1699. free(line);
  1700. }
  1701. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1702. {
  1703. FILE *fp;
  1704. char profileFileName[128];
  1705. char *line = NULL;
  1706. size_t len = 0;
  1707. time_t CurrentTime;
  1708. struct tm *tmComposite;
  1709. struct StructChargingProfile maxProfile;
  1710. struct StructChargingProfile defaultTxProfile;
  1711. struct StructChargingProfile txProfile;
  1712. struct StructChargingSchedulePeriod tmpPeriod;
  1713. uint8_t limitMax=0;
  1714. uint8_t limitDef=0;
  1715. uint8_t limitTx=0;
  1716. int compositePeriodIdx = 0;
  1717. CurrentTime = time(NULL);
  1718. tmComposite=localtime(&CurrentTime);
  1719. 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);
  1720. if(isUnitA)
  1721. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1722. else
  1723. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1724. compositeProfile->ChargingSchedule.Duration = durationReq;
  1725. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1726. {
  1727. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1728. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1729. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1730. }
  1731. compositeProfile->ChargingProfileId = 0;
  1732. compositeProfile->StackLevel = 99 ;
  1733. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1734. maxProfile.ChargingProfileId = -1;
  1735. defaultTxProfile.ChargingProfileId = -1;
  1736. txProfile.ChargingProfileId = -1;
  1737. maxProfile.ChargingSchedule.Duration = -1;
  1738. defaultTxProfile.ChargingSchedule.Duration = -1;
  1739. txProfile.ChargingSchedule.Duration = -1;
  1740. system("rm -f /tmp/*.json");
  1741. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1742. /*
  1743. * Search valid charging profile
  1744. */
  1745. //DEBUG_INFO("====================================\n");
  1746. // Search tx profile
  1747. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1748. if((access(profileFileName, F_OK))!=-1)
  1749. {
  1750. fp = fopen(profileFileName, "r");
  1751. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1752. {
  1753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1755. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1756. }
  1757. txProfile.ChargingProfileId = -1;
  1758. txProfile.StackLevel = -1;
  1759. while(getline(&line, &len, fp) != -1)
  1760. {
  1761. json_object *obj = NULL;
  1762. obj = json_tokener_parse(line);
  1763. if(is_error(obj))
  1764. {
  1765. DEBUG_ERROR("Parse txProfile from file error.\n");
  1766. }
  1767. else
  1768. {
  1769. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1770. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1771. )
  1772. {
  1773. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1774. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1775. )
  1776. {
  1777. struct tm tmFrom, tmTo;
  1778. struct timeb tbFrom, tbTo;
  1779. 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) &&
  1780. (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))
  1781. {
  1782. tmFrom.tm_year -= 1900;
  1783. tmFrom.tm_mon -= 1;
  1784. tbFrom.time = mktime(&tmFrom);
  1785. tmTo.tm_year -= 1900;
  1786. tmTo.tm_mon -= 1;
  1787. tbTo.time = mktime(&tmTo);
  1788. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1789. {
  1790. if(txProfile.ChargingProfileId == -1)
  1791. DEBUG_INFO("TxProfile found.\n");
  1792. else
  1793. DEBUG_INFO("TxProfile updated.\n");
  1794. // Required item
  1795. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1796. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1797. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1798. if(isUnitA)
  1799. {
  1800. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1801. 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++)
  1802. {
  1803. 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"));
  1804. 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?
  1805. 3:
  1806. 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")));
  1807. 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")));
  1808. }
  1809. }
  1810. else
  1811. {
  1812. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1813. 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++)
  1814. {
  1815. 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"));
  1816. 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?
  1817. 3:
  1818. 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")));
  1819. 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));
  1820. }
  1821. }
  1822. // Optional item
  1823. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1824. {
  1825. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1826. }
  1827. else
  1828. {
  1829. sprintf((char*)txProfile.ValidFrom, " ");
  1830. }
  1831. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1832. {
  1833. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1834. }
  1835. else
  1836. {
  1837. sprintf((char*)txProfile.ValidTo, " ");
  1838. }
  1839. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1840. {
  1841. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1842. }
  1843. else
  1844. {
  1845. sprintf((char*)txProfile.RecurrencyKind, " ");
  1846. }
  1847. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1848. {
  1849. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1850. }
  1851. else
  1852. {
  1853. txProfile.TransactionId = -1;
  1854. }
  1855. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1856. {
  1857. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1858. }
  1859. else
  1860. {
  1861. txProfile.ChargingSchedule.Duration = 86400;
  1862. }
  1863. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1864. {
  1865. 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")));
  1866. }
  1867. else
  1868. {
  1869. 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));
  1870. }
  1871. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1872. {
  1873. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1874. }
  1875. else
  1876. {
  1877. txProfile.ChargingSchedule.MinChargingRate = -1;
  1878. }
  1879. }
  1880. }
  1881. }
  1882. else
  1883. {
  1884. if(txProfile.ChargingProfileId == -1)
  1885. DEBUG_INFO("TxProfile found.\n");
  1886. else
  1887. DEBUG_INFO("TxProfile updated.\n");
  1888. // Required item
  1889. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1890. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1891. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1892. if(isUnitA)
  1893. {
  1894. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1895. 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++)
  1896. {
  1897. 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"));
  1898. 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?
  1899. 3:
  1900. 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")));
  1901. 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")));
  1902. }
  1903. }
  1904. else
  1905. {
  1906. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1907. 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++)
  1908. {
  1909. 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"));
  1910. 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?
  1911. 3:
  1912. 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")));
  1913. 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));
  1914. }
  1915. }
  1916. // Optional item
  1917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1918. {
  1919. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1920. }
  1921. else
  1922. {
  1923. sprintf((char*)txProfile.ValidFrom, " ");
  1924. }
  1925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1926. {
  1927. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1928. }
  1929. else
  1930. {
  1931. sprintf((char*)txProfile.ValidTo, " ");
  1932. }
  1933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1934. {
  1935. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1936. }
  1937. else
  1938. {
  1939. sprintf((char*)txProfile.RecurrencyKind, " ");
  1940. }
  1941. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1942. {
  1943. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1944. }
  1945. else
  1946. {
  1947. txProfile.TransactionId = -1;
  1948. }
  1949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1950. {
  1951. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1952. }
  1953. else
  1954. {
  1955. txProfile.ChargingSchedule.Duration = 86400;
  1956. }
  1957. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1958. {
  1959. 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")));
  1960. }
  1961. else
  1962. {
  1963. 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));
  1964. }
  1965. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1966. {
  1967. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1968. }
  1969. else
  1970. {
  1971. txProfile.ChargingSchedule.MinChargingRate = -1;
  1972. }
  1973. }
  1974. }
  1975. }
  1976. json_object_put(obj);
  1977. }
  1978. fclose(fp);
  1979. /*
  1980. if(txProfile.ChargingProfileId != -1)
  1981. {
  1982. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1983. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1984. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1985. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1986. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1987. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1988. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1989. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1990. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1991. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1992. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1993. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1994. {
  1995. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1996. {
  1997. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1998. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1999. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2000. }
  2001. }
  2002. }
  2003. else
  2004. DEBUG_INFO("TxProfile not found.\n");*/
  2005. }
  2006. // Search default tx profile
  2007. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2008. if((access(profileFileName, F_OK))==-1)
  2009. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2010. if((access(profileFileName, F_OK))!=-1)
  2011. {
  2012. fp = fopen(profileFileName, "r");
  2013. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2014. {
  2015. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2016. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2017. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2018. }
  2019. defaultTxProfile.ChargingProfileId = -1;
  2020. defaultTxProfile.StackLevel = -1;
  2021. while(getline(&line, &len, fp) != -1)
  2022. {
  2023. json_object *obj = NULL;
  2024. obj = json_tokener_parse(line);
  2025. if(is_error(obj))
  2026. {
  2027. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2028. }
  2029. else
  2030. {
  2031. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2032. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2033. )
  2034. {
  2035. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2036. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2037. )
  2038. {
  2039. struct tm tmFrom, tmTo;
  2040. struct timeb tbFrom, tbTo;
  2041. 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) &&
  2042. (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))
  2043. {
  2044. tmFrom.tm_year -= 1900;
  2045. tmFrom.tm_mon -= 1;
  2046. tbFrom.time = mktime(&tmFrom);
  2047. tmTo.tm_year -= 1900;
  2048. tmTo.tm_mon -= 1;
  2049. tbTo.time = mktime(&tmTo);
  2050. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2051. {
  2052. if(defaultTxProfile.ChargingProfileId == -1)
  2053. DEBUG_INFO("TxDefaultProfile found.\n");
  2054. else
  2055. DEBUG_INFO("TxDefaultProfile updated.\n");
  2056. // Required item
  2057. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2058. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2059. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2060. if(isUnitA)
  2061. {
  2062. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2063. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2064. {
  2065. 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"));
  2066. 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?
  2067. 3:
  2068. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2069. 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")));
  2070. }
  2071. }
  2072. else
  2073. {
  2074. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2075. 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++)
  2076. {
  2077. 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"));
  2078. 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?
  2079. 3:
  2080. 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")));
  2081. 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));
  2082. }
  2083. }
  2084. // Optional item
  2085. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2086. {
  2087. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2088. }
  2089. else
  2090. {
  2091. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2092. }
  2093. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2094. {
  2095. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2096. }
  2097. else
  2098. {
  2099. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2100. }
  2101. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2102. {
  2103. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2104. }
  2105. else
  2106. {
  2107. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2108. }
  2109. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2110. {
  2111. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2112. }
  2113. else
  2114. {
  2115. defaultTxProfile.TransactionId = -1;
  2116. }
  2117. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2118. {
  2119. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2120. }
  2121. else
  2122. {
  2123. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2124. }
  2125. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2126. {
  2127. 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")));
  2128. }
  2129. else
  2130. {
  2131. 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));
  2132. }
  2133. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2134. {
  2135. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2136. }
  2137. else
  2138. {
  2139. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2140. }
  2141. }
  2142. }
  2143. }
  2144. else
  2145. {
  2146. if(defaultTxProfile.ChargingProfileId == -1)
  2147. DEBUG_INFO("TxDefaultProfile found.\n");
  2148. else
  2149. DEBUG_INFO("TxDefaultProfile updated.\n");
  2150. // Required item
  2151. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2152. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2153. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2154. if(isUnitA)
  2155. {
  2156. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2157. 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++)
  2158. {
  2159. 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"));
  2160. 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?
  2161. 3:
  2162. 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")));
  2163. 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")));
  2164. }
  2165. }
  2166. else
  2167. {
  2168. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2169. 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++)
  2170. {
  2171. 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"));
  2172. 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?
  2173. 3:
  2174. 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")));
  2175. 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));
  2176. }
  2177. }
  2178. // Optional item
  2179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2180. {
  2181. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2182. }
  2183. else
  2184. {
  2185. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2186. }
  2187. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2188. {
  2189. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2190. }
  2191. else
  2192. {
  2193. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2194. }
  2195. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2196. {
  2197. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2198. }
  2199. else
  2200. {
  2201. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2202. }
  2203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2204. {
  2205. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2206. }
  2207. else
  2208. {
  2209. defaultTxProfile.TransactionId = -1;
  2210. }
  2211. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2212. {
  2213. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2214. }
  2215. else
  2216. {
  2217. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2218. }
  2219. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2220. {
  2221. 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")));
  2222. }
  2223. else
  2224. {
  2225. 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));
  2226. }
  2227. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2228. {
  2229. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2230. }
  2231. else
  2232. {
  2233. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2234. }
  2235. }
  2236. }
  2237. }
  2238. json_object_put(obj);
  2239. }
  2240. fclose(fp);
  2241. /*
  2242. if(defaultTxProfile.ChargingProfileId != -1)
  2243. {
  2244. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2245. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2246. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2247. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2248. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2249. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2250. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2251. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2252. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2253. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2254. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2256. {
  2257. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2258. {
  2259. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2260. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2261. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2262. }
  2263. }
  2264. }
  2265. else
  2266. DEBUG_INFO("TxDefaultProfile not found.\n");
  2267. DEBUG_INFO("------------------------------------\n");*/
  2268. }
  2269. // Search max profile
  2270. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2271. if((access(profileFileName, F_OK))!=-1)
  2272. {
  2273. fp = fopen(profileFileName, "r");
  2274. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2275. {
  2276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2277. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2278. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2279. }
  2280. maxProfile.ChargingProfileId = -1;
  2281. maxProfile.StackLevel = -1;
  2282. while(getline(&line, &len, fp) != -1)
  2283. {
  2284. json_object *obj = NULL;
  2285. obj = json_tokener_parse(line);
  2286. if(is_error(obj))
  2287. {
  2288. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2289. }
  2290. else
  2291. {
  2292. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2293. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2294. )
  2295. {
  2296. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2297. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2298. )
  2299. {
  2300. struct tm tmFrom, tmTo;
  2301. struct timeb tbFrom, tbTo;
  2302. 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) &&
  2303. (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))
  2304. {
  2305. tmFrom.tm_year -= 1900;
  2306. tmFrom.tm_mon -= 1;
  2307. tbFrom.time = mktime(&tmFrom);
  2308. tmTo.tm_year -= 1900;
  2309. tmTo.tm_mon -= 1;
  2310. tbTo.time = mktime(&tmTo);
  2311. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2312. {
  2313. if(maxProfile.ChargingProfileId == -1)
  2314. DEBUG_INFO("MaxProfile found.\n");
  2315. else
  2316. DEBUG_INFO("MaxProfile updated.\n");
  2317. // Required item
  2318. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2319. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2320. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2321. if(isUnitA)
  2322. {
  2323. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2324. 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++)
  2325. {
  2326. 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"));
  2327. 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?
  2328. 3:
  2329. 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")));
  2330. 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")));
  2331. }
  2332. }
  2333. else
  2334. {
  2335. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2336. 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++)
  2337. {
  2338. 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"));
  2339. 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?
  2340. 3:
  2341. 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")));
  2342. 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));
  2343. }
  2344. }
  2345. // Optional item
  2346. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2347. {
  2348. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2349. }
  2350. else
  2351. {
  2352. sprintf((char*)maxProfile.ValidFrom, " ");
  2353. }
  2354. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2355. {
  2356. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2357. }
  2358. else
  2359. {
  2360. sprintf((char*)maxProfile.ValidTo, " ");
  2361. }
  2362. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2363. {
  2364. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2365. }
  2366. else
  2367. {
  2368. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2369. }
  2370. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2371. {
  2372. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2373. }
  2374. else
  2375. {
  2376. maxProfile.TransactionId = -1;
  2377. }
  2378. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2379. {
  2380. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2381. }
  2382. else
  2383. {
  2384. maxProfile.ChargingSchedule.Duration = 86400;
  2385. }
  2386. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2387. {
  2388. 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")));
  2389. }
  2390. else
  2391. {
  2392. 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));
  2393. }
  2394. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2395. {
  2396. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2397. }
  2398. else
  2399. {
  2400. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2401. }
  2402. }
  2403. }
  2404. }
  2405. else
  2406. {
  2407. if(maxProfile.ChargingProfileId == -1)
  2408. DEBUG_INFO("MaxProfile found.\n");
  2409. else
  2410. DEBUG_INFO("MaxProfile updated.\n");
  2411. // Required item
  2412. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2413. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2414. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2415. if(isUnitA)
  2416. {
  2417. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2418. 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++)
  2419. {
  2420. 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"));
  2421. 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?
  2422. 3:
  2423. 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")));
  2424. 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")));
  2425. }
  2426. }
  2427. else
  2428. {
  2429. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2430. 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++)
  2431. {
  2432. 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"));
  2433. 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?
  2434. 3:
  2435. 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")));
  2436. 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));
  2437. }
  2438. }
  2439. // Optional item
  2440. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2441. {
  2442. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2443. }
  2444. else
  2445. {
  2446. sprintf((char*)maxProfile.ValidFrom, " ");
  2447. }
  2448. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2449. {
  2450. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2451. }
  2452. else
  2453. {
  2454. sprintf((char*)maxProfile.ValidTo, " ");
  2455. }
  2456. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2457. {
  2458. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2459. }
  2460. else
  2461. {
  2462. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2463. }
  2464. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2465. {
  2466. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2467. }
  2468. else
  2469. {
  2470. maxProfile.TransactionId = -1;
  2471. }
  2472. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2473. {
  2474. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2475. }
  2476. else
  2477. {
  2478. maxProfile.ChargingSchedule.Duration = 86400;
  2479. }
  2480. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2481. {
  2482. 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")));
  2483. }
  2484. else
  2485. {
  2486. 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));
  2487. }
  2488. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2489. {
  2490. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2491. }
  2492. else
  2493. {
  2494. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2495. }
  2496. }
  2497. }
  2498. }
  2499. json_object_put(obj);
  2500. }
  2501. fclose(fp);
  2502. /*
  2503. if(maxProfile.ChargingProfileId !=-1)
  2504. {
  2505. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2506. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2507. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2508. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2509. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2510. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2511. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2512. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2513. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2514. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2515. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2516. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2517. {
  2518. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2519. {
  2520. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2521. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2522. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2523. }
  2524. }
  2525. }
  2526. else
  2527. DEBUG_INFO("MaxProfile not found.\n");
  2528. DEBUG_INFO("------------------------------------\n");*/
  2529. }
  2530. /*
  2531. * Align found profile start schedule & periods
  2532. */
  2533. //DEBUG_INFO("====================================\n");
  2534. /*
  2535. // For local test usage, force modify found profile start schedule info
  2536. 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);
  2537. 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);
  2538. 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);
  2539. */
  2540. if(txProfile.ChargingProfileId != -1)
  2541. {
  2542. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2543. {
  2544. if(txProfile.ChargingSchedule.Duration != -1)
  2545. {
  2546. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2547. 0:
  2548. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2549. }
  2550. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2551. {
  2552. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2553. {
  2554. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2555. 0:
  2556. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2557. if(idxPeriod > 0)
  2558. {
  2559. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2560. {
  2561. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2562. }
  2563. }
  2564. }
  2565. }
  2566. }
  2567. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2568. {
  2569. if(txProfile.ChargingSchedule.Duration != -1)
  2570. {
  2571. 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?
  2572. 0:
  2573. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2574. }
  2575. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2576. {
  2577. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2578. {
  2579. 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?
  2580. 0:
  2581. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2582. if(idxPeriod > 0)
  2583. {
  2584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2585. {
  2586. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2587. }
  2588. }
  2589. }
  2590. }
  2591. }
  2592. else
  2593. {
  2594. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2595. {
  2596. if(txProfile.ChargingSchedule.Duration != -1)
  2597. {
  2598. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2599. 0:
  2600. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2601. }
  2602. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2603. {
  2604. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2605. {
  2606. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2607. 0:
  2608. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2609. if(idxPeriod > 0)
  2610. {
  2611. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2612. {
  2613. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2614. }
  2615. }
  2616. }
  2617. }
  2618. }
  2619. else
  2620. {
  2621. if(txProfile.ChargingSchedule.Duration != -1)
  2622. {
  2623. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2624. 0:
  2625. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2626. }
  2627. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2628. {
  2629. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2630. {
  2631. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2632. 0:
  2633. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2634. if(idxPeriod > 0)
  2635. {
  2636. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2637. {
  2638. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. }
  2645. /*
  2646. DEBUG_INFO("txProfile after align.\n");
  2647. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2648. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2649. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2650. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2651. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2652. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2653. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2654. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2655. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2656. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2657. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2658. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2659. {
  2660. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2661. {
  2662. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2663. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2664. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2665. }
  2666. }*/
  2667. }
  2668. if(defaultTxProfile.ChargingProfileId != -1)
  2669. {
  2670. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2671. {
  2672. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2673. {
  2674. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2675. 0:
  2676. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2677. }
  2678. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2679. {
  2680. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2681. {
  2682. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2683. 0:
  2684. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2685. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2686. {
  2687. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2688. }
  2689. if(idxPeriod > 0)
  2690. {
  2691. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2692. {
  2693. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2694. }
  2695. }
  2696. }
  2697. }
  2698. }
  2699. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2700. {
  2701. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2702. {
  2703. 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?
  2704. 0:
  2705. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2706. }
  2707. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2708. {
  2709. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2710. {
  2711. 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?
  2712. 0:
  2713. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2714. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2715. {
  2716. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2717. }
  2718. if(idxPeriod > 0)
  2719. {
  2720. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2721. {
  2722. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2723. }
  2724. }
  2725. }
  2726. }
  2727. }
  2728. else
  2729. {
  2730. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2731. {
  2732. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2733. {
  2734. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2735. 0:
  2736. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2737. }
  2738. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2739. {
  2740. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2741. {
  2742. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2743. 0:
  2744. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2745. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2746. {
  2747. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2748. }
  2749. if(idxPeriod > 0)
  2750. {
  2751. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2752. {
  2753. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2754. }
  2755. }
  2756. }
  2757. }
  2758. }
  2759. else
  2760. {
  2761. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2762. {
  2763. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2764. 0:
  2765. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2766. }
  2767. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2768. {
  2769. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2770. {
  2771. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2772. 0:
  2773. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2774. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2775. {
  2776. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2777. }
  2778. if(idxPeriod > 0)
  2779. {
  2780. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2781. {
  2782. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2783. }
  2784. }
  2785. }
  2786. }
  2787. }
  2788. }
  2789. /*
  2790. DEBUG_INFO("defaultTxProfile after align.\n");
  2791. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2792. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2793. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2794. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2795. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2796. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2797. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2798. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2799. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2800. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2801. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2802. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2803. {
  2804. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2805. {
  2806. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2807. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2808. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2809. }
  2810. }
  2811. DEBUG_INFO("------------------------------------\n");*/
  2812. }
  2813. if(maxProfile.ChargingProfileId != -1)
  2814. {
  2815. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2816. {
  2817. if(maxProfile.ChargingSchedule.Duration != -1)
  2818. {
  2819. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2820. 0:
  2821. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2822. }
  2823. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2824. {
  2825. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2826. {
  2827. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2828. 0:
  2829. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2830. if(idxPeriod > 0)
  2831. {
  2832. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2833. {
  2834. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2835. }
  2836. }
  2837. }
  2838. }
  2839. }
  2840. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2841. {
  2842. if(maxProfile.ChargingSchedule.Duration != -1)
  2843. {
  2844. 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?
  2845. 0:
  2846. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2847. }
  2848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2849. {
  2850. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2851. {
  2852. 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?
  2853. 0:
  2854. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2855. if(idxPeriod > 0)
  2856. {
  2857. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2858. {
  2859. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2860. }
  2861. }
  2862. }
  2863. }
  2864. }
  2865. else
  2866. {
  2867. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2868. {
  2869. if(maxProfile.ChargingSchedule.Duration != -1)
  2870. {
  2871. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2872. 0:
  2873. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2874. }
  2875. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2876. {
  2877. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2878. {
  2879. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2880. 0:
  2881. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2882. if(idxPeriod > 0)
  2883. {
  2884. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2885. {
  2886. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2887. }
  2888. }
  2889. }
  2890. }
  2891. }
  2892. else
  2893. {
  2894. if(maxProfile.ChargingSchedule.Duration != -1)
  2895. {
  2896. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2897. 0:
  2898. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2899. }
  2900. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2901. {
  2902. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2903. {
  2904. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2905. 0:
  2906. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2907. if(idxPeriod > 0)
  2908. {
  2909. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2910. {
  2911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. }
  2918. /*
  2919. DEBUG_INFO("MaxProfile after align.\n");
  2920. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2921. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2922. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2923. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2924. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2925. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2926. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2927. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2928. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2929. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2930. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2931. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2932. {
  2933. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2934. {
  2935. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2936. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2937. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2938. }
  2939. }
  2940. DEBUG_INFO("------------------------------------\n");*/
  2941. }
  2942. /*
  2943. * Merge to conposite schedule
  2944. */
  2945. //DEBUG_INFO("====================================\n");
  2946. // Find each profile period quantity
  2947. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2948. {
  2949. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2950. limitMax = idx+1;
  2951. }
  2952. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2953. {
  2954. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2955. limitDef = idx+1;
  2956. }
  2957. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2958. {
  2959. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2960. limitTx = idx+1;
  2961. }
  2962. // TxProfile found, composite schedule based on it
  2963. if(txProfile.ChargingProfileId != -1)
  2964. {
  2965. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2966. {
  2967. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2968. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2969. (txProfile.ChargingSchedule.Duration > 0))
  2970. {
  2971. if(maxProfile.ChargingProfileId != -1)
  2972. {
  2973. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2974. {
  2975. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2976. {
  2977. if((maxProfile.ChargingSchedule.Duration > 0))
  2978. {
  2979. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2980. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2981. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2982. }
  2983. else
  2984. {
  2985. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2986. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2987. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2988. }
  2989. }
  2990. if(idxMaxPeriod == (limitMax-1))
  2991. {
  2992. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2993. {
  2994. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2995. {
  2996. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2997. compositePeriodIdx++;
  2998. }
  2999. else
  3000. {
  3001. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3002. }
  3003. }
  3004. }
  3005. }
  3006. }
  3007. else
  3008. {
  3009. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3010. {
  3011. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3012. compositePeriodIdx++;
  3013. }
  3014. else
  3015. {
  3016. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3017. }
  3018. }
  3019. }
  3020. if(idxTxPeriod == (limitTx-1))
  3021. {
  3022. if(defaultTxProfile.ChargingProfileId != -1)
  3023. {
  3024. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3025. {
  3026. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3027. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3028. (defaultTxProfile.ChargingSchedule.Duration>0))
  3029. {
  3030. if(maxProfile.ChargingProfileId != -1)
  3031. {
  3032. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3033. {
  3034. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3035. {
  3036. if((maxProfile.ChargingSchedule.Duration > 0))
  3037. {
  3038. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3039. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3040. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3041. }
  3042. else
  3043. {
  3044. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3045. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3046. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3047. }
  3048. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3049. {
  3050. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3051. {
  3052. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3053. compositePeriodIdx++;
  3054. }
  3055. else
  3056. {
  3057. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3058. }
  3059. }
  3060. // Delete duplicate period
  3061. if(compositePeriodIdx > 1)
  3062. {
  3063. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3064. {
  3065. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3066. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3067. compositePeriodIdx -= 1;
  3068. }
  3069. }
  3070. }
  3071. else
  3072. break;
  3073. }
  3074. }
  3075. else
  3076. {
  3077. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3078. {
  3079. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3080. compositePeriodIdx++;
  3081. }
  3082. else
  3083. {
  3084. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3085. }
  3086. }
  3087. }
  3088. }
  3089. }
  3090. }
  3091. }
  3092. }
  3093. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3094. else if(defaultTxProfile.ChargingProfileId != -1)
  3095. {
  3096. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3097. {
  3098. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3099. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3100. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3101. {
  3102. if(maxProfile.ChargingProfileId != -1)
  3103. {
  3104. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3105. {
  3106. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3107. {
  3108. if((maxProfile.ChargingSchedule.Duration > 0))
  3109. {
  3110. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3111. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3112. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3113. }
  3114. else
  3115. {
  3116. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3117. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3118. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3119. }
  3120. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3121. {
  3122. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3123. {
  3124. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3125. compositePeriodIdx++;
  3126. }
  3127. else
  3128. {
  3129. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3130. }
  3131. }
  3132. // Delete duplicate period
  3133. if(compositePeriodIdx > 1)
  3134. {
  3135. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3136. {
  3137. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3138. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3139. compositePeriodIdx -= 1;
  3140. }
  3141. }
  3142. }
  3143. else
  3144. break;
  3145. }
  3146. }
  3147. else
  3148. {
  3149. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3150. {
  3151. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3152. compositePeriodIdx++;
  3153. }
  3154. else
  3155. {
  3156. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3157. }
  3158. }
  3159. }
  3160. }
  3161. }
  3162. // Fill other period by MaxProfile
  3163. if(maxProfile.ChargingProfileId != -1)
  3164. {
  3165. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3166. {
  3167. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3168. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3169. (maxProfile.ChargingSchedule.Duration > 0))
  3170. {
  3171. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  3172. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3173. {
  3174. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  3175. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  3176. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3177. }
  3178. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3179. {
  3180. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  3181. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3182. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3183. }
  3184. if(tmpPeriod.Limit != -1)
  3185. {
  3186. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3187. {
  3188. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3189. {
  3190. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3191. compositePeriodIdx++;
  3192. }
  3193. else
  3194. {
  3195. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3196. }
  3197. }
  3198. // Delete duplicate period
  3199. if(compositePeriodIdx > 1)
  3200. {
  3201. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3202. {
  3203. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3204. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3205. compositePeriodIdx -= 1;
  3206. }
  3207. }
  3208. }
  3209. }
  3210. }
  3211. }
  3212. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3213. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3214. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3215. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3216. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3217. {
  3218. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3219. {
  3220. compositeProfile->ChargingProfileId = 1;
  3221. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3222. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3223. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3224. }
  3225. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3226. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3227. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3228. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3229. }
  3230. if(line)
  3231. free(line);
  3232. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3233. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3234. }
  3235. //==========================================
  3236. // Init all share memory
  3237. //==========================================
  3238. int InitShareMemory()
  3239. {
  3240. int result = PASS;
  3241. int MeterSMId;
  3242. //creat ShmSysConfigAndInfo
  3243. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3244. {
  3245. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3246. result = FAIL;
  3247. }
  3248. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3249. {
  3250. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3251. result = FAIL;
  3252. }
  3253. else
  3254. {}
  3255. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3256. {
  3257. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3258. result = FAIL;
  3259. }
  3260. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3261. {
  3262. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3263. result = FAIL;
  3264. }
  3265. else
  3266. {}
  3267. //creat ShmPsuData
  3268. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3269. {
  3270. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3271. result = FAIL;
  3272. }
  3273. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3274. {
  3275. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3276. result = FAIL;
  3277. }
  3278. else
  3279. {}
  3280. //creat ShmOCPP16Data
  3281. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3282. {
  3283. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3284. result = FAIL;
  3285. }
  3286. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3287. {
  3288. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3289. result = FAIL;
  3290. }
  3291. else
  3292. {}
  3293. /****************************** For Initial Settings************************************************/
  3294. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3295. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3296. // allocate Configuration memory address
  3297. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3298. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3299. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3300. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3301. //offline MeterValue Interval
  3302. TempMeterValueInterval = 0;
  3303. return result;
  3304. }
  3305. int ProcessShareMemory()
  3306. {
  3307. if(InitShareMemory() == FAIL)
  3308. {
  3309. DEBUG_ERROR("InitShareMemory NG\n");
  3310. if(ShmStatusCodeData!=NULL)
  3311. {
  3312. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3313. }
  3314. sleep(5);
  3315. return FAIL;
  3316. }
  3317. return PASS;
  3318. }
  3319. void CheckSystemValue(void)
  3320. {
  3321. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3322. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3323. char filenmae[100]={0};
  3324. char str[100]={0};
  3325. int tempIndex = 0;
  3326. //===============================
  3327. // send Heartbeat
  3328. //===============================
  3329. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3330. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3331. {
  3332. clientTime.Heartbeat=time((time_t*)NULL);
  3333. if(server_sign == TRUE)
  3334. {
  3335. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3336. }
  3337. else
  3338. {
  3339. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3340. }
  3341. }
  3342. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3343. {
  3344. //parameter for test
  3345. sendHeartbeatRequest(0);
  3346. //==============================================
  3347. // Reset Waiting Time
  3348. //==============================================
  3349. HeartBeatWithNOResponse += 1;
  3350. }
  3351. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3352. {
  3353. //==========================================
  3354. // csu trigger DataTransferReq
  3355. //==========================================
  3356. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3357. {
  3358. sendDataTransferRequest(gun_index);
  3359. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3360. }
  3361. //===============================
  3362. // CSU Trigger Authorize Request
  3363. //===============================
  3364. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3365. {
  3366. sendAuthorizeRequest(0);
  3367. authorizeRetryTimes = authorizeRetryTimes + 1;
  3368. if(authorizeRetryTimes < 3)
  3369. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3370. }
  3371. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3372. {
  3373. authorizeRetryTimes = 0;
  3374. SetOcppConnStatus(FALSE);
  3375. server_sign = FALSE;
  3376. }
  3377. 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))
  3378. {
  3379. sendAuthorizeRequest(0);
  3380. }
  3381. //==============================================
  3382. // Charger start transaction
  3383. //==============================================
  3384. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3385. {
  3386. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3387. sendStartTransactionRequest(gun_index);
  3388. clientTime.StartTransaction = time((time_t*)NULL);
  3389. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3390. storeTempStopTransaction(gun_index);
  3391. }
  3392. //==============================================
  3393. // Charger stop transaction
  3394. //==============================================
  3395. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3396. {
  3397. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3398. sendStopTransactionRequest(gun_index);
  3399. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3400. clientTime.StopTransaction = time((time_t*)NULL);
  3401. }
  3402. //==============================================
  3403. // Charger status report
  3404. //==============================================
  3405. //--- Check Mode Change ---//
  3406. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3407. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3408. {
  3409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3410. {
  3411. tempIndex = ((gun_index==2) ? 1: 0);
  3412. }
  3413. else
  3414. {
  3415. tempIndex = gun_index;
  3416. }
  3417. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3418. {
  3419. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3420. {
  3421. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3422. {
  3423. // Sent unplug message for California pricing logic
  3424. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3425. {
  3426. uint8_t ts[20];
  3427. getNowDatetime(ts);
  3428. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3429. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3430. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3431. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3432. }
  3433. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3434. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3435. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3436. }
  3437. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3438. {
  3439. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3440. if((access(filenmae,F_OK))!=-1)
  3441. {
  3442. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3443. sprintf(str,"rm -f %s",filenmae);
  3444. system(str);
  3445. }
  3446. }
  3447. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3448. #if 1 // for TempStopTransaction
  3449. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3450. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3451. {
  3452. checkTempStopTransaction(gun_index);
  3453. }
  3454. #endif
  3455. }
  3456. }
  3457. }
  3458. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3459. {
  3460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3461. {
  3462. tempIndex = ((gun_index==2) ? 1: 0);
  3463. }
  3464. else
  3465. {
  3466. tempIndex = gun_index;
  3467. }
  3468. for (int index = 0; index < CCS_QUANTITY; index++)
  3469. {
  3470. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3471. {
  3472. 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]*/ )
  3473. {
  3474. // Sent unplug message for California pricing logic
  3475. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3476. {
  3477. uint8_t ts[20];
  3478. getNowDatetime(ts);
  3479. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3480. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3481. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3482. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3483. }
  3484. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3485. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3486. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3487. }
  3488. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3489. {
  3490. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3491. if((access(filenmae,F_OK))!=-1)
  3492. {
  3493. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3494. sprintf(str,"rm -f %s",filenmae);
  3495. system(str);
  3496. }
  3497. }
  3498. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3499. #if 1 // for TempStopTransaction
  3500. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3501. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3502. {
  3503. checkTempStopTransaction(gun_index);
  3504. }
  3505. #endif
  3506. }
  3507. }
  3508. }
  3509. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3510. {
  3511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3512. {
  3513. tempIndex = ((gun_index==2) ? 1: 0);
  3514. }
  3515. else
  3516. {
  3517. tempIndex = gun_index;
  3518. }
  3519. for (int index = 0; index < GB_QUANTITY; index++)
  3520. {
  3521. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3522. {
  3523. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3524. {
  3525. // Sent unplug message for California pricing logic
  3526. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3527. {
  3528. uint8_t ts[20];
  3529. getNowDatetime(ts);
  3530. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3531. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3532. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3533. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3534. }
  3535. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3536. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3537. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3538. }
  3539. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3540. {
  3541. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3542. if((access(filenmae,F_OK))!=-1)
  3543. {
  3544. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3545. sprintf(str,"rm -f %s",filenmae);
  3546. system(str);
  3547. }
  3548. }
  3549. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3550. #if 1 // for TempStopTransaction
  3551. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3552. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3553. {
  3554. checkTempStopTransaction(gun_index);
  3555. }
  3556. #endif
  3557. }
  3558. }
  3559. }
  3560. else if(gunType[gun_index] == GUN_TYPE_DO)
  3561. {
  3562. tempIndex = gun_index;
  3563. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3564. {
  3565. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3566. {
  3567. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3568. {
  3569. // Sent unplug message for California pricing logic
  3570. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3571. {
  3572. uint8_t ts[20];
  3573. getNowDatetime(ts);
  3574. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3575. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3576. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3577. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3578. }
  3579. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3580. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3581. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3582. }
  3583. 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
  3584. {
  3585. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3586. if((access(filenmae,F_OK))!=-1)
  3587. {
  3588. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3589. sprintf(str,"rm -f %s",filenmae);
  3590. system(str);
  3591. }
  3592. }
  3593. 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);
  3594. #if 1 // for TempStopTransaction
  3595. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3596. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3597. {
  3598. checkTempStopTransaction(gun_index);
  3599. }
  3600. #endif
  3601. }
  3602. }
  3603. }
  3604. else
  3605. {
  3606. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3607. {
  3608. tempIndex = 2;
  3609. }
  3610. else
  3611. {
  3612. tempIndex = gun_index;
  3613. }
  3614. for (int index = 0; index < AC_QUANTITY; index++)
  3615. {
  3616. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3617. {
  3618. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3619. {
  3620. // Sent unplug message for California pricing logic
  3621. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3622. {
  3623. uint8_t ts[20];
  3624. getNowDatetime(ts);
  3625. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3626. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3627. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3628. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3629. }
  3630. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3631. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3632. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3633. }
  3634. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3635. {
  3636. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3637. if((access(filenmae,F_OK))!=-1)
  3638. {
  3639. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3640. sprintf(str,"rm -f %s",filenmae);
  3641. system(str);
  3642. }
  3643. }
  3644. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3645. #if 1 // for TempStopTransaction
  3646. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3647. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3648. {
  3649. checkTempStopTransaction(gun_index);
  3650. }
  3651. #endif
  3652. }
  3653. }// END
  3654. }
  3655. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3656. (
  3657. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3658. )
  3659. )
  3660. {
  3661. if(SystemInitial > 0)
  3662. SystemInitial -= 1;
  3663. sendStatusNotificationRequest(gun_index);
  3664. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3665. }
  3666. //==============================================
  3667. // CSU Trigger Smart Charging Profilw
  3668. //==============================================
  3669. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3670. {
  3671. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3672. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3673. }
  3674. //==============================================
  3675. // Meter report
  3676. //==============================================
  3677. // Trigger MeterValue
  3678. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3679. {
  3680. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3681. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3682. }
  3683. // ClockAlign MeterValue
  3684. 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))
  3685. {
  3686. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3687. {
  3688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3689. {
  3690. tempIndex = ((gun_index==2) ? 1: 0);
  3691. }
  3692. else
  3693. {
  3694. tempIndex = gun_index;
  3695. }
  3696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3697. {
  3698. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3699. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3700. {
  3701. reqClockAlignMeter[gun_index] = 1;
  3702. }
  3703. }// End for CHAdeMO
  3704. }
  3705. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3708. {
  3709. tempIndex = ((gun_index==2) ? 1: 0);
  3710. }
  3711. else
  3712. {
  3713. tempIndex = gun_index;
  3714. }
  3715. for (int index = 0; index < CCS_QUANTITY; index++)
  3716. {
  3717. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3718. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3719. {
  3720. reqClockAlignMeter[gun_index] = 1;
  3721. }
  3722. } // End for CCS
  3723. }
  3724. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3725. {
  3726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3727. {
  3728. tempIndex = ((gun_index==2) ? 1: 0);
  3729. }
  3730. else
  3731. {
  3732. tempIndex = gun_index;
  3733. }
  3734. for (int index = 0; index < GB_QUANTITY; index++)
  3735. {
  3736. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3737. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3738. {
  3739. reqClockAlignMeter[gun_index] = 1;
  3740. }
  3741. }// End for GB
  3742. }
  3743. else if(gunType[gun_index] == GUN_TYPE_DO)
  3744. {
  3745. tempIndex = gun_index;
  3746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3747. {
  3748. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3749. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3750. {
  3751. reqClockAlignMeter[gun_index] = 1;
  3752. }
  3753. }
  3754. }
  3755. else
  3756. {
  3757. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3758. {
  3759. tempIndex = 2;
  3760. }
  3761. else
  3762. {
  3763. tempIndex = gun_index;
  3764. }
  3765. for (int index = 0; index < AC_QUANTITY; index++)
  3766. {
  3767. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3768. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3769. {
  3770. reqClockAlignMeter[gun_index] = 1;
  3771. }
  3772. }//End for AC
  3773. }
  3774. if(reqClockAlignMeter[gun_index] == 1)
  3775. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3776. }
  3777. // Sample period MeterValue
  3778. 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))))
  3779. {
  3780. //check Transaction active
  3781. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3784. {
  3785. tempIndex = ((gun_index==2) ? 1: 0);
  3786. }
  3787. else
  3788. {
  3789. tempIndex = gun_index;
  3790. }
  3791. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3792. {
  3793. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3794. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3795. {
  3796. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3797. {
  3798. reqSampleMeter[gun_index] = 1;
  3799. }
  3800. }
  3801. }// End for CHAdeMO
  3802. }
  3803. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3804. {
  3805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3806. {
  3807. tempIndex = ((gun_index==2) ? 1: 0);
  3808. }
  3809. else
  3810. {
  3811. tempIndex = gun_index;
  3812. }
  3813. for (int index = 0; index < CCS_QUANTITY; index++)
  3814. {
  3815. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3816. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3817. {
  3818. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3819. {
  3820. reqSampleMeter[gun_index] = 1;
  3821. }
  3822. }
  3823. } // End for CCS
  3824. }
  3825. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3826. {
  3827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3828. {
  3829. tempIndex = ((gun_index==2) ? 1: 0);
  3830. }
  3831. else
  3832. {
  3833. tempIndex = gun_index;
  3834. }
  3835. for (int index = 0; index < GB_QUANTITY; index++)
  3836. {
  3837. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3838. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3839. {
  3840. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3841. {
  3842. reqSampleMeter[gun_index] = 1;
  3843. }
  3844. }
  3845. }// End for GB
  3846. }
  3847. else if(gunType[gun_index] == GUN_TYPE_DO)
  3848. {
  3849. tempIndex = gun_index;
  3850. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3851. {
  3852. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3853. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3854. {
  3855. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3856. {
  3857. reqSampleMeter[gun_index] = 1;
  3858. }
  3859. }
  3860. }
  3861. }
  3862. else
  3863. {
  3864. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3865. {
  3866. tempIndex = 2;
  3867. }
  3868. else
  3869. {
  3870. tempIndex = gun_index;
  3871. }
  3872. for (int index = 0; index < AC_QUANTITY; index++)
  3873. {
  3874. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3875. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3876. {
  3877. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3878. {
  3879. reqSampleMeter[gun_index] = 1;
  3880. }
  3881. }
  3882. }//End for AC
  3883. }
  3884. if(reqSampleMeter[gun_index] == 1)
  3885. {
  3886. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3887. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3888. storeTempStopTransaction(gun_index);
  3889. }
  3890. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3891. }
  3892. //==============================================
  3893. // Check Connector reserved
  3894. //==============================================
  3895. //===============================
  3896. // Check if Reserve is expired
  3897. //===============================
  3898. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  3899. {
  3900. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  3901. {
  3902. DEBUG_INFO("reserve expired.\n");
  3903. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3904. }
  3905. }//END OF Check if Reserve is expired
  3906. //==========================================
  3907. // csu trigger FirmwareStatusNotificationReq
  3908. //==========================================
  3909. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3910. {
  3911. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3912. }
  3913. //==========================================
  3914. // csu trigger DiagnosticsStatusNotificationReq
  3915. //==========================================
  3916. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3917. {
  3918. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3919. }
  3920. //==========================================
  3921. // csu trigger CancelReservationConf
  3922. //==========================================
  3923. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3924. {
  3925. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3926. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3927. }
  3928. //==========================================
  3929. // csu trigger ChangeAvailabilityConf
  3930. //==========================================
  3931. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3932. {
  3933. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3934. }
  3935. //==========================================
  3936. // csu trigger UnlockConnectorConf
  3937. //==========================================
  3938. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3939. {
  3940. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3941. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3942. }
  3943. //==========================================
  3944. // csu trigger ReserveNowConf
  3945. //==========================================
  3946. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3947. {
  3948. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3949. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3950. }
  3951. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3952. {
  3953. sendSignCertificateRequest();
  3954. }
  3955. }
  3956. }
  3957. //==========================================
  3958. // send request routine
  3959. //==========================================
  3960. int sendAuthorizeRequest(int gun_index)
  3961. {
  3962. mtrace();
  3963. int result = FAIL;
  3964. char message[100]={0};
  3965. char guid[37];
  3966. char tempdata[65]={0};
  3967. DEBUG_INFO("sendAuthorizeRequest...\n");
  3968. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3969. //Local Authorize
  3970. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3971. {
  3972. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3973. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3974. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3975. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3976. result = PASS;
  3977. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3978. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3979. authorizeRetryTimes = 0;
  3980. return result;
  3981. }
  3982. 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))||
  3983. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3984. {
  3985. // Query from cache
  3986. DEBUG_INFO("Authorize from cache.\n");
  3987. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3988. // Query from list
  3989. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3990. {
  3991. DEBUG_INFO("Authorize from list.\n");
  3992. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3993. }
  3994. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3995. {
  3996. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3997. {
  3998. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3999. }
  4000. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4001. {
  4002. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4003. }
  4004. if(!GetOcppConnStatus())
  4005. {
  4006. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4007. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4008. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4009. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4010. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4011. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4012. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4013. authorizeRetryTimes = 0;
  4014. return result;
  4015. }
  4016. }
  4017. else
  4018. {
  4019. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4020. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4021. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4022. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4023. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4024. else
  4025. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4026. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4027. result = PASS;
  4028. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4029. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4030. authorizeRetryTimes = 0;
  4031. return result;
  4032. }
  4033. }
  4034. //initialize struct Authorize
  4035. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4036. //get data from shared memory
  4037. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4038. random_uuid(guid);
  4039. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4040. LWS_Send(message);
  4041. sprintf(tempdata, "Authorize,%d", gun_index);
  4042. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4043. {
  4044. result = PASS;
  4045. DEBUG_INFO("Authorize mapItem pass\n");
  4046. }
  4047. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4048. return result;
  4049. }
  4050. int sendBootNotificationRequest(void)
  4051. {
  4052. mtrace();
  4053. int result = FAIL;
  4054. char message[500]={0}, payload[700]={0};
  4055. char guid[37]={0};
  4056. char tempdata[65]={0};
  4057. // Fill BootNotification fields
  4058. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4059. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4060. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4061. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4062. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4063. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4064. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4065. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4066. ShmOCPP16Data->ChargeBoxId
  4067. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4068. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4069. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4070. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4071. ,ShmOCPP16Data->BootNotification.CpIccid
  4072. ,ShmOCPP16Data->BootNotification.CpImsi);
  4073. random_uuid(guid);
  4074. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4075. LWS_Send(message);
  4076. sprintf(tempdata, "BootNotification,0");
  4077. 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*/)
  4078. {
  4079. result = PASS;
  4080. }
  4081. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4082. strcpy(queuedata,message);
  4083. return result;
  4084. }
  4085. int sendDataTransferRequest(int gun_index)
  4086. {
  4087. mtrace();
  4088. char message[1000]={0};
  4089. char guid[37]={0};
  4090. char tempdata[65]={0};
  4091. int result = FAIL;
  4092. random_uuid(guid);
  4093. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4094. MESSAGE_TYPE_CALL,
  4095. guid,
  4096. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4097. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4098. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4099. LWS_Send(message);
  4100. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4101. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4102. {
  4103. result = PASS;
  4104. DEBUG_INFO("DataTransfer mapItem pass\n");
  4105. }
  4106. return result;
  4107. }
  4108. int sendDiagnosticsStatusNotificationRequest(char *status)
  4109. {
  4110. mtrace();
  4111. int result = FAIL;
  4112. char message[110]={0};
  4113. char guid[37]={0};
  4114. char tempdata[65]={0};
  4115. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4116. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4117. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4118. random_uuid(guid);
  4119. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4120. LWS_SendNow(message);
  4121. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4122. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4123. {
  4124. result = PASS;
  4125. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4126. }
  4127. //#ifdef SystemLogMessage
  4128. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4129. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4130. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4131. //#endif
  4132. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4133. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4134. //record status
  4135. if(strcmp(status,"Idle")==0)
  4136. {
  4137. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4138. }
  4139. else if(strcmp(status,"Uploaded")==0)
  4140. {
  4141. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4142. }
  4143. else if(strcmp(status,"UploadFailed")==0)
  4144. {
  4145. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4146. }
  4147. else if(strcmp(status,"Uploading")==0)
  4148. {
  4149. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4150. }
  4151. return result;
  4152. }
  4153. int sendFirmwareStatusNotificationRequest(char *status)
  4154. {
  4155. mtrace();
  4156. int result = FAIL;
  4157. char message[110]={0};
  4158. char guid[37]={0};
  4159. char tempdata[65]={0};
  4160. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4161. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4162. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4163. random_uuid(guid);
  4164. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4165. LWS_SendNow(message);
  4166. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4167. 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*/)
  4168. {
  4169. result = PASS;
  4170. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4171. }
  4172. //#ifdef SystemLogMessage
  4173. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4174. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4175. //#endif
  4176. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4177. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4178. //record status
  4179. if(strcmp(status,"Downloaded")==0)
  4180. {
  4181. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4182. }
  4183. else if(strcmp(status,"DownloadFailed")==0)
  4184. {
  4185. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4186. }
  4187. else if(strcmp(status,"Downloading")==0)
  4188. {
  4189. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4190. }
  4191. else if(strcmp(status,"Idle")==0)
  4192. {
  4193. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4194. }
  4195. else if(strcmp(status,"InstallationFailed")==0)
  4196. {
  4197. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4198. }
  4199. else if(strcmp(status,"Installing")==0)
  4200. {
  4201. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4202. }
  4203. else if(strcmp(status,"Installed")==0)
  4204. {
  4205. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4206. }
  4207. return result;
  4208. }
  4209. int sendHeartbeatRequest(int gun_index)
  4210. {
  4211. mtrace();
  4212. int result = FAIL;
  4213. char message[80]={0};
  4214. char guid[37]={0};
  4215. char tempdata[65]={0};
  4216. random_uuid(guid);
  4217. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4218. , MESSAGE_TYPE_CALL
  4219. , guid );
  4220. LWS_Send(message);
  4221. sprintf(tempdata, "Heartbeat,%d", 0);
  4222. 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*/)
  4223. {
  4224. result = PASS;
  4225. }
  4226. return result;
  4227. }
  4228. int sendStartTransactionRequest(int gun_index)
  4229. {
  4230. mtrace();
  4231. int result = FAIL;
  4232. char message[250]={0};
  4233. char guid[37]={0};
  4234. struct timeval tmnow;
  4235. struct tm *tm;
  4236. char buf[28];//, usec_buf[6];
  4237. char tempdata[65]={0};
  4238. int tempIndex = 0;
  4239. DEBUG_INFO("sendStartTransactionRequest...\n");
  4240. gettimeofday(&tmnow, NULL);
  4241. time_t t;
  4242. t = time(NULL);
  4243. /*UTC time and date*/
  4244. tm = gmtime(&t);
  4245. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4246. #if 0 // remove temporally
  4247. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4248. strcat(buf,".");
  4249. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4250. strcat(buf,usec_buf);
  4251. #endif
  4252. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4253. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4254. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4255. // clear StartTransaction Response
  4256. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4257. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4258. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4259. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4260. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4261. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4262. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4263. {
  4264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4265. {
  4266. tempIndex = ((gun_index==2) ? 1: 0);
  4267. }
  4268. else
  4269. {
  4270. tempIndex = gun_index;
  4271. }
  4272. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4273. {
  4274. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4275. {
  4276. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4277. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4278. }
  4279. }
  4280. }
  4281. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4282. {
  4283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4284. {
  4285. tempIndex = ((gun_index==2) ? 1: 0);
  4286. }
  4287. else
  4288. {
  4289. tempIndex = gun_index;
  4290. }
  4291. for (int index = 0; index < CCS_QUANTITY; index++)
  4292. {
  4293. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4294. {
  4295. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4296. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4297. }
  4298. }
  4299. }
  4300. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4301. {
  4302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4303. {
  4304. tempIndex = ((gun_index==2) ? 1: 0);
  4305. }
  4306. else
  4307. {
  4308. tempIndex = gun_index;
  4309. }
  4310. for (int index = 0; index < GB_QUANTITY; index++)
  4311. {
  4312. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4313. {
  4314. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4315. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4316. }
  4317. }
  4318. }
  4319. else if(gunType[gun_index] == GUN_TYPE_DO)
  4320. {
  4321. tempIndex = gun_index;
  4322. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4323. {
  4324. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4325. {
  4326. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4327. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4328. }
  4329. }
  4330. }
  4331. else
  4332. {
  4333. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4334. {
  4335. tempIndex = 2;
  4336. }
  4337. else
  4338. {
  4339. tempIndex = gun_index;
  4340. }
  4341. for (int index = 0; index < AC_QUANTITY; index++)
  4342. {
  4343. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4344. {
  4345. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4346. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4347. }
  4348. }
  4349. }
  4350. random_uuid(guid);
  4351. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4352. {
  4353. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4354. , gun_index +1
  4355. , MESSAGE_TYPE_CALL
  4356. , guid
  4357. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4358. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4359. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4360. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4361. }
  4362. else
  4363. {
  4364. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4365. , gun_index +1
  4366. , MESSAGE_TYPE_CALL
  4367. , guid
  4368. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4369. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4370. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4371. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4372. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4373. }
  4374. #if 1
  4375. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4376. 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*/)
  4377. {
  4378. result = PASS;
  4379. }
  4380. #endif
  4381. strcpy(queuedata, message);
  4382. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4383. OCPP_insert_transaction_msg(YES, queuedata);
  4384. return result;
  4385. }
  4386. int sendStatusNotificationRequest(int gun_index)
  4387. {
  4388. mtrace();
  4389. int result = FAIL;
  4390. char message[600]={0};
  4391. char guid[37];
  4392. int currentStatus = 0;
  4393. struct timeval tmnow;
  4394. struct tm *tm;
  4395. char buf[28];//, usec_buf[6];
  4396. char tempdata[65]={0};
  4397. int tempIndex = 0;
  4398. uint8_t isStateChanged = TRUE;
  4399. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4400. gettimeofday(&tmnow, NULL);
  4401. time_t t;
  4402. t = time(NULL);
  4403. /*UTC time and date*/
  4404. tm = gmtime(&t);
  4405. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4406. #if 0 // remove temporally
  4407. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4408. strcat(buf,".");
  4409. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4410. strcat(buf,usec_buf);
  4411. #endif
  4412. //printf("%s",buf);
  4413. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4414. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4415. // it's option
  4416. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4417. /*
  4418. enum _SYSTEM_STATUS
  4419. {
  4420. S_BOOTING = 0,
  4421. S_IDLE, = 1
  4422. S_AUTHORIZING, =2
  4423. S_REASSIGN_CHECK, =3
  4424. S_REASSIGN, =4
  4425. S_PRECHARGE, =5
  4426. S_PREPARING_FOR_EV, =6
  4427. S_PREPARING_FOR_EVSE, =7
  4428. S_CHARGING, =8
  4429. S_TERMINATING, =9
  4430. S_COMPLETE, =10
  4431. S_ALARM, =11
  4432. S_FAULT =12
  4433. }
  4434. */
  4435. //check Transaction active
  4436. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4437. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4438. {
  4439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4440. {
  4441. tempIndex = ((gun_index==2) ? 1: 0);
  4442. }
  4443. else
  4444. {
  4445. tempIndex = gun_index;
  4446. }
  4447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4448. {
  4449. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4450. {
  4451. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4452. {
  4453. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4454. {
  4455. currentStatus = Preparing; //OCPP Status: Preparing
  4456. }
  4457. else
  4458. {
  4459. currentStatus = Available; //OCPP Status: Available
  4460. }
  4461. }
  4462. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4463. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4464. ) //S_PRECHARGE
  4465. {
  4466. currentStatus = Preparing; //OCPP Status: Preparing
  4467. }
  4468. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4469. {
  4470. currentStatus = Charging; //OCPP Status: Charging
  4471. }
  4472. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4473. {
  4474. currentStatus = Finishing; //OCPP Status: Finishing
  4475. }
  4476. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4477. {
  4478. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4479. }
  4480. 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
  4481. {
  4482. currentStatus = Unavailable; //OCPP Status: Unavailable
  4483. }
  4484. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4485. {
  4486. currentStatus = Faulted; //OCPP Status: Faulted
  4487. }
  4488. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4489. {
  4490. currentStatus = Reserved; //OCPP Status: Reserved
  4491. }
  4492. } //end of the same index
  4493. }//end of for CHAdeMO_QUANTITY
  4494. }
  4495. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4496. {
  4497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4498. {
  4499. tempIndex = ((gun_index==2) ? 1: 0);
  4500. }
  4501. else
  4502. {
  4503. tempIndex = gun_index;
  4504. }
  4505. for (int index = 0; index < CCS_QUANTITY; index++)
  4506. {
  4507. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4508. {
  4509. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4510. {
  4511. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4512. {
  4513. currentStatus = Preparing; //OCPP Status: Preparing
  4514. }
  4515. else
  4516. {
  4517. currentStatus = Available; //OCPP Status: Available
  4518. }
  4519. }
  4520. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4521. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4522. ) //S_PRECHARGE
  4523. {
  4524. currentStatus = Preparing; //OCPP Status: Preparing
  4525. }
  4526. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4527. {
  4528. currentStatus = Charging; //OCPP Status: Charging
  4529. }
  4530. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4531. {
  4532. currentStatus = Finishing; //OCPP Status: Finishing
  4533. }
  4534. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4535. {
  4536. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4537. }
  4538. 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
  4539. {
  4540. currentStatus = Unavailable; //OCPP Status : Unavailable
  4541. }
  4542. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4543. {
  4544. currentStatus = Faulted; //OCPP Status: Faulted
  4545. }
  4546. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4547. {
  4548. currentStatus = Reserved; //OCPP Status: Reserved
  4549. }
  4550. } //end of the same index
  4551. } // end of for CCS_QUANTITY
  4552. }
  4553. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4554. {
  4555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4556. {
  4557. tempIndex = ((gun_index==2) ? 1: 0);
  4558. }
  4559. else
  4560. {
  4561. tempIndex = gun_index;
  4562. }
  4563. for (int index = 0; index < GB_QUANTITY; index++)
  4564. {
  4565. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4566. {
  4567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4568. {
  4569. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4570. {
  4571. currentStatus = Preparing; //OCPP Status: Preparing
  4572. }
  4573. else
  4574. {
  4575. currentStatus = Available; //OCPP Status: Available
  4576. }
  4577. }
  4578. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4579. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4580. ) //S_PRECHARGE
  4581. {
  4582. currentStatus = Preparing; //OCPP Status: Preparing
  4583. }
  4584. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4585. {
  4586. currentStatus = Charging; //OCPP Status: Charging
  4587. }
  4588. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4589. {
  4590. currentStatus = Finishing; //OCPP Status: Finishing
  4591. }
  4592. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4593. {
  4594. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4595. }
  4596. 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
  4597. {
  4598. currentStatus = Unavailable; //OCPP Status: Unavailable
  4599. }
  4600. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4601. {
  4602. currentStatus = Faulted; //OCPP Status: Faulted
  4603. }
  4604. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4605. {
  4606. currentStatus = Reserved; //OCPP Status: Reserved
  4607. }
  4608. } //end of the same index
  4609. } // end of for GB_QUANTITY
  4610. }
  4611. else if(gunType[gun_index] == GUN_TYPE_DO)
  4612. {
  4613. tempIndex = gun_index;
  4614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4615. {
  4616. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4617. {
  4618. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4619. {
  4620. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4621. {
  4622. currentStatus = Preparing; //OCPP Status: Preparing
  4623. }
  4624. else
  4625. {
  4626. currentStatus = Available; //OCPP Status: Available
  4627. }
  4628. }
  4629. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4630. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4631. ) //S_PRECHARGE
  4632. {
  4633. currentStatus = Preparing; //OCPP Status: Preparing
  4634. }
  4635. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4636. {
  4637. currentStatus = Charging; //OCPP Status: Charging
  4638. }
  4639. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4640. {
  4641. currentStatus = Finishing; //OCPP Status: Finishing
  4642. }
  4643. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4644. {
  4645. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4646. }
  4647. 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
  4648. {
  4649. currentStatus = Unavailable; //OCPP Status: Unavailable
  4650. }
  4651. 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
  4652. {
  4653. currentStatus = Faulted; //OCPP Status: Faulted
  4654. }
  4655. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4656. {
  4657. currentStatus = Reserved; //OCPP Status: Reserved
  4658. }
  4659. } //end of the same index
  4660. }
  4661. }
  4662. else
  4663. {
  4664. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4665. {
  4666. tempIndex = 2;
  4667. }
  4668. else
  4669. {
  4670. tempIndex = gun_index;
  4671. }
  4672. for (int index = 0; index < AC_QUANTITY; index++)
  4673. {
  4674. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4675. {
  4676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4677. {
  4678. 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))
  4679. {
  4680. currentStatus = Preparing; //OCPP Status: Preparing
  4681. }
  4682. else
  4683. {
  4684. currentStatus = Available; //OCPP Status: Available
  4685. }
  4686. }
  4687. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4688. {
  4689. currentStatus = Preparing; //OCPP Status: Preparing
  4690. }
  4691. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4692. {
  4693. currentStatus = Charging; //OCPP Status: Charging
  4694. }
  4695. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4696. {
  4697. currentStatus = Finishing; //OCPP Status: Finishing
  4698. }
  4699. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4700. {
  4701. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4702. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4703. else
  4704. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4705. }
  4706. 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
  4707. {
  4708. currentStatus = Unavailable; //OCPP Status: Unavailable
  4709. }
  4710. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4711. {
  4712. currentStatus = Faulted; //OCPP Status: Faulted
  4713. }
  4714. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4715. {
  4716. currentStatus = Reserved; //OCPP Status: Reserved
  4717. }
  4718. }//end of the same index
  4719. }//end of for AC_QUANTITY
  4720. }
  4721. //it's option
  4722. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4723. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4724. {
  4725. isStateChanged = FALSE;
  4726. }
  4727. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4728. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4729. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4730. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4731. random_uuid(guid);
  4732. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4733. , MESSAGE_TYPE_CALL
  4734. , guid
  4735. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4736. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4737. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4738. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4739. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4740. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4741. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4742. if((server_sign == TRUE) && isStateChanged)
  4743. {
  4744. LWS_Send(message);
  4745. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4746. 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*/)
  4747. {
  4748. //DEBUG_ERROR("statusNotification mapitem pass");
  4749. result = PASS;
  4750. }
  4751. }
  4752. else
  4753. {
  4754. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4755. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4756. result = PASS;
  4757. }
  4758. return result;
  4759. }
  4760. int sendStopTransactionRequest(int gun_index)
  4761. {
  4762. mtrace();
  4763. int result = FAIL;
  4764. //char message[1500]={0};
  4765. char guid[37]={0};
  4766. char tempdata[65]={0};
  4767. int tempIndex = 0;
  4768. char TempStopTransaction[256];
  4769. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4770. //int idx_sample=0;
  4771. DEBUG_INFO("sendStopTransactionRequest \n");
  4772. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4773. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4774. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4775. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4776. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4777. {
  4778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4779. {
  4780. tempIndex = ((gun_index==2) ? 1: 0);
  4781. }
  4782. else
  4783. {
  4784. tempIndex = gun_index;
  4785. }
  4786. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4787. {
  4788. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4789. {
  4790. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4791. }
  4792. }// END OF CHAdeMO_QUANTITY
  4793. }
  4794. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4795. {
  4796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4797. {
  4798. tempIndex = ((gun_index==2) ? 1: 0);
  4799. }
  4800. else
  4801. {
  4802. tempIndex = gun_index;
  4803. }
  4804. for (int index = 0; index < CCS_QUANTITY; index++)
  4805. {
  4806. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4807. {
  4808. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4809. }
  4810. }// END OF CCS_QUANTITY
  4811. }
  4812. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4813. {
  4814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4815. {
  4816. tempIndex = ((gun_index==2) ? 1: 0);
  4817. }
  4818. else
  4819. {
  4820. tempIndex = gun_index;
  4821. }
  4822. for (int index = 0; index < GB_QUANTITY; index++)
  4823. {
  4824. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4825. {
  4826. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4827. }
  4828. }// END OF GB_QUANTITY
  4829. }
  4830. else if(gunType[gun_index] == GUN_TYPE_DO)
  4831. {
  4832. tempIndex = gun_index;
  4833. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4834. {
  4835. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4836. {
  4837. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4838. }
  4839. }// END OF GB_QUANTITY
  4840. }
  4841. else
  4842. {
  4843. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4844. {
  4845. tempIndex = 2;
  4846. }
  4847. else
  4848. {
  4849. tempIndex = gun_index;
  4850. }
  4851. for (int index = 0; index < AC_QUANTITY; index++)
  4852. {
  4853. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4854. {
  4855. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4856. }
  4857. }// END OF AC_QUANTITY
  4858. }
  4859. //====================================== Stop Transaction Time =====================================================
  4860. struct timeval tmnow;
  4861. struct tm *tm;
  4862. char buf[28];//, usec_buf[6];
  4863. gettimeofday(&tmnow, NULL);
  4864. time_t t;
  4865. t = time(NULL);
  4866. /*UTC time and date*/
  4867. tm = gmtime(&t);
  4868. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4870. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4871. random_uuid(guid);
  4872. /***********************************transactionData******************************************************/
  4873. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4875. //=================================
  4876. // Transaction_Begin
  4877. //=================================
  4878. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4879. {
  4880. //============================================ Energy.Active.Import.Interval ================================
  4881. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4884. 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*/]);
  4885. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4886. 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))
  4887. {
  4888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4889. }
  4890. else
  4891. {
  4892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4893. }
  4894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4896. }
  4897. //=================================
  4898. // Transaction_End
  4899. //=================================
  4900. // ================================= Current.Import L1 ===============================================
  4901. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4902. {
  4903. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4904. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4905. {
  4906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4907. {
  4908. tempIndex = ((gun_index==2) ? 1: 0);
  4909. }
  4910. else
  4911. {
  4912. tempIndex = gun_index;
  4913. }
  4914. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4915. {
  4916. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4917. {
  4918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4919. }
  4920. }// End of for CHAdeMO_QUANTITY
  4921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4922. }
  4923. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4924. {
  4925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4926. {
  4927. tempIndex = ((gun_index==2) ? 1: 0);
  4928. }
  4929. else
  4930. {
  4931. tempIndex = gun_index;
  4932. }
  4933. for (int index = 0; index < CCS_QUANTITY; index++)
  4934. {
  4935. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4936. {
  4937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4938. }
  4939. }// End of for CCS_QUANTITY
  4940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4941. }
  4942. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4943. {
  4944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4945. {
  4946. tempIndex = ((gun_index==2) ? 1: 0);
  4947. }
  4948. else
  4949. {
  4950. tempIndex = gun_index;
  4951. }
  4952. for (int index = 0; index < GB_QUANTITY; index++)
  4953. {
  4954. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4955. {
  4956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4957. }
  4958. }// End of for GB_QUANTITY
  4959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4960. }
  4961. else if(gunType[gun_index] == GUN_TYPE_DO)
  4962. {
  4963. tempIndex = gun_index;
  4964. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4965. {
  4966. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4967. {
  4968. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4969. }
  4970. }
  4971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4972. }
  4973. else
  4974. {
  4975. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4976. {
  4977. tempIndex = 2;
  4978. }
  4979. else
  4980. {
  4981. tempIndex = gun_index;
  4982. }
  4983. for (int index = 0; index < AC_QUANTITY; index++)
  4984. {
  4985. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4986. {
  4987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4988. }
  4989. }// End of for AC_QUANTITY
  4990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4991. }
  4992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4997. }
  4998. // ================================= Energy.Active.Import.Interval ==============================================
  4999. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5000. {
  5001. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5002. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5003. {
  5004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5005. {
  5006. tempIndex = ((gun_index==2) ? 1: 0);
  5007. }
  5008. else
  5009. {
  5010. tempIndex = gun_index;
  5011. }
  5012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5013. {
  5014. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5015. {
  5016. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5017. }
  5018. }// END OF CHAdeMO_QUANTITY
  5019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5020. }
  5021. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5022. {
  5023. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5024. {
  5025. tempIndex = ((gun_index==2) ? 1: 0);
  5026. }
  5027. else
  5028. {
  5029. tempIndex = gun_index;
  5030. }
  5031. for (int index = 0; index < CCS_QUANTITY; index++)
  5032. {
  5033. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5034. {
  5035. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5036. }
  5037. }// END OF CCS_QUANTITY
  5038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5039. }
  5040. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5041. {
  5042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5043. {
  5044. tempIndex = ((gun_index==2) ? 1: 0);
  5045. }
  5046. else
  5047. {
  5048. tempIndex = gun_index;
  5049. }
  5050. for (int index = 0; index < GB_QUANTITY; index++)
  5051. {
  5052. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5053. {
  5054. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5055. }
  5056. }// END OF GB_QUANTITY
  5057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5058. }
  5059. else if(gunType[gun_index] == GUN_TYPE_DO)
  5060. {
  5061. tempIndex = gun_index;
  5062. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5063. {
  5064. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5065. {
  5066. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5067. }
  5068. }
  5069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5070. }
  5071. else
  5072. {
  5073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5074. {
  5075. tempIndex = 2;
  5076. }
  5077. else
  5078. {
  5079. tempIndex = gun_index;
  5080. }
  5081. for (int index = 0; index < AC_QUANTITY; index++)
  5082. {
  5083. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5084. {
  5085. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5086. }
  5087. }// END OF AC_QUANTITY
  5088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5089. }
  5090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5095. }
  5096. //=================================== Power.Active.Import ==================================================
  5097. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5098. {
  5099. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5100. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5101. {
  5102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5103. {
  5104. tempIndex = ((gun_index==2) ? 1: 0);
  5105. }
  5106. else
  5107. {
  5108. tempIndex = gun_index;
  5109. }
  5110. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5111. {
  5112. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5113. {
  5114. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5115. }
  5116. } // End for CHAdeMO_QUANTITY
  5117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5118. }
  5119. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5120. {
  5121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5122. {
  5123. tempIndex = ((gun_index==2) ? 1: 0);
  5124. }
  5125. else
  5126. {
  5127. tempIndex = gun_index;
  5128. }
  5129. for (int index = 0; index < CCS_QUANTITY; index++)
  5130. {
  5131. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5132. {
  5133. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5134. }
  5135. } // END for CCS_QUANTITY
  5136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5137. }
  5138. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5139. {
  5140. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5141. {
  5142. tempIndex = ((gun_index==2) ? 1: 0);
  5143. }
  5144. else
  5145. {
  5146. tempIndex = gun_index;
  5147. }
  5148. for (int index = 0; index < GB_QUANTITY; index++)
  5149. {
  5150. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5151. {
  5152. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5153. }
  5154. }// END for GB_QUANTITY
  5155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5156. }
  5157. else if(gunType[gun_index] == GUN_TYPE_DO)
  5158. {
  5159. tempIndex = gun_index;
  5160. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5161. {
  5162. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5163. {
  5164. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5165. }
  5166. }
  5167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5168. }
  5169. else
  5170. {
  5171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5172. {
  5173. tempIndex = 2;
  5174. }
  5175. else
  5176. {
  5177. tempIndex = gun_index;
  5178. }
  5179. for (int index = 0; index < AC_QUANTITY; index++)
  5180. {
  5181. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5182. {
  5183. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5184. }
  5185. } // END for AC_QUANTITY
  5186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5187. }
  5188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5193. }
  5194. //============================ Voltage L1 ====================================
  5195. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5196. {
  5197. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5198. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5199. {
  5200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5201. {
  5202. tempIndex = ((gun_index==2) ? 1: 0);
  5203. }
  5204. else
  5205. {
  5206. tempIndex = gun_index;
  5207. }
  5208. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5209. {
  5210. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5211. {
  5212. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5213. }
  5214. } // END OF FOR CHAdeMO_QUANTITY
  5215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5216. }
  5217. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5218. {
  5219. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5220. {
  5221. tempIndex = ((gun_index==2) ? 1: 0);
  5222. }
  5223. else
  5224. {
  5225. tempIndex = gun_index;
  5226. }
  5227. for (int index = 0; index < CCS_QUANTITY; index++)
  5228. {
  5229. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5230. {
  5231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5232. }
  5233. } // END OF FOR CCS_QUANTITY
  5234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5235. }
  5236. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5237. {
  5238. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5239. {
  5240. tempIndex = ((gun_index==2) ? 1: 0);
  5241. }
  5242. else
  5243. {
  5244. tempIndex = gun_index;
  5245. }
  5246. for (int index = 0; index < GB_QUANTITY; index++)
  5247. {
  5248. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5249. {
  5250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5251. }
  5252. } // END OF FOR GB_QUANTITY
  5253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5254. }
  5255. else if(gunType[gun_index] == GUN_TYPE_DO)
  5256. {
  5257. tempIndex = gun_index;
  5258. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5259. {
  5260. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5261. {
  5262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5263. }
  5264. }
  5265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5266. }
  5267. else
  5268. {
  5269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5270. {
  5271. tempIndex = 2;
  5272. }
  5273. else
  5274. {
  5275. tempIndex = gun_index;
  5276. }
  5277. for (int index = 0; index < AC_QUANTITY; index++)
  5278. {
  5279. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5280. {
  5281. 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
  5282. }
  5283. } // END OF FOR AC_QUANTITY
  5284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5285. }
  5286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5291. }
  5292. //====================== End SoC ================================
  5293. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5294. {
  5295. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5296. 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))
  5297. {
  5298. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5299. {
  5300. tempIndex = ((gun_index==2) ? 1: 0);
  5301. }
  5302. else
  5303. {
  5304. tempIndex = gun_index;
  5305. }
  5306. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5307. {
  5308. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5309. {
  5310. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5311. {
  5312. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5313. }
  5314. }
  5315. }
  5316. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5317. {
  5318. for (int index = 0; index < CCS_QUANTITY; index++)
  5319. {
  5320. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5321. {
  5322. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5323. }
  5324. }
  5325. }
  5326. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5327. {
  5328. for (int index = 0; index < GB_QUANTITY; index++)
  5329. {
  5330. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5331. {
  5332. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5333. }
  5334. }
  5335. }
  5336. else if(gunType[gun_index] == GUN_TYPE_DO)
  5337. {
  5338. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5339. {
  5340. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5341. {
  5342. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5343. }
  5344. }
  5345. }
  5346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5350. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5352. } // END FOR DC CASE
  5353. }
  5354. // ================================= Current.Import L2 ===============================================
  5355. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5356. {
  5357. // AC 3 phse L2 current
  5358. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5359. {
  5360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5361. {
  5362. tempIndex = 2;
  5363. }
  5364. else
  5365. {
  5366. tempIndex = gun_index;
  5367. }
  5368. for (int index = 0; index < AC_QUANTITY; index++)
  5369. {
  5370. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5371. {
  5372. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5373. }
  5374. }// End of for AC_QUANTITY
  5375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5376. }
  5377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5382. }
  5383. // ================================= Current.Import L3 ===============================================
  5384. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5385. {
  5386. // AC 3 phse L3 current
  5387. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5388. {
  5389. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5390. {
  5391. tempIndex = 2;
  5392. }
  5393. else
  5394. {
  5395. tempIndex = gun_index;
  5396. }
  5397. for (int index = 0; index < AC_QUANTITY; index++)
  5398. {
  5399. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5400. {
  5401. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5402. }
  5403. }// End of for AC_QUANTITY
  5404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5405. }
  5406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5411. }
  5412. //============================ Voltage L2 ====================================
  5413. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5414. {
  5415. // AC 3 phse L2 voltage
  5416. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5417. {
  5418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5419. {
  5420. tempIndex = 2;
  5421. }
  5422. else
  5423. {
  5424. tempIndex = gun_index;
  5425. }
  5426. for (int index = 0; index < AC_QUANTITY; index++)
  5427. {
  5428. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5429. {
  5430. 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
  5431. }
  5432. } // END OF FOR AC_QUANTITY
  5433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5434. }
  5435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5440. }
  5441. //============================ Voltage L3 ====================================
  5442. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5443. {
  5444. // AC 3 phse L3 voltage
  5445. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5446. {
  5447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5448. {
  5449. tempIndex = 2;
  5450. }
  5451. else
  5452. {
  5453. tempIndex = gun_index;
  5454. }
  5455. for (int index = 0; index < AC_QUANTITY; index++)
  5456. {
  5457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5458. {
  5459. 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
  5460. }
  5461. } // END OF FOR AC_QUANTITY
  5462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5463. }
  5464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5469. }
  5470. //====================== Start SoC ================================
  5471. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5472. {
  5473. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5474. 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))
  5475. {
  5476. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5477. {
  5478. tempIndex = ((gun_index==2) ? 1: 0);
  5479. }
  5480. else
  5481. {
  5482. tempIndex = gun_index;
  5483. }
  5484. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5485. {
  5486. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5487. {
  5488. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5489. {
  5490. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5491. }
  5492. }
  5493. }
  5494. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5495. {
  5496. for (int index = 0; index < CCS_QUANTITY; index++)
  5497. {
  5498. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5499. {
  5500. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5501. }
  5502. }
  5503. }
  5504. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5505. {
  5506. for (int index = 0; index < GB_QUANTITY; index++)
  5507. {
  5508. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5509. {
  5510. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5511. }
  5512. }
  5513. }
  5514. else if(gunType[gun_index] == GUN_TYPE_DO)
  5515. {
  5516. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5517. {
  5518. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5519. {
  5520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5521. }
  5522. }
  5523. }
  5524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5530. } // END FOR DC CASE
  5531. }
  5532. //================================================ Message create ====================================================
  5533. json_object *StopTransaction = json_object_new_object();
  5534. json_object *transactionDatas = json_object_new_array();
  5535. json_object *sampledValues = json_object_new_array();
  5536. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5537. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5538. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5539. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5540. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5541. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5542. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5543. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5544. {
  5545. json_object *transactionData = json_object_new_object();
  5546. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5547. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5548. {
  5549. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5550. {
  5551. json_object *sampledValue = json_object_new_object();
  5552. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5553. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5554. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5555. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5556. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5557. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5558. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5559. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5560. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5561. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5562. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5563. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5564. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5565. json_object_array_add(sampledValues, sampledValue);
  5566. }
  5567. }
  5568. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5569. json_object_array_add(transactionDatas, transactionData);
  5570. }
  5571. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5572. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5573. ,MESSAGE_TYPE_CALL
  5574. ,guid
  5575. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5576. json_object_put(StopTransaction);
  5577. #if 1 // for TempStopTransaction
  5578. //Delete TempStopTransaction
  5579. if((access(TempStopTransaction,F_OK))!=-1)
  5580. {
  5581. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5582. }
  5583. #endif
  5584. #if 1
  5585. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5586. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5587. {
  5588. result = PASS;
  5589. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5590. }
  5591. #endif
  5592. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5593. OCPP_insert_transaction_msg(NO, queuedata);
  5594. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5595. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5596. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5597. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5598. {
  5599. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5600. }
  5601. //for test
  5602. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5603. return result;
  5604. }
  5605. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5606. {
  5607. mtrace();
  5608. int result = FAIL;
  5609. char guid[37]={0};
  5610. char tempdata[65]={0};
  5611. int tempIndex = 0;
  5612. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5613. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5614. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5615. //set value
  5616. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5617. 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) )?
  5618. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5619. -1);
  5620. random_uuid(guid);
  5621. //UTC Date time
  5622. struct timeval tmnow;
  5623. struct tm *tm;
  5624. char buf[28];//, usec_buf[6];
  5625. gettimeofday(&tmnow, NULL);
  5626. time_t t;
  5627. t = time(NULL);
  5628. /*UTC time and date*/
  5629. tm = gmtime(&t);
  5630. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5632. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5633. //********************************(1)Current.Import L1************************************************/
  5634. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5635. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5636. (dataType == ReadingContext_Trigger))
  5637. {
  5638. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5639. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5640. {
  5641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5642. {
  5643. tempIndex = ((gun_index==2) ? 1: 0);
  5644. }
  5645. else
  5646. {
  5647. tempIndex = gun_index;
  5648. }
  5649. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5650. {
  5651. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5652. {
  5653. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5654. }
  5655. }
  5656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5657. }
  5658. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5659. {
  5660. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5661. {
  5662. tempIndex = ((gun_index==2) ? 1: 0);
  5663. }
  5664. else
  5665. {
  5666. tempIndex = gun_index;
  5667. }
  5668. for (int index = 0; index < CCS_QUANTITY; index++)
  5669. {
  5670. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5671. {
  5672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5673. }
  5674. }
  5675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5676. }
  5677. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5678. {
  5679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5680. {
  5681. tempIndex = ((gun_index==2) ? 1: 0);
  5682. }
  5683. else
  5684. {
  5685. tempIndex = gun_index;
  5686. }
  5687. for (int index = 0; index < GB_QUANTITY; index++)
  5688. {
  5689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5690. {
  5691. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5692. }
  5693. }
  5694. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5695. }
  5696. else if(gunType[gun_index] == GUN_TYPE_DO)
  5697. {
  5698. tempIndex = gun_index;
  5699. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5700. {
  5701. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5702. {
  5703. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5704. }
  5705. }
  5706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5707. }
  5708. else
  5709. {
  5710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5711. {
  5712. tempIndex = 2;
  5713. }
  5714. else
  5715. {
  5716. tempIndex = gun_index;
  5717. }
  5718. for (int index = 0; index < AC_QUANTITY; index++)
  5719. {
  5720. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5721. {
  5722. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5723. }
  5724. }
  5725. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5726. }
  5727. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5728. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5729. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5730. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5731. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5732. }
  5733. //********************************(2)Energy.Active.Import.Register ************************************************/
  5734. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5735. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5736. (dataType == ReadingContext_Trigger))
  5737. {
  5738. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5739. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5740. {
  5741. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5742. {
  5743. tempIndex = ((gun_index==2) ? 1: 0);
  5744. }
  5745. else
  5746. {
  5747. tempIndex = gun_index;
  5748. }
  5749. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5750. {
  5751. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5752. {
  5753. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5754. }
  5755. }
  5756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5757. }
  5758. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5759. {
  5760. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5761. {
  5762. tempIndex = ((gun_index==2) ? 1: 0);
  5763. }
  5764. else
  5765. {
  5766. tempIndex = gun_index;
  5767. }
  5768. for (int index = 0; index < CCS_QUANTITY; index++)
  5769. {
  5770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5771. {
  5772. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5773. }
  5774. }
  5775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5776. }
  5777. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5778. {
  5779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5780. {
  5781. tempIndex = ((gun_index==2) ? 1: 0);
  5782. }
  5783. else
  5784. {
  5785. tempIndex = gun_index;
  5786. }
  5787. for (int index = 0; index < GB_QUANTITY; index++)
  5788. {
  5789. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5790. {
  5791. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5792. }
  5793. }
  5794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5795. }
  5796. else if(gunType[gun_index] == GUN_TYPE_DO)
  5797. {
  5798. tempIndex = gun_index;
  5799. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5800. {
  5801. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5802. {
  5803. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5804. }
  5805. }
  5806. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5807. }
  5808. else
  5809. {
  5810. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5811. {
  5812. tempIndex = 2;
  5813. }
  5814. else
  5815. {
  5816. tempIndex = gun_index;
  5817. }
  5818. for (int index = 0; index < AC_QUANTITY; index++)
  5819. {
  5820. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5821. {
  5822. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5823. }
  5824. }
  5825. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5826. }
  5827. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5828. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5829. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5830. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5832. }
  5833. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5834. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5835. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5836. (dataType == ReadingContext_Trigger))
  5837. {
  5838. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5839. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5840. {
  5841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5842. {
  5843. tempIndex = ((gun_index==2) ? 1: 0);
  5844. }
  5845. else
  5846. {
  5847. tempIndex = gun_index;
  5848. }
  5849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5850. {
  5851. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5852. {
  5853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5854. }
  5855. } // END OF FOR CHAdeMO_QUANTITY
  5856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5857. }
  5858. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5859. {
  5860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5861. {
  5862. tempIndex = ((gun_index==2) ? 1: 0);
  5863. }
  5864. else
  5865. {
  5866. tempIndex = gun_index;
  5867. }
  5868. for (int index = 0; index < CCS_QUANTITY; index++)
  5869. {
  5870. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5871. {
  5872. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5873. }
  5874. } // END OF CCS_QUANTITY
  5875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5876. }
  5877. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5878. {
  5879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5880. {
  5881. tempIndex = ((gun_index==2) ? 1: 0);
  5882. }
  5883. else
  5884. {
  5885. tempIndex = gun_index;
  5886. }
  5887. for (int index = 0; index < GB_QUANTITY; index++)
  5888. {
  5889. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5890. {
  5891. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5892. }
  5893. } // END OF GB_QUANTITY
  5894. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5895. }
  5896. else if(gunType[gun_index] == GUN_TYPE_DO)
  5897. {
  5898. tempIndex = gun_index;
  5899. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5900. {
  5901. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5902. {
  5903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5904. }
  5905. }
  5906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5907. }
  5908. else
  5909. {
  5910. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5911. {
  5912. tempIndex = 2;
  5913. }
  5914. else
  5915. {
  5916. tempIndex = gun_index;
  5917. }
  5918. for (int index = 0; index < AC_QUANTITY; index++)
  5919. {
  5920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5921. {
  5922. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5923. }
  5924. }
  5925. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5926. }
  5927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5929. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5932. }
  5933. //********************************(4)Power.Active.Import************************************************/
  5934. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5935. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5936. (dataType == ReadingContext_Trigger))
  5937. {
  5938. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5940. {
  5941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5942. {
  5943. tempIndex = ((gun_index==2) ? 1: 0);
  5944. }
  5945. else
  5946. {
  5947. tempIndex = gun_index;
  5948. }
  5949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5950. {
  5951. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5952. {
  5953. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5954. }
  5955. } // END OF FOR
  5956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5957. }
  5958. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5959. {
  5960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5961. {
  5962. tempIndex = ((gun_index==2) ? 1: 0);
  5963. }
  5964. else
  5965. {
  5966. tempIndex = gun_index;
  5967. }
  5968. for (int index = 0; index < CCS_QUANTITY; index++)
  5969. {
  5970. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5971. {
  5972. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5973. }
  5974. }
  5975. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5976. }
  5977. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5978. {
  5979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5980. {
  5981. tempIndex = ((gun_index==2) ? 1: 0);
  5982. }
  5983. else
  5984. {
  5985. tempIndex = gun_index;
  5986. }
  5987. for (int index = 0; index < GB_QUANTITY; index++)
  5988. {
  5989. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5990. {
  5991. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5992. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5993. }
  5994. }
  5995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5996. }
  5997. else if(gunType[gun_index] == GUN_TYPE_DO)
  5998. {
  5999. tempIndex = gun_index;
  6000. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6001. {
  6002. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6003. {
  6004. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6005. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6006. }
  6007. }
  6008. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6009. }
  6010. else
  6011. {
  6012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6013. {
  6014. tempIndex = 2;
  6015. }
  6016. else
  6017. {
  6018. tempIndex = gun_index;
  6019. }
  6020. for (int index = 0; index < AC_QUANTITY; index++)
  6021. {
  6022. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6023. {
  6024. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6025. }
  6026. }
  6027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6028. }
  6029. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6034. }
  6035. //***********************************************(5)VOLTAGE L1******************************************************/
  6036. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6037. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6038. (dataType == ReadingContext_Trigger))
  6039. {
  6040. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6041. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6042. {
  6043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6044. {
  6045. tempIndex = ((gun_index==2) ? 1: 0);
  6046. }
  6047. else
  6048. {
  6049. tempIndex = gun_index;
  6050. }
  6051. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6052. {
  6053. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6054. {
  6055. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6056. }
  6057. }
  6058. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6059. }
  6060. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6061. {
  6062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6063. {
  6064. tempIndex = ((gun_index==2) ? 1: 0);
  6065. }
  6066. else
  6067. {
  6068. tempIndex = gun_index;
  6069. }
  6070. for (int index = 0; index < CCS_QUANTITY; index++)
  6071. {
  6072. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6073. {
  6074. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6075. }
  6076. }
  6077. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6078. }
  6079. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6080. {
  6081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6082. {
  6083. tempIndex = ((gun_index==2) ? 1: 0);
  6084. }
  6085. else
  6086. {
  6087. tempIndex = gun_index;
  6088. }
  6089. for (int index = 0; index < GB_QUANTITY; index++)
  6090. {
  6091. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6092. {
  6093. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6094. }
  6095. }
  6096. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6097. }
  6098. else if(gunType[gun_index] == GUN_TYPE_DO)
  6099. {
  6100. tempIndex = gun_index;
  6101. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6102. {
  6103. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6104. {
  6105. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6106. }
  6107. }
  6108. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6109. }
  6110. else
  6111. {
  6112. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6113. {
  6114. tempIndex = 2;
  6115. }
  6116. else
  6117. {
  6118. tempIndex = gun_index;
  6119. }
  6120. for (int index = 0; index < AC_QUANTITY; index++)
  6121. {
  6122. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6123. {
  6124. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6125. }
  6126. }
  6127. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6128. }
  6129. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6134. }
  6135. //***********************************************(6)SOC******************************************************/
  6136. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6137. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6138. (dataType == ReadingContext_Trigger))
  6139. {
  6140. 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))
  6141. {
  6142. //idx_sample=5;
  6143. //sampledValue = NULL;
  6144. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6145. {
  6146. tempIndex = ((gun_index==2) ? 1: 0);
  6147. }
  6148. else
  6149. {
  6150. tempIndex = gun_index;
  6151. }
  6152. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6153. {
  6154. //tempIndex = ((gun_index==2) ? 1: 0);
  6155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6156. {
  6157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6158. {
  6159. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6160. }
  6161. }
  6162. }
  6163. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6164. {
  6165. //tempIndex = ((gun_index==2) ? 1: 0);
  6166. for (int index = 0; index < CCS_QUANTITY; index++)
  6167. {
  6168. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6169. {
  6170. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6171. }
  6172. }
  6173. }
  6174. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6175. {
  6176. //tempIndex = ((gun_index==2) ? 1: 0);
  6177. for (int index = 0; index < GB_QUANTITY; index++)
  6178. {
  6179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6180. {
  6181. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6182. }
  6183. }
  6184. }
  6185. else if(gunType[gun_index] == GUN_TYPE_DO)
  6186. {
  6187. //tempIndex = ((gun_index==2) ? 1: 0);
  6188. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6189. {
  6190. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6191. {
  6192. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6193. }
  6194. }
  6195. }
  6196. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6197. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6198. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6202. }
  6203. }
  6204. //********************************(7)Current.Import L2************************************************/
  6205. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6206. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6207. (dataType == ReadingContext_Trigger))
  6208. {
  6209. // Only for AC 3 phase
  6210. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6211. {
  6212. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6213. {
  6214. tempIndex = 2;
  6215. }
  6216. else
  6217. {
  6218. tempIndex = gun_index;
  6219. }
  6220. for (int index = 0; index < AC_QUANTITY; index++)
  6221. {
  6222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6223. {
  6224. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6225. }
  6226. }
  6227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6228. }
  6229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6234. }
  6235. //********************************(8)Current.Import L3************************************************/
  6236. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6237. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6238. (dataType == ReadingContext_Trigger))
  6239. {
  6240. // Only for AC 3 phase
  6241. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6242. {
  6243. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6244. {
  6245. tempIndex = 2;
  6246. }
  6247. else
  6248. {
  6249. tempIndex = gun_index;
  6250. }
  6251. for (int index = 0; index < AC_QUANTITY; index++)
  6252. {
  6253. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6254. {
  6255. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6256. }
  6257. }
  6258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6259. }
  6260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6261. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6262. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6263. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6264. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6265. }
  6266. //***********************************************(9)VOLTAGE L2******************************************************/
  6267. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6268. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6269. (dataType == ReadingContext_Trigger))
  6270. {
  6271. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6272. {
  6273. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6274. {
  6275. tempIndex = 2;
  6276. }
  6277. else
  6278. {
  6279. tempIndex = gun_index;
  6280. }
  6281. for (int index = 0; index < AC_QUANTITY; index++)
  6282. {
  6283. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6284. {
  6285. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6286. }
  6287. }
  6288. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6289. }
  6290. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6291. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6292. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6295. }
  6296. //***********************************************(10)VOLTAGE L3******************************************************/
  6297. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6298. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6299. (dataType == ReadingContext_Trigger))
  6300. {
  6301. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6302. {
  6303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6304. {
  6305. tempIndex = 2;
  6306. }
  6307. else
  6308. {
  6309. tempIndex = gun_index;
  6310. }
  6311. for (int index = 0; index < AC_QUANTITY; index++)
  6312. {
  6313. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6314. {
  6315. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6316. }
  6317. }
  6318. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6319. }
  6320. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6322. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6324. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6325. }
  6326. //***********************************************(11)Current.Offered******************************************************/
  6327. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6328. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6329. (dataType == ReadingContext_Trigger))
  6330. {
  6331. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6332. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6333. {
  6334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6335. {
  6336. tempIndex = ((gun_index==2) ? 1: 0);
  6337. }
  6338. else
  6339. {
  6340. tempIndex = gun_index;
  6341. }
  6342. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6343. {
  6344. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6345. {
  6346. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6347. }
  6348. } // END OF FOR CHAdeMO_QUANTITY
  6349. }
  6350. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6351. {
  6352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6353. {
  6354. tempIndex = ((gun_index==2) ? 1: 0);
  6355. }
  6356. else
  6357. {
  6358. tempIndex = gun_index;
  6359. }
  6360. for (int index = 0; index < CCS_QUANTITY; index++)
  6361. {
  6362. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6363. {
  6364. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6365. }
  6366. } // END OF CCS_QUANTITY
  6367. }
  6368. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6369. {
  6370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6371. {
  6372. tempIndex = ((gun_index==2) ? 1: 0);
  6373. }
  6374. else
  6375. {
  6376. tempIndex = gun_index;
  6377. }
  6378. for (int index = 0; index < GB_QUANTITY; index++)
  6379. {
  6380. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6381. {
  6382. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6383. }
  6384. } // END OF GB_QUANTITY
  6385. }
  6386. else if(gunType[gun_index] == GUN_TYPE_DO)
  6387. {
  6388. tempIndex = gun_index;
  6389. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6390. {
  6391. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6392. {
  6393. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6394. }
  6395. }
  6396. }
  6397. else
  6398. {
  6399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6400. {
  6401. tempIndex = 2;
  6402. }
  6403. else
  6404. {
  6405. tempIndex = gun_index;
  6406. }
  6407. for (int index = 0; index < AC_QUANTITY; index++)
  6408. {
  6409. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6410. {
  6411. uint16_t currentOffer;
  6412. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6413. {
  6414. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6415. }
  6416. else
  6417. {
  6418. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6419. }
  6420. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6421. }
  6422. }
  6423. }
  6424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6429. }
  6430. //***********************************************(12)Power.Offered******************************************************/
  6431. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6432. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6433. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6434. {
  6435. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6436. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6437. {
  6438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6439. {
  6440. tempIndex = ((gun_index==2) ? 1: 0);
  6441. }
  6442. else
  6443. {
  6444. tempIndex = gun_index;
  6445. }
  6446. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6447. {
  6448. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6449. {
  6450. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  6451. }
  6452. } // END OF FOR CHAdeMO_QUANTITY
  6453. }
  6454. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6455. {
  6456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6457. {
  6458. tempIndex = ((gun_index==2) ? 1: 0);
  6459. }
  6460. else
  6461. {
  6462. tempIndex = gun_index;
  6463. }
  6464. for (int index = 0; index < CCS_QUANTITY; index++)
  6465. {
  6466. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6467. {
  6468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  6469. }
  6470. } // END OF CCS_QUANTITY
  6471. }
  6472. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6473. {
  6474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6475. {
  6476. tempIndex = ((gun_index==2) ? 1: 0);
  6477. }
  6478. else
  6479. {
  6480. tempIndex = gun_index;
  6481. }
  6482. for (int index = 0; index < GB_QUANTITY; index++)
  6483. {
  6484. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6485. {
  6486. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  6487. }
  6488. } // END OF GB_QUANTITY
  6489. }
  6490. else if(gunType[gun_index] == GUN_TYPE_DO)
  6491. {
  6492. tempIndex = gun_index;
  6493. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6494. {
  6495. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6496. {
  6497. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  6498. }
  6499. }
  6500. }
  6501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6506. }
  6507. // Message create ====================================================================================================
  6508. if(TRUE)
  6509. {
  6510. json_object *MeterValueReq = json_object_new_object();
  6511. json_object *MeterValues = json_object_new_array();
  6512. json_object *sampledValues = json_object_new_array();
  6513. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6514. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6515. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6516. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6517. {
  6518. json_object *MeterValue = json_object_new_object();
  6519. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6520. {
  6521. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6522. {
  6523. json_object *sampledValue = json_object_new_object();
  6524. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6525. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6526. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6527. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6528. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6529. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6530. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6531. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6532. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6533. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6534. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6535. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6536. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6537. json_object_array_add(sampledValues, sampledValue);
  6538. }
  6539. }
  6540. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6541. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6542. json_object_array_add(MeterValues, MeterValue);
  6543. }
  6544. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6545. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6546. ,gun_index + 1
  6547. ,MESSAGE_TYPE_CALL
  6548. ,guid
  6549. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6550. json_object_put(MeterValueReq);
  6551. }
  6552. // Put request guid to hash map
  6553. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6554. 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*/)
  6555. {
  6556. result = PASS;
  6557. //DEBUG_INFO("MeterValues mapitem pass\n");
  6558. }
  6559. if((dataType != ReadingContext_Trigger) &&
  6560. (dataType != ReadingContext_Sample_Clock) &&
  6561. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6562. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6563. else
  6564. {
  6565. if(FirstHeartBeat)
  6566. LWS_Send(queuedata +2);
  6567. }
  6568. return result;
  6569. }
  6570. int sendLogStatusNotificationRequest(char *status)
  6571. {
  6572. mtrace();
  6573. int result = PASS;
  6574. char message[4096]={0};
  6575. char guid[37]={0};
  6576. char tempdata[128]={0};
  6577. json_object *LogStatusNotification = json_object_new_object();
  6578. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6579. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6580. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6581. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6582. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6583. random_uuid(guid);
  6584. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6585. json_object_put(LogStatusNotification);
  6586. LWS_Send(message);
  6587. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6588. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6589. {
  6590. result = PASS;
  6591. }
  6592. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6593. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6594. return result;
  6595. }
  6596. int sendSecurityEventNotificationRequest()
  6597. {
  6598. mtrace();
  6599. int result = PASS;
  6600. char message[4096]={0};
  6601. char guid[37]={0};
  6602. char tempdata[128]={0};
  6603. json_object *SecurityEventNotification = json_object_new_object();
  6604. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6605. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6606. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6607. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6608. random_uuid(guid);
  6609. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6610. json_object_put(SecurityEventNotification);
  6611. LWS_Send(message);
  6612. sprintf(tempdata, "SecurityEventNotification,0");
  6613. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6614. {
  6615. result = PASS;
  6616. }
  6617. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6618. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6619. return result;
  6620. }
  6621. int sendSignCertificateRequest()
  6622. {
  6623. mtrace();
  6624. int result = PASS;
  6625. char message[4096]={0};
  6626. char guid[37]={0};
  6627. char tempdata[128]={0};
  6628. json_object *SignCertificate = json_object_new_object();
  6629. DEBUG_INFO("sendSignCertificateRequest...\n");
  6630. // Read csr file content
  6631. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6632. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6633. char *line = NULL;
  6634. size_t len = 0;
  6635. while(getline(&line, &len, fp) != -1)
  6636. {
  6637. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6638. {
  6639. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6640. }
  6641. }
  6642. fclose(fp);
  6643. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6644. random_uuid(guid);
  6645. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6646. json_object_put(SignCertificate);
  6647. LWS_Send(message);
  6648. sprintf(tempdata, "SignCertificate,0");
  6649. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6650. {
  6651. result = PASS;
  6652. }
  6653. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6654. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6655. return result;
  6656. }
  6657. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6658. {
  6659. mtrace();
  6660. int result = PASS;
  6661. char message[110]={0};
  6662. char guid[37]={0};
  6663. char tempdata[65]={0};
  6664. json_object *FirmwareStatusNotification = json_object_new_object();
  6665. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6666. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6667. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6668. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6669. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6670. random_uuid(guid);
  6671. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6672. json_object_put(FirmwareStatusNotification);
  6673. LWS_Send(message);
  6674. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6675. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6676. {
  6677. result = PASS;
  6678. }
  6679. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6680. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6681. return result;
  6682. }
  6683. //==========================================
  6684. // send confirm routine
  6685. //==========================================
  6686. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6687. {
  6688. mtrace();
  6689. int result = FAIL;
  6690. char message[100]={0};
  6691. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6692. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6693. LWS_Send(message);
  6694. result = TRUE;
  6695. return result;
  6696. }
  6697. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6698. {
  6699. mtrace();
  6700. int result = FAIL;
  6701. char message[100]={0};
  6702. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6703. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6704. LWS_Send(message);
  6705. result = TRUE;
  6706. return result;
  6707. }
  6708. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6709. {
  6710. mtrace();
  6711. int result = FAIL;
  6712. char message[100]={0};
  6713. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6714. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6715. LWS_Send(message);
  6716. result = TRUE;
  6717. return result;
  6718. }
  6719. int sendClearCacheConfirmation(char *uuid,char *payload)
  6720. {
  6721. mtrace();
  6722. int result = FAIL;
  6723. char message[500]={0};
  6724. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6725. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6726. LWS_Send(message);
  6727. return result;
  6728. }
  6729. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6730. {
  6731. mtrace();
  6732. int result = FAIL;
  6733. char message[500]={0};
  6734. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6735. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6736. LWS_Send(message);
  6737. return result;
  6738. }
  6739. int sendDataTransferConfirmation(char *uuid,char *payload)
  6740. {
  6741. mtrace();
  6742. char statusStr[20]={0};
  6743. char dataStr[10]={0};
  6744. char sstr[20]={0};
  6745. int c = 0;
  6746. char *loc;
  6747. int result = FAIL;
  6748. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6749. /**********************status**************************/
  6750. loc = strstr(payload, "status");
  6751. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6752. c = 0;
  6753. while (loc[3+strlen("status")+c] != '\"')
  6754. {
  6755. sstr[c] = loc[3+strlen("status")+c];
  6756. c++;
  6757. }
  6758. sstr[c] = '\0';
  6759. strcpy(statusStr, sstr);
  6760. /**********************data**************************/
  6761. loc = strstr(payload, "data");
  6762. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6763. c = 0;
  6764. while (loc[3+strlen("data")+c] != '\"')
  6765. {
  6766. sstr[c] = loc[3+strlen("data")+c];
  6767. c++;
  6768. }
  6769. sstr[c] = '\0';
  6770. strcpy(dataStr, sstr);
  6771. return result;
  6772. }
  6773. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6774. {
  6775. mtrace();
  6776. int result = FAIL;
  6777. char message[1000]={0};
  6778. int CompositeScheduleIndex = 0;
  6779. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6780. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6781. if(nPeriod == 0)
  6782. {
  6783. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6784. {
  6785. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6786. ,MESSAGE_TYPE_CALLRESULT
  6787. ,uuid
  6788. ,payload
  6789. ,connectorIdInt);
  6790. }
  6791. else
  6792. {
  6793. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6794. ,MESSAGE_TYPE_CALLRESULT
  6795. ,uuid
  6796. ,payload
  6797. ,connectorIdInt
  6798. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6799. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6800. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6801. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6802. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6803. }
  6804. }
  6805. else
  6806. {
  6807. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6808. ,MESSAGE_TYPE_CALLRESULT
  6809. ,uuid
  6810. ,payload
  6811. ,connectorIdInt
  6812. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6813. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6814. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6815. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6816. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6817. {
  6818. if (idx_sample == 0)
  6819. {
  6820. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6821. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6822. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6823. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6824. }
  6825. else
  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. }
  6833. sprintf(message + strlen(message), "]}}]");
  6834. }
  6835. LWS_Send(message);
  6836. result = TRUE;
  6837. return result;
  6838. }
  6839. int sendGetConfigurationConfirmation(char *uuid)
  6840. {
  6841. mtrace();
  6842. int result = FAIL;
  6843. int MaxKeySupported = 0;
  6844. int sentConfigurationNumber= 0;
  6845. int sentunConfigurationNumber= 0;
  6846. char message[1024*10]={0};
  6847. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6848. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6849. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6850. ,MESSAGE_TYPE_CALLRESULT
  6851. ,uuid );
  6852. //configuration key
  6853. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6854. {
  6855. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6856. {
  6857. if (sentConfigurationNumber == 0)
  6858. {
  6859. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6860. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6861. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6862. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6863. }
  6864. else
  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. sentConfigurationNumber = sentConfigurationNumber + 1;
  6872. }
  6873. }
  6874. sprintf(message + strlen(message), "]");
  6875. if(UnknownKeynum != 0)
  6876. {
  6877. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6878. //unkown key
  6879. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6880. {
  6881. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6882. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6883. if(sentunConfigurationNumber == 0)
  6884. {
  6885. sprintf(message + strlen(message), "\"%s\""
  6886. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6887. }
  6888. else
  6889. {
  6890. sprintf(message + strlen(message), ",\"%s\""
  6891. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6892. }
  6893. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6894. }
  6895. sprintf(message + strlen(message), "]");
  6896. }
  6897. sprintf(message + strlen(message), "}]");
  6898. LWS_Send(message);
  6899. return result;
  6900. }
  6901. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6902. {
  6903. mtrace();
  6904. int result = FAIL;
  6905. char message[400]={0};
  6906. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6907. if(strcmp(payload,"")==0)
  6908. {
  6909. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6910. }
  6911. else
  6912. {
  6913. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6914. }
  6915. LWS_Send(message);
  6916. result = TRUE;
  6917. return result;
  6918. }
  6919. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6920. {
  6921. mtrace();
  6922. int result = FAIL;
  6923. char message[80]={0};
  6924. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6925. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6926. LWS_Send(message);
  6927. result = TRUE;
  6928. return result;
  6929. }
  6930. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6931. {
  6932. mtrace();
  6933. int result = FAIL;
  6934. char message[80]={0};
  6935. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6936. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6937. LWS_Send(message);
  6938. result = TRUE;
  6939. return result;
  6940. }
  6941. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6942. {
  6943. mtrace();
  6944. int result = FAIL;
  6945. char message[80]={0};
  6946. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6947. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6948. LWS_Send(message);
  6949. result = TRUE;
  6950. return result;
  6951. }
  6952. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6953. {
  6954. mtrace();
  6955. int result = FAIL;
  6956. char message[80]={0};
  6957. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6958. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6959. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6960. LWS_Send(message);
  6961. result = TRUE;
  6962. return result;
  6963. }
  6964. int sendResetConfirmation(char *uuid,char *payload)
  6965. {
  6966. mtrace();
  6967. int result = FAIL;
  6968. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6969. char message[80]={0};
  6970. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6971. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6972. LWS_Send(message);
  6973. result = TRUE;
  6974. return result;
  6975. }
  6976. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6977. {
  6978. mtrace();
  6979. int result = FAIL;
  6980. char message[500]={0};
  6981. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6982. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6983. LWS_Send(message);
  6984. result = TRUE;
  6985. return result;
  6986. }
  6987. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6988. {
  6989. mtrace();
  6990. int result = FAIL;
  6991. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6992. char message[80]={0};
  6993. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6994. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6995. LWS_Send(message);
  6996. result = TRUE;
  6997. return result;
  6998. }
  6999. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7000. {
  7001. mtrace();
  7002. int result = FAIL;
  7003. char message[80]={0};
  7004. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7005. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7006. LWS_Send(message);
  7007. result = TRUE;
  7008. return result;
  7009. }
  7010. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7011. {
  7012. mtrace();
  7013. int result = FAIL;
  7014. char message[80]={0};
  7015. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7016. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7017. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7018. LWS_Send(message);
  7019. result = TRUE;
  7020. return result;
  7021. }
  7022. int sendUpdateFirmwareConfirmation(char *uuid)
  7023. {
  7024. mtrace();
  7025. int result = FAIL;
  7026. char message[60]={0};
  7027. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7028. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7029. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7030. LWS_Send(message);
  7031. result = TRUE;
  7032. return result;
  7033. }
  7034. int sendCertificateSignedConfirmation(char *uuid)
  7035. {
  7036. mtrace();
  7037. int result = PASS;
  7038. char message[4096]={0};
  7039. json_object *CertificateSigned = json_object_new_object();
  7040. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7041. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7042. sprintf(message,"[%d,\"%s\",%s]"
  7043. ,MESSAGE_TYPE_CALLRESULT
  7044. ,uuid
  7045. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7046. json_object_put(CertificateSigned);
  7047. LWS_Send(message);
  7048. return result;
  7049. }
  7050. int sendDeleteCertificateConfirmation(char *uuid)
  7051. {
  7052. mtrace();
  7053. int result = PASS;
  7054. char message[4096]={0};
  7055. json_object *DeleteCertificate = json_object_new_object();
  7056. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7057. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7058. sprintf(message,"[%d,\"%s\",%s]"
  7059. ,MESSAGE_TYPE_CALLRESULT
  7060. ,uuid
  7061. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7062. json_object_put(DeleteCertificate);
  7063. LWS_Send(message);
  7064. return result;
  7065. }
  7066. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7067. {
  7068. mtrace();
  7069. int result = PASS;
  7070. char message[4096]={0};
  7071. json_object *ExtendedTriggerMessage = json_object_new_object();
  7072. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7073. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7074. sprintf(message,"[%d,\"%s\",%s]"
  7075. ,MESSAGE_TYPE_CALLRESULT
  7076. ,uuid
  7077. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7078. json_object_put(ExtendedTriggerMessage);
  7079. LWS_Send(message);
  7080. return result;
  7081. }
  7082. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7083. {
  7084. mtrace();
  7085. int result = PASS;
  7086. char message[4096]={0};
  7087. json_object *GetInstalledCertificateIds = json_object_new_object();
  7088. json_object *certificateHashDataDatas = json_object_new_array();
  7089. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7090. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7091. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7092. {
  7093. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7094. {
  7095. json_object *certificateHashData = json_object_new_object();
  7096. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7097. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7098. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7099. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7100. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7101. }
  7102. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7103. }
  7104. else
  7105. {
  7106. json_object_put(certificateHashDataDatas);
  7107. }
  7108. sprintf(message,"[%d,\"%s\",%s]"
  7109. ,MESSAGE_TYPE_CALLRESULT
  7110. ,uuid
  7111. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7112. json_object_put(GetInstalledCertificateIds);
  7113. LWS_Send(message);
  7114. return result;
  7115. }
  7116. int sendGetLogConfirmation(char *uuid)
  7117. {
  7118. mtrace();
  7119. int result = PASS;
  7120. char message[4096]={0};
  7121. json_object *GetLog = json_object_new_object();
  7122. DEBUG_INFO("sendGetLogConfirmation...\n");
  7123. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7124. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7125. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7126. sprintf(message,"[%d,\"%s\",%s]"
  7127. ,MESSAGE_TYPE_CALLRESULT
  7128. ,uuid
  7129. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7130. json_object_put(GetLog);
  7131. LWS_Send(message);
  7132. return result;
  7133. }
  7134. int sendInstallCertificateConfirmation(char *uuid)
  7135. {
  7136. mtrace();
  7137. int result = PASS;
  7138. char message[4096]={0};
  7139. json_object *InstallCertificate = json_object_new_object();
  7140. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7141. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7142. sprintf(message,"[%d,\"%s\",%s]"
  7143. ,MESSAGE_TYPE_CALLRESULT
  7144. ,uuid
  7145. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7146. json_object_put(InstallCertificate);
  7147. LWS_Send(message);
  7148. return result;
  7149. }
  7150. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7151. {
  7152. mtrace();
  7153. int result = PASS;
  7154. char message[4096]={0};
  7155. json_object *SignedUpdateFirmware = json_object_new_object();
  7156. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7157. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7158. sprintf(message,"[%d,\"%s\",%s]"
  7159. ,MESSAGE_TYPE_CALLRESULT
  7160. ,uuid
  7161. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7162. json_object_put(SignedUpdateFirmware);
  7163. LWS_Send(message);
  7164. return result;
  7165. }
  7166. int sendUnknownConfirmation(char *uuid)
  7167. {
  7168. mtrace();
  7169. int result = PASS;
  7170. char message[256]={0};
  7171. DEBUG_INFO("sendUnknownConfirmation...\n");
  7172. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7173. LWS_Send(message);
  7174. return result;
  7175. }
  7176. //==========================================
  7177. // Handle server request routine Start
  7178. //==========================================
  7179. int handleCancelReservationRequest(char *uuid, char *payload)
  7180. {
  7181. mtrace();
  7182. int result = FAIL;
  7183. int gunNO = 0;
  7184. int reservationIdInt = -1;
  7185. char comfirmstr[20];
  7186. DEBUG_INFO("handleCancelReservationRequest...\n");
  7187. json_object *CancelReservation;
  7188. CancelReservation = json_tokener_parse(payload);
  7189. if(!is_error(CancelReservation))
  7190. {
  7191. // Required data
  7192. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7193. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7194. }
  7195. json_object_put(CancelReservation);
  7196. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7197. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7198. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7199. if(reservationIdInt != -1)
  7200. {
  7201. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7202. //check Transaction active
  7203. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7205. {
  7206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7207. {
  7208. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7209. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7210. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7211. {
  7212. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7213. }
  7214. else
  7215. {
  7216. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7217. }
  7218. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7219. goto end;
  7220. }
  7221. }
  7222. for (int index = 0; index < CCS_QUANTITY; index++)
  7223. {
  7224. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7225. {
  7226. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7227. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7228. if(gunType[2] == GUN_TYPE_CCS)
  7229. {
  7230. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7231. }
  7232. else
  7233. {
  7234. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7235. }
  7236. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7237. goto end;
  7238. }
  7239. }
  7240. for (int index = 0; index < GB_QUANTITY; index++)
  7241. {
  7242. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7243. {
  7244. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7245. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7246. if(gunType[2] == GUN_TYPE_GBT)
  7247. {
  7248. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7249. }
  7250. else
  7251. {
  7252. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7253. }
  7254. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7255. goto end;
  7256. }
  7257. }
  7258. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7259. {
  7260. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7261. {
  7262. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7263. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7264. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7265. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7266. goto end;
  7267. }
  7268. }
  7269. for (int index = 0; index < AC_QUANTITY; index++)
  7270. {
  7271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7272. {
  7273. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7274. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7276. {
  7277. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7278. }
  7279. else
  7280. {
  7281. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7282. }
  7283. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7284. goto end;
  7285. }
  7286. }
  7287. }
  7288. //The reservationId does NOT match the reservationId
  7289. sendCancelReservationConfirmation(uuid, comfirmstr);
  7290. end:
  7291. // Fill in ocpp packet uuid
  7292. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7293. return result;
  7294. }
  7295. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7296. {
  7297. mtrace();
  7298. int result = FAIL;
  7299. int gunIndex = 0;
  7300. char typeStr[16]={0};
  7301. char comfirmstr[20];
  7302. int specificId = FALSE;
  7303. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7304. json_object *ChangeAvailability;
  7305. ChangeAvailability = json_tokener_parse(payload);
  7306. if(!is_error(ChangeAvailability))
  7307. {
  7308. // Required data
  7309. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7310. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7311. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7312. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7313. }
  7314. json_object_put(ChangeAvailability);
  7315. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7316. {
  7317. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7318. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7319. }
  7320. else if(gunIndex == 0)
  7321. {
  7322. for(int i=0; i < gunTotalNumber; i++)
  7323. {
  7324. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7325. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7326. }
  7327. }
  7328. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7329. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7330. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7331. {
  7332. specificId = TRUE;
  7333. }
  7334. if(specificId == FALSE)
  7335. goto end;
  7336. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7337. {
  7338. //----------------------gunIndex is 0 ------------------------------------------------//
  7339. if(gunIndex == 0)
  7340. {
  7341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7342. {
  7343. for(int i=0; i < gunTotalNumber; i++)
  7344. {
  7345. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7346. {
  7347. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7348. {
  7349. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7350. {
  7351. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7352. goto end;
  7353. }
  7354. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7355. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7356. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7357. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7358. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7359. {
  7360. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7361. goto end;
  7362. }
  7363. }
  7364. }//END FOR CHAdeMO_QUANTITY
  7365. for (int index = 0; index < CCS_QUANTITY; index++)
  7366. {
  7367. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7368. {
  7369. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7370. {
  7371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7372. goto end;
  7373. }
  7374. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7375. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7376. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7377. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7378. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7379. {
  7380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7381. goto end;
  7382. }
  7383. }
  7384. }//END FOR CCS_QUANTITY
  7385. for (int index = 0; index < GB_QUANTITY; index++)
  7386. {
  7387. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7388. {
  7389. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7390. {
  7391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7392. goto end;
  7393. }
  7394. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7395. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7396. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7397. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7398. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7399. {
  7400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7401. goto end;
  7402. }
  7403. }
  7404. }// END FOR GB_QUANTITY
  7405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7406. {
  7407. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7408. {
  7409. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7410. {
  7411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7412. goto end;
  7413. }
  7414. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7415. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7416. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7417. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7418. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7419. {
  7420. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7421. goto end;
  7422. }
  7423. }
  7424. }// END FOR GENERAL_GUN_QUANTITY
  7425. for (int index = 0; index < AC_QUANTITY; index++)
  7426. {
  7427. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7428. {
  7429. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7430. {
  7431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7432. goto end;
  7433. }
  7434. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7435. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7436. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7437. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7438. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7439. {
  7440. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7441. goto end;
  7442. }
  7443. }
  7444. }//END FOR AC_QUANTITY
  7445. }// END FOR gunTotalNumber
  7446. }
  7447. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7448. {
  7449. for(int i=0; i < gunTotalNumber; i++)
  7450. {
  7451. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7452. {
  7453. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7454. goto end;
  7455. }
  7456. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7457. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7458. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7459. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7460. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7461. {
  7462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7463. goto end;
  7464. }
  7465. }
  7466. }
  7467. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7468. goto end;
  7469. }
  7470. //----------------------gunIndex is not 0 ------------------------------------------------//
  7471. //check Transaction active
  7472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7473. {
  7474. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7475. {
  7476. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7477. {
  7478. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7479. goto end;
  7480. }
  7481. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7482. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7483. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7484. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7485. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7486. {
  7487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7488. goto end;
  7489. }
  7490. else
  7491. {
  7492. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7493. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7494. goto end;
  7495. }
  7496. }
  7497. }//END FOR CHAdeMO_QUANTITY
  7498. for (int index = 0; index < CCS_QUANTITY; index++)
  7499. {
  7500. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7501. {
  7502. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7503. {
  7504. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7505. goto end;
  7506. }
  7507. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7508. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7509. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7510. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7511. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7512. {
  7513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7514. goto end;
  7515. }
  7516. else
  7517. {
  7518. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7519. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7520. goto end;
  7521. }
  7522. }
  7523. }//END FOR CCS_QUANTITY
  7524. for (int index = 0; index < GB_QUANTITY; index++)
  7525. {
  7526. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7527. {
  7528. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7529. {
  7530. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7531. goto end;
  7532. }
  7533. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7534. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7535. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7536. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7537. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7538. {
  7539. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7540. goto end;
  7541. }
  7542. else
  7543. {
  7544. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7545. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7546. goto end;
  7547. }
  7548. }
  7549. }// END FOR GB_QUANTITY
  7550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7551. {
  7552. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7553. {
  7554. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7555. {
  7556. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7557. goto end;
  7558. }
  7559. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7560. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7561. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7562. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7563. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7564. {
  7565. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7566. goto end;
  7567. }
  7568. else
  7569. {
  7570. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7572. goto end;
  7573. }
  7574. }
  7575. }// END FOR GENERAL_GUN_QUANTITY
  7576. for (int index = 0; index < AC_QUANTITY; index++)
  7577. {
  7578. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7579. {
  7580. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7581. {
  7582. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7583. goto end;
  7584. }
  7585. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7586. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7587. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7588. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7589. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7590. {
  7591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7592. goto end;
  7593. }
  7594. else
  7595. {
  7596. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7597. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7598. goto end;
  7599. }
  7600. }
  7601. }//END FOR AC_QUANTITY
  7602. }//END FOR AvailabilityTypeStr[Inoperative]
  7603. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7604. {
  7605. //----------------------gunIndex is 0 ------------------------------------------------//
  7606. if(gunIndex == 0)
  7607. {
  7608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7609. {
  7610. for(int i=0; i < gunTotalNumber; i++)
  7611. {
  7612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7613. {
  7614. 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
  7615. {
  7616. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7617. goto end;
  7618. }
  7619. }//END FOR CHAdeMO_QUANTITY
  7620. for (int index = 0; index < CCS_QUANTITY; index++)
  7621. {
  7622. 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
  7623. {
  7624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7625. goto end;
  7626. }
  7627. }//END FOR CCS_QUANTITY
  7628. for (int index = 0; index < GB_QUANTITY; index++)
  7629. {
  7630. 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
  7631. {
  7632. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7633. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7634. goto end;
  7635. }
  7636. }// END FOR GB_QUANTITY
  7637. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7638. {
  7639. 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
  7640. {
  7641. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7643. goto end;
  7644. }
  7645. }// END FOR GENERAL_GUN_QUANTITY
  7646. for (int index = 0; index < AC_QUANTITY; index++)
  7647. {
  7648. 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
  7649. {
  7650. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7651. goto end;
  7652. }
  7653. }//END FOR CHAdeMO_QUANTITY
  7654. }// END FOR gunTotalNumber
  7655. }
  7656. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7657. {
  7658. for(int i=0; i < gunTotalNumber; i++)
  7659. {
  7660. for (int index = 0; index < AC_QUANTITY; index++)
  7661. {
  7662. 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
  7663. {
  7664. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7665. goto end;
  7666. }
  7667. }//END FOR CHAdeMO_QUANTITY
  7668. } // END FOR gunTotalNumber
  7669. }
  7670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7671. goto end;
  7672. }
  7673. //----------------------gunIndex is not 0 ------------------------------------------------//
  7674. //check Transaction active
  7675. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7676. {
  7677. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7678. {
  7679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7680. goto end;
  7681. }
  7682. }//END FOR CHAdeMO_QUANTITY
  7683. for (int index = 0; index < CCS_QUANTITY; index++)
  7684. {
  7685. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7686. {
  7687. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7688. goto end;
  7689. }
  7690. }//END FOR CCS_QUANTITY
  7691. for (int index = 0; index < GB_QUANTITY; index++)
  7692. {
  7693. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7694. {
  7695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7696. goto end;
  7697. }
  7698. }// END FOR GB_QUANTITY
  7699. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7700. {
  7701. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7702. {
  7703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7704. goto end;
  7705. }
  7706. }// END FOR GENERAL_GUN_QUANTITY
  7707. for (int index = 0; index < AC_QUANTITY; index++)
  7708. {
  7709. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7710. {
  7711. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7712. goto end;
  7713. }
  7714. }//END FOR AC_QUANTITY
  7715. }//END FOR AvailabilityTypeStr[Operative]
  7716. end:
  7717. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7718. {
  7719. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7720. }
  7721. else
  7722. {
  7723. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7724. }
  7725. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7726. {
  7727. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7728. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7729. }
  7730. else if(gunIndex == 0)
  7731. {
  7732. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7733. {
  7734. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7735. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7736. }
  7737. }
  7738. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7739. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7740. return result;
  7741. }
  7742. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7743. {
  7744. mtrace();
  7745. int result = FAIL;
  7746. char keystr[40]={0};
  7747. char valuestr[256]={0};
  7748. char comfirmstr[20]={0};
  7749. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7750. json_object *ChangeConfiguration;
  7751. ChangeConfiguration = json_tokener_parse(payload);
  7752. if(!is_error(ChangeConfiguration))
  7753. {
  7754. // Required data
  7755. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7756. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7757. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7758. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7759. }
  7760. json_object_put(ChangeConfiguration);
  7761. if((uuid==NULL) || (payload ==NULL) )
  7762. {
  7763. DEBUG_ERROR("Payload is null\n");
  7764. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7765. }
  7766. else
  7767. {
  7768. int status = setKeyValue(keystr, valuestr);
  7769. switch(status)
  7770. {
  7771. case ConfigurationStatus_Accepted:
  7772. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7773. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7774. StoreConfigurationTable();
  7775. break;
  7776. case RebootRequired:
  7777. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7778. StoreConfigurationTable();
  7779. break;
  7780. case NotSupported:
  7781. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7782. break;
  7783. case ConfigurationStatus_Rejected:
  7784. default:
  7785. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7786. break;
  7787. }
  7788. }
  7789. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7790. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7791. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7792. {
  7793. ChageWebSocketPingInterval(atoi(valuestr));
  7794. }
  7795. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7796. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7797. {
  7798. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7799. SetOcppConnStatus(FALSE);
  7800. }
  7801. return result;
  7802. }
  7803. int handleClearCacheRequest(char *uuid, char *payload)
  7804. {
  7805. mtrace();
  7806. int result = FAIL;
  7807. char comfirmstr[20];
  7808. char rmFileCmd[100]={0};
  7809. struct stat stats;
  7810. DEBUG_INFO("handleClearCacheRequest...\n");
  7811. stat("/Storage/OCPP", &stats);
  7812. // Check for directory existence
  7813. if (S_ISDIR(stats.st_mode) == 1)
  7814. {}
  7815. else
  7816. {
  7817. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7818. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7819. system(rmFileCmd);
  7820. }
  7821. if(OCPP_cleanLocalCache())
  7822. {
  7823. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7824. }
  7825. else
  7826. {
  7827. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7828. }
  7829. sendClearCacheConfirmation(uuid, comfirmstr);
  7830. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7831. return result;
  7832. }
  7833. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7834. {
  7835. mtrace();
  7836. int result = FAIL;
  7837. int resultRename;
  7838. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7839. char chargingProfilePurposeStr[26]={0};
  7840. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7841. char tempchargingProfilePurposeStr[26]={0};
  7842. char str[100]={0};
  7843. char fname[200]={0};
  7844. char comfirmstr[20]={0};
  7845. char word[1600]={0};
  7846. int clearflag = FALSE;
  7847. int chargingProfileIdIsNULL = FALSE;
  7848. int connectorIsNULL = FALSE;
  7849. int chargingProfilePurposeIsNULL = FALSE;
  7850. int stackLevelIsNULL = FALSE;
  7851. //int GotoEnd = FALSE;
  7852. FILE *fptr1, *fptr2;
  7853. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7854. int n_chargingProfile=0;
  7855. int isEmptyFile = FALSE;
  7856. char sLineWord[1600]={0};
  7857. char chargingProfiles[10][100]={0};
  7858. int ChargeProfileCount = 0;
  7859. int ch;
  7860. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7861. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7862. json_object *ClearChargingProfile;
  7863. ClearChargingProfile = json_tokener_parse(payload);
  7864. if(!is_error(ClearChargingProfile))
  7865. {
  7866. // Optional data
  7867. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7868. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7869. else
  7870. chargingProfileIdIsNULL = TRUE;
  7871. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7872. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7873. else
  7874. connectorIsNULL = TRUE;
  7875. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7876. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7877. else
  7878. chargingProfilePurposeIsNULL = TRUE;
  7879. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7880. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7881. else
  7882. stackLevelIsNULL = TRUE;
  7883. }
  7884. json_object_put(ClearChargingProfile);
  7885. if(connectorIsNULL == FALSE)
  7886. {
  7887. switch(connectorIdInt)
  7888. {
  7889. case 0:
  7890. if(chargingProfilePurposeIsNULL == TRUE)
  7891. {
  7892. int l = 0;
  7893. strcpy(fname, ChargePointMaxProfile_JSON);
  7894. if((access(fname,F_OK))!=-1)
  7895. {
  7896. strcpy(chargingProfiles[l], fname);
  7897. l = l + 1;
  7898. }
  7899. strcpy(fname, TxDefaultProfile_0_JSON);
  7900. if((access(fname,F_OK))!=-1)
  7901. {
  7902. strcpy(chargingProfiles[l], fname);
  7903. l = l + 1;
  7904. }
  7905. ChargeProfileCount = l;
  7906. }
  7907. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7908. {
  7909. strcpy(fname, ChargePointMaxProfile_JSON);
  7910. if((access(fname,F_OK))!=-1)
  7911. {
  7912. strcpy(chargingProfiles[0], fname);
  7913. ChargeProfileCount = 1;
  7914. }
  7915. }
  7916. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7917. {
  7918. strcpy(fname, TxDefaultProfile_0_JSON);
  7919. if((access(fname,F_OK))!=-1)
  7920. {
  7921. strcpy(chargingProfiles[0], fname);
  7922. ChargeProfileCount = 1;
  7923. }
  7924. }
  7925. break;
  7926. default:
  7927. if(chargingProfilePurposeIsNULL == TRUE)
  7928. {
  7929. int m = 0;
  7930. memset(fname, 0, ARRAY_SIZE(fname));
  7931. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7932. if((access(fname,F_OK))!=-1)
  7933. {
  7934. strcpy(chargingProfiles[m], fname);
  7935. m = m + 1;
  7936. }
  7937. memset(fname, 0, ARRAY_SIZE(fname));
  7938. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7939. if((access(fname,F_OK))!=-1)
  7940. {
  7941. strcpy(chargingProfiles[m], fname);
  7942. m = m + 1;
  7943. }
  7944. ChargeProfileCount = m;
  7945. }
  7946. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7947. {
  7948. //strcpy(fname, TxDefaultProfile_1_JSON);
  7949. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7950. if((access(fname,F_OK))!=-1)
  7951. {
  7952. strcpy(chargingProfiles[0], fname);
  7953. ChargeProfileCount = 1;
  7954. }
  7955. }
  7956. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7957. {
  7958. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7959. if((access(fname,F_OK))!=-1)
  7960. {
  7961. strcpy(chargingProfiles[0], fname);
  7962. ChargeProfileCount = 1;
  7963. }
  7964. //strcpy(fname, TxProfile_1_JSON);
  7965. }
  7966. //strcpy(fname, ChargePointMaxProfile_JSON );
  7967. break;
  7968. }
  7969. }
  7970. else // Check all Charging Profiles
  7971. {
  7972. int i = 0;
  7973. char fnametemp[200]={0};
  7974. ChargeProfileCount = 0;
  7975. //Check ChargePointMaxProfile.json exit
  7976. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7977. {
  7978. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7979. i = i + 1;
  7980. }
  7981. //Check TxDefaultProfile_0.json exit
  7982. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7983. {
  7984. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7985. i = i + 1;
  7986. }
  7987. //Check TxDefaultProfile_%d.json
  7988. for(int j=1; j <= gunTotalNumber; j++)
  7989. {
  7990. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7991. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7992. if((access(fnametemp,F_OK))!=-1)
  7993. {
  7994. strcpy(chargingProfiles[i], fnametemp);
  7995. i = i + 1;
  7996. }
  7997. }
  7998. //Check TxProfile_%d.json
  7999. for(int j=1; j <= gunTotalNumber; j++)
  8000. {
  8001. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8002. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8003. if((access(fnametemp,F_OK))!=-1)
  8004. {
  8005. strcpy(chargingProfiles[i], fnametemp);
  8006. i = i + 1;
  8007. }
  8008. }
  8009. ChargeProfileCount = i;
  8010. }// End connectorIsNULL is TRUE
  8011. if(ChargeProfileCount == 0)
  8012. {
  8013. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8014. goto end;
  8015. }
  8016. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8017. {
  8018. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8019. goto end;
  8020. }
  8021. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8022. {
  8023. memset(str, 0, ARRAY_SIZE(str));
  8024. // clear temp file
  8025. sprintf(str,"rm -f %s",temp);
  8026. system(str);
  8027. for(int k=0; k < ChargeProfileCount; k++)
  8028. {
  8029. memset(str, 0, ARRAY_SIZE(str));
  8030. //clear file in C
  8031. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8032. system(str);
  8033. }
  8034. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8035. goto end;
  8036. }
  8037. else if(connectorIsNULL == TRUE)
  8038. {
  8039. for(int k=0; k < ChargeProfileCount; k++)
  8040. {
  8041. fptr1 = fopen(chargingProfiles[k], "r");
  8042. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8043. //Check Charging Profile Count
  8044. while(fscanf(fptr1, "%s", word) != EOF)
  8045. {
  8046. //DEBUG_INFO("word=%s\n",word);
  8047. if(strstr(word, "chargingProfileId")!= NULL)
  8048. {
  8049. //DEBUG_INFO("test chargingProfileId \n");
  8050. n_chargingProfile = n_chargingProfile + 1;
  8051. //DEBUG_INFO("chargingProfileId Found\n");
  8052. }
  8053. }
  8054. rewind(fptr1);
  8055. //search Charging Profile Element
  8056. //int i= 0;
  8057. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8058. {
  8059. json_object *tmpProfilee;
  8060. tmpProfilee = json_tokener_parse(sLineWord);
  8061. if(!is_error(tmpProfilee))
  8062. {
  8063. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8064. {
  8065. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8066. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8067. }
  8068. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8069. {
  8070. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8071. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8072. }
  8073. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8074. {
  8075. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8076. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8077. }
  8078. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8079. {
  8080. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8081. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8082. }
  8083. }
  8084. json_object_put(tmpProfilee);
  8085. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8086. {
  8087. //------- not write to fptr2-------//
  8088. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8089. //clearflag = TRUE;
  8090. }
  8091. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8092. {
  8093. //------- not write to fptr2-------//
  8094. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8095. }
  8096. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8097. {
  8098. //------- not write to fptr2-------//
  8099. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8100. }
  8101. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8102. {
  8103. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8104. }
  8105. else
  8106. {
  8107. fprintf(fptr2, sLineWord);//writing data into file
  8108. }
  8109. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8110. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8111. if(clearflag == TRUE)
  8112. {
  8113. fclose(fptr1);
  8114. fclose(fptr2);
  8115. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8116. system(str);
  8117. // clear temp file
  8118. sprintf(str,"rm -f %s",temp);
  8119. system(str);
  8120. }
  8121. else
  8122. {
  8123. fclose(fptr1);
  8124. fclose(fptr2);
  8125. memset(str, 0, ARRAY_SIZE(str));
  8126. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8127. system(str);
  8128. resultRename = rename(temp, chargingProfiles[k]);
  8129. if(resultRename == 0)
  8130. {
  8131. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8132. }
  8133. else
  8134. {
  8135. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8136. }
  8137. if(comfirmstr[0]== 0)
  8138. {
  8139. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8140. }
  8141. //Check chargingProfile is empty file
  8142. /*------ Read the file ----------------*/
  8143. fptr1=fopen(chargingProfiles[k],"r");
  8144. ch=fgetc(fptr1);
  8145. rewind(fptr1);
  8146. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8147. if(ch!=EOF)
  8148. {
  8149. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8150. {
  8151. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8152. if(sLineWord[0]=='\0')
  8153. {
  8154. isEmptyFile = TRUE;
  8155. break;
  8156. }
  8157. else
  8158. {
  8159. isEmptyFile = FALSE;
  8160. break;
  8161. }
  8162. }
  8163. }
  8164. else
  8165. isEmptyFile = TRUE;
  8166. fclose(fptr1);
  8167. if(isEmptyFile == TRUE)
  8168. {
  8169. memset(str, 0, ARRAY_SIZE(str));
  8170. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8171. system(str);
  8172. }
  8173. }
  8174. }// End of while(int k=0; k < ChargePointCount; k++)
  8175. }
  8176. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8177. {
  8178. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8179. for(int k=0; k < ChargeProfileCount; k++)
  8180. {
  8181. fptr1 = fopen(chargingProfiles[k], "r");
  8182. fptr2 = fopen(temp, "w+");
  8183. //Check Charging Profile Count
  8184. while(fscanf(fptr1, "%s", word) != EOF)
  8185. {
  8186. //DEBUG_INFO("word=%s\n",word);
  8187. if(strstr(word, "chargingProfileId")!= NULL)
  8188. {
  8189. n_chargingProfile = n_chargingProfile + 1;
  8190. }
  8191. }
  8192. rewind(fptr1);
  8193. //search Charging Profile Element
  8194. //int i= 0;
  8195. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8196. {
  8197. json_object *tmpProfilee;
  8198. tmpProfilee = json_tokener_parse(sLineWord);
  8199. if(!is_error(tmpProfilee))
  8200. {
  8201. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8202. {
  8203. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8204. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8205. }
  8206. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8207. {
  8208. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8209. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8210. }
  8211. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8212. {
  8213. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8214. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8215. }
  8216. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8217. {
  8218. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8219. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8220. }
  8221. }
  8222. json_object_put(tmpProfilee);
  8223. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8224. {
  8225. //------- not write to fptr2-------//
  8226. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8227. //clearflag = TRUE;
  8228. }
  8229. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8230. {
  8231. //------- not write to fptr2-------//
  8232. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8233. }
  8234. else if(stackLevelIsNULL == TRUE)
  8235. {
  8236. //Clear Whole File
  8237. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8238. clearflag = TRUE;
  8239. break;
  8240. }
  8241. else
  8242. {
  8243. fprintf(fptr2, sLineWord);//writing data into file
  8244. }
  8245. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8246. }
  8247. if(clearflag == TRUE)
  8248. {
  8249. fclose(fptr1);
  8250. fclose(fptr2);
  8251. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8252. system(str);
  8253. // clear temp file
  8254. sprintf(str,"rm -f %s",temp);
  8255. system(str);
  8256. }
  8257. else
  8258. {
  8259. fclose(fptr1);
  8260. fclose(fptr2);
  8261. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8262. system(str);
  8263. resultRename = rename(temp, chargingProfiles[k]);
  8264. if(resultRename == 0)
  8265. {
  8266. DEBUG_INFO("File ChargingProfile renamed successfully");
  8267. }
  8268. else
  8269. {
  8270. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8271. }
  8272. if(comfirmstr[0]== 0)
  8273. {
  8274. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8275. }
  8276. //Check chargingProfile is empty file
  8277. /*------ Read the file ----------------*/
  8278. fptr1=fopen(chargingProfiles[k],"r");
  8279. ch=fgetc(fptr1);
  8280. rewind(fptr1);
  8281. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8282. if(ch!=EOF)
  8283. {
  8284. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8285. {
  8286. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8287. if(sLineWord[0]=='\0')
  8288. {
  8289. isEmptyFile = TRUE;
  8290. break;
  8291. }
  8292. else
  8293. {
  8294. isEmptyFile = FALSE;
  8295. break;
  8296. }
  8297. }
  8298. }
  8299. else
  8300. isEmptyFile = TRUE;
  8301. fclose(fptr1);
  8302. if(isEmptyFile == TRUE)
  8303. {
  8304. memset(str, 0, ARRAY_SIZE(str));
  8305. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8306. system(str);
  8307. }
  8308. /*------- End of reading ---------------*/
  8309. }
  8310. } // while(int k=0; k < ChargeProfileCount; k++)
  8311. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8312. end:
  8313. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8314. {
  8315. if(connectorIdInt == 0)
  8316. {
  8317. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8318. {
  8319. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8320. }
  8321. }
  8322. else
  8323. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8324. }
  8325. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8326. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8327. return result;
  8328. }
  8329. void createFirmwareVersionByDataTransfer(void)
  8330. {
  8331. json_object *FirmwareDataTransfer = json_object_new_object();
  8332. // AC & DC model
  8333. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8334. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8335. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8336. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8337. // DC model
  8338. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8339. {
  8340. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8341. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8342. (gunType[3] != GUN_TYPE_UNKNOWN))
  8343. {
  8344. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8345. }
  8346. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8347. {
  8348. // DS DM DW
  8349. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8350. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8351. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8352. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8353. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8354. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8355. }
  8356. else
  8357. {
  8358. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8359. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  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. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8363. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8364. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8365. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8366. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8367. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8368. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8369. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8370. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8371. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8372. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8373. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8374. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8375. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8376. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8377. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8378. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8379. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8380. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8381. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8382. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8383. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8384. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8385. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8386. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8387. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8388. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8389. }
  8390. }
  8391. // 4G model
  8392. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8393. {
  8394. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8395. }
  8396. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8397. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8398. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8399. json_object_put(FirmwareDataTransfer);
  8400. }
  8401. int handleDataTransferRequest(char *uuid, char *payload)
  8402. {
  8403. mtrace();
  8404. json_object *response = json_object_new_object();
  8405. int result = FAIL;
  8406. char tempvendorId[255]={0};
  8407. char tempmessageId[50]={0};
  8408. char tempdata[512]={0};
  8409. char message[2048]={0};
  8410. DEBUG_INFO("handleDataTransferRequest...\n");
  8411. if((uuid != NULL) && (payload != NULL))
  8412. {
  8413. json_object *DataTransfer;
  8414. DataTransfer = json_tokener_parse(payload);
  8415. if(!is_error(DataTransfer))
  8416. {
  8417. // Required data
  8418. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8419. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8420. // Optional data
  8421. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8422. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8423. if(json_object_object_get(DataTransfer, "data") != NULL)
  8424. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8425. result = PASS;
  8426. }
  8427. json_object_put(DataTransfer);
  8428. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8429. {
  8430. // Send all moudle firmware version on EVSE
  8431. createFirmwareVersionByDataTransfer();
  8432. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8433. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8434. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8435. json_object_put(response);
  8436. }
  8437. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8438. {
  8439. system("/usr/bin/run_tmate_restart.sh &");
  8440. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  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, "SetLEDBar") != NULL)
  8445. {
  8446. json_object *data;
  8447. data = json_tokener_parse(tempdata);
  8448. if(!is_error(data))
  8449. {
  8450. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8451. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8452. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8453. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8454. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8455. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8456. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8457. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8458. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8459. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8460. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8461. }
  8462. else
  8463. {
  8464. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8465. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8466. }
  8467. json_object_put(data);
  8468. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8469. json_object_put(response);
  8470. }
  8471. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8472. {
  8473. json_object *data;
  8474. data = json_tokener_parse(tempdata);
  8475. if(!is_error(data))
  8476. {
  8477. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8478. if(json_object_object_get(data, "idToken") != NULL)
  8479. {
  8480. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8481. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8482. }
  8483. if(json_object_object_get(data, "price") != NULL)
  8484. {
  8485. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8486. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8487. }
  8488. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8489. }
  8490. else
  8491. {
  8492. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8493. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8494. }
  8495. json_object_put(data);
  8496. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8497. json_object_put(response);
  8498. }
  8499. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8500. {
  8501. json_object *data;
  8502. data = json_tokener_parse(tempdata);
  8503. if(!is_error(data))
  8504. {
  8505. if(json_object_object_get(data, "txId") != NULL)
  8506. {
  8507. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8508. for(int idx = 0;idx<gunTotalNumber;idx++)
  8509. {
  8510. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8511. {
  8512. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8513. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8514. if(json_object_object_get(data, "description") != NULL)
  8515. {
  8516. // California pricing V1.0
  8517. DEBUG_INFO("California pricing V1.0\n");
  8518. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8519. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8520. }
  8521. else
  8522. {
  8523. // California pricing V1.1
  8524. DEBUG_INFO("California pricing V1.1\n");
  8525. if(json_object_object_get(data, "timestamp") != NULL)
  8526. {
  8527. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8528. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8529. }
  8530. if(json_object_object_get(data, "meterValue") != NULL)
  8531. {
  8532. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8533. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8534. }
  8535. if(json_object_object_get(data, "cost") != NULL)
  8536. {
  8537. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8538. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8539. }
  8540. if(json_object_object_get(data, "state") != NULL)
  8541. {
  8542. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8543. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8544. }
  8545. if(json_object_object_get(data, "chargingPrice") != NULL)
  8546. {
  8547. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8548. {
  8549. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8550. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8551. }
  8552. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8553. {
  8554. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8555. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8556. }
  8557. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8558. {
  8559. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8560. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8561. }
  8562. }
  8563. if(json_object_object_get(data, "idlePrice") != NULL)
  8564. {
  8565. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8566. {
  8567. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8568. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8569. }
  8570. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8571. {
  8572. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8573. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8574. }
  8575. }
  8576. if(json_object_object_get(data, "nextPeriod") != NULL)
  8577. {
  8578. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8579. {
  8580. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8581. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8582. }
  8583. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8584. {
  8585. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8586. {
  8587. 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")));
  8588. 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"));
  8589. }
  8590. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8591. {
  8592. 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")));
  8593. 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"));
  8594. }
  8595. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8596. {
  8597. 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")));
  8598. 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"));
  8599. }
  8600. }
  8601. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8602. {
  8603. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8604. {
  8605. 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")));
  8606. 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"));
  8607. }
  8608. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8609. {
  8610. 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")));
  8611. 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"));
  8612. }
  8613. }
  8614. }
  8615. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8616. {
  8617. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8618. {
  8619. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8620. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8621. }
  8622. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8623. {
  8624. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8625. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8626. }
  8627. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8628. {
  8629. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8630. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8631. }
  8632. }
  8633. }
  8634. }
  8635. }
  8636. }
  8637. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8638. }
  8639. else
  8640. {
  8641. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8642. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8643. }
  8644. json_object_put(data);
  8645. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8646. json_object_put(response);
  8647. }
  8648. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8649. {
  8650. json_object *data;
  8651. data = json_tokener_parse(tempdata);
  8652. if(!is_error(data))
  8653. {
  8654. if(json_object_object_get(data, "txId") != NULL)
  8655. {
  8656. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8657. for(int idx = 0;idx<gunTotalNumber;idx++)
  8658. {
  8659. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8660. {
  8661. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8662. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8663. if(json_object_object_get(data, "description") != NULL)
  8664. {
  8665. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8666. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8667. }
  8668. }
  8669. }
  8670. }
  8671. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8672. }
  8673. else
  8674. {
  8675. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8676. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8677. }
  8678. json_object_put(data);
  8679. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8680. json_object_put(response);
  8681. }
  8682. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8683. {
  8684. json_object *data;
  8685. data = json_tokener_parse(tempdata);
  8686. if(!is_error(data))
  8687. {
  8688. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8689. if(json_object_object_get(data, "Content_Type") != NULL)
  8690. {
  8691. 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))
  8692. {
  8693. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8694. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8695. {
  8696. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8697. }
  8698. }
  8699. else
  8700. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8701. }
  8702. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8703. }
  8704. else
  8705. {
  8706. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8707. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8708. }
  8709. json_object_put(data);
  8710. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8711. json_object_put(response);
  8712. }
  8713. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8714. {
  8715. json_object *data;
  8716. data = json_tokener_parse(tempdata);
  8717. if(!is_error(data))
  8718. {
  8719. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8720. if(json_object_object_get(data, "Page_Index") != NULL)
  8721. {
  8722. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8723. }
  8724. if(json_object_object_get(data, "Duration") != NULL)
  8725. {
  8726. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8727. }
  8728. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8729. }
  8730. else
  8731. {
  8732. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8733. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8734. }
  8735. json_object_put(data);
  8736. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8737. json_object_put(response);
  8738. }
  8739. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8740. {
  8741. json_object *data;
  8742. data = json_tokener_parse(tempdata);
  8743. if(!is_error(data))
  8744. {
  8745. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8746. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8747. {
  8748. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8749. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8750. else
  8751. {
  8752. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8753. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8754. }
  8755. }
  8756. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8757. {
  8758. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8759. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8760. else
  8761. {
  8762. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8763. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8764. }
  8765. }
  8766. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8767. {
  8768. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8769. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8770. else
  8771. {
  8772. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8773. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8774. }
  8775. }
  8776. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8777. {
  8778. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8779. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8780. else
  8781. {
  8782. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8783. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8784. }
  8785. }
  8786. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8787. {
  8788. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8789. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8790. else
  8791. {
  8792. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8793. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8794. }
  8795. }
  8796. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8797. {
  8798. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8799. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8800. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8801. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8802. else
  8803. {
  8804. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8805. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8806. }
  8807. }
  8808. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8809. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8810. }
  8811. else
  8812. {
  8813. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8814. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8815. }
  8816. json_object_put(data);
  8817. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8818. json_object_put(response);
  8819. }
  8820. else
  8821. {
  8822. // Can not find valid message id
  8823. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8824. }
  8825. }
  8826. else
  8827. {
  8828. // Payload is null
  8829. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8830. }
  8831. LWS_Send(message);
  8832. return result;
  8833. }
  8834. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8835. {
  8836. mtrace();
  8837. int result = FAIL;
  8838. int connectorIdInt, durationInt;
  8839. char chargingRateUnitStr[4]={0};
  8840. char comfirmstr[20];
  8841. int confirmPeriods = 0;
  8842. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8843. json_object *GetCompositeSchedule;
  8844. GetCompositeSchedule = json_tokener_parse(payload);
  8845. if(!is_error(GetCompositeSchedule))
  8846. {
  8847. // Required data
  8848. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8849. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8850. else
  8851. connectorIdInt = -1;
  8852. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8853. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8854. else
  8855. durationInt = 86400;
  8856. // Optional data
  8857. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8858. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8859. }
  8860. json_object_put(GetCompositeSchedule);
  8861. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8862. if((connectorIdInt == 0) ||
  8863. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8864. {
  8865. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8866. struct StructChargingProfile tmpProfile[1];
  8867. if(strstr(chargingRateUnitStr, "W") != NULL)
  8868. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8869. else
  8870. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8871. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8872. {
  8873. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8874. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8875. }
  8876. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8877. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8878. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8879. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8880. {
  8881. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8882. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8883. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8884. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8885. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8886. {
  8887. confirmPeriods = idx;
  8888. break;
  8889. }
  8890. }
  8891. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8892. {
  8893. confirmPeriods += 1;
  8894. }
  8895. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8896. }
  8897. else
  8898. {
  8899. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8900. }
  8901. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8902. return result;
  8903. }
  8904. int handleGetConfigurationRequest(char *uuid, char *payload)
  8905. {
  8906. mtrace();
  8907. int result = FAIL;
  8908. int MaxKeySupported = 0;
  8909. int n_keys = 0;
  8910. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8911. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8912. json_object *GetConfiguration;
  8913. GetConfiguration = json_tokener_parse(payload);
  8914. if(!is_error(GetConfiguration))
  8915. {
  8916. // Optional data
  8917. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8918. {
  8919. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8920. {
  8921. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8922. n_keys = idx + 1;
  8923. }
  8924. }
  8925. }
  8926. json_object_put(GetConfiguration);
  8927. UnknownKeynum = 0;
  8928. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8929. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8930. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8931. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8932. if(n_keys != 0)
  8933. {
  8934. for(int i=0;i<n_keys;i++)
  8935. {
  8936. getKeyValue(requestKey[i]);
  8937. }
  8938. }
  8939. else
  8940. {
  8941. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8942. getKeyValue("");
  8943. }
  8944. processUnkownKey();
  8945. sendGetConfigurationConfirmation(uuid);
  8946. return result;
  8947. }
  8948. static char fnamePlusPath[100]={0};
  8949. static char fnamePWithNoPath[60]={0};
  8950. void checkUploadLog(void)
  8951. {
  8952. FILE *fp;
  8953. /* Open the command for reading. */
  8954. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8955. if (fp == NULL) {
  8956. DEBUG_WARN("Failed to run command\n" );
  8957. exit(1);
  8958. }
  8959. int ftppathlen = 0;
  8960. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8961. int i = 0;
  8962. /* Read the output a line at a time - output it. */
  8963. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8964. if(i==0)
  8965. {
  8966. ftppathlen = strlen(fnamePlusPath);
  8967. DEBUG_INFO("%s\n", fnamePlusPath);
  8968. fnamePlusPath[ftppathlen]='\0';
  8969. break;
  8970. }
  8971. i= i+1;
  8972. }
  8973. /* close */
  8974. pclose(fp);
  8975. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8976. {
  8977. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8978. {
  8979. fnamePlusPath[k]='\0';
  8980. }
  8981. }
  8982. i=1;
  8983. //char fname[60]={0};
  8984. while(i < ftppathlen)
  8985. {
  8986. int len=ftppathlen-i;
  8987. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8988. {
  8989. DEBUG_INFO("compare '/' all right\n");
  8990. break;
  8991. }
  8992. i=i+1;
  8993. }
  8994. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8995. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8996. fnamePWithNoPath[i+1] = '\0';
  8997. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8998. {
  8999. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9000. {
  9001. fnamePWithNoPath[j]='\0';
  9002. }
  9003. }
  9004. FILE* fp1 = fopen(fnamePlusPath, "r");
  9005. if (fp1)
  9006. {
  9007. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9008. // file exists
  9009. fclose(fp1);
  9010. }
  9011. else
  9012. {
  9013. // file doesn't exist
  9014. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9015. }
  9016. }
  9017. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9018. {
  9019. mtrace();
  9020. int result = FAIL;
  9021. time_t CurrentTime;
  9022. struct tm *tm;
  9023. pthread_t th_Status;
  9024. CurrentTime = time(NULL);
  9025. tm = localtime(&CurrentTime);
  9026. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9027. 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);
  9028. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9029. if(!interLock.isGetDiagnosticGoing)
  9030. {
  9031. interLock.isGetDiagnosticGoing = 1;
  9032. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9033. }
  9034. else
  9035. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9036. return result;
  9037. }
  9038. void* GetDiagnosticsProcess(void* data)
  9039. {
  9040. pthread_detach(pthread_self());
  9041. mtrace();
  9042. int retriesInt=0, retryIntervalInt=0;
  9043. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9044. 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};
  9045. int port=0;
  9046. int isSuccess = FALSE;
  9047. char cmdBuf[2048];
  9048. struct tm *tmNow;
  9049. time_t CurrentTime;
  9050. struct tm tmStart;
  9051. struct tm tmStop;
  9052. CurrentTime = time(NULL);
  9053. tmNow=localtime(&CurrentTime);
  9054. uint16_t targetYear, targetMonth;
  9055. json_object *GetDiagnostics;
  9056. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9057. GetDiagnostics = json_tokener_parse(data);
  9058. if(!is_error(GetDiagnostics))
  9059. {
  9060. // Required data
  9061. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9062. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9063. // Optional data
  9064. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9065. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9066. else
  9067. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9068. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9069. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9070. else
  9071. retryIntervalInt = 30;
  9072. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9073. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9074. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9075. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9076. }
  9077. json_object_put(GetDiagnostics);
  9078. // Pack log to compress file
  9079. 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) &&
  9080. (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))
  9081. {
  9082. // Pack system log
  9083. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9084. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9085. targetYear = tmStart.tm_year;
  9086. targetMonth = tmStart.tm_mon;
  9087. do
  9088. {
  9089. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9090. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  9091. if(targetMonth+1>=13)
  9092. {
  9093. targetYear += 1;
  9094. targetMonth = 1;
  9095. }
  9096. else
  9097. {
  9098. targetMonth += 1;
  9099. }
  9100. }while((targetYear < (tmNow->tm_year+1900)) ||
  9101. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9102. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9103. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9104. system(cmdBuf);
  9105. // Pack charging & event log
  9106. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9107. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9108. targetYear = tmStart.tm_year;
  9109. targetMonth = tmStart.tm_mon;
  9110. do
  9111. {
  9112. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9113. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  9114. if(targetMonth+1>=13)
  9115. {
  9116. targetYear += 1;
  9117. targetMonth = 1;
  9118. }
  9119. else
  9120. {
  9121. targetMonth += 1;
  9122. }
  9123. }while((targetYear < (tmNow->tm_year+1900)) ||
  9124. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9125. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9126. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9127. system(cmdBuf);
  9128. // Combine log file
  9129. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9130. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9131. }
  9132. else
  9133. {
  9134. system("exec /root/logPackTools 'log' 6");
  9135. }
  9136. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9137. system(cmdBuf);
  9138. checkUploadLog();
  9139. //****************location*******************/
  9140. if(strcmp(locationstr,"")==0)
  9141. {
  9142. DEBUG_INFO("location is <Empty>!\n");
  9143. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9144. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9145. goto end;
  9146. }
  9147. memset(protocol, 0, ARRAY_SIZE(protocol));
  9148. memset(user, 0, ARRAY_SIZE(user) );
  9149. memset(password, 0, ARRAY_SIZE(password));
  9150. memset(host, 0, ARRAY_SIZE(host));
  9151. memset(path, 0, ARRAY_SIZE(path));
  9152. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9153. memset(host1, 0, ARRAY_SIZE(host1));
  9154. memset(path1, 0, ARRAY_SIZE(path1));
  9155. /*location: ftp://user:password@host:port/path*/
  9156. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9157. if((access(fnamePlusPath,F_OK))!=-1)
  9158. {
  9159. DEBUG_INFO("fnamePlusPath exist.\n");
  9160. }
  9161. else
  9162. {
  9163. DEBUG_INFO("fnamePlusPath not exist!\n");
  9164. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9165. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9166. goto end;
  9167. }
  9168. if(strchr(locationstr,'@')==NULL)
  9169. {
  9170. sscanf(locationstr,
  9171. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9172. protocol, host, &port, path);
  9173. strcpy(user,"anonymous");
  9174. strcpy(password,"");
  9175. }
  9176. else
  9177. {
  9178. //DEBUG_INFO("pch=%s\n", pch);
  9179. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9180. protocol, user, password, host, &port, path);
  9181. }
  9182. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9183. {
  9184. DEBUG_INFO("protocol is not ftp/http ! \n");
  9185. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9186. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9187. goto end;
  9188. }
  9189. if(strncmp(locationstr,"http", 4) == 0)
  9190. {
  9191. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9192. sprintf(ftppath,"/%s", path);
  9193. do
  9194. {
  9195. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9196. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9197. sleep(3);
  9198. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9199. if(!isSuccess)
  9200. {
  9201. DEBUG_INFO("Diagnostics fail.\n");
  9202. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9203. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9204. sleep(retryIntervalInt);
  9205. }
  9206. else
  9207. {
  9208. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9209. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9210. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9211. }
  9212. retriesInt--;
  9213. }while((isSuccess == 0)&&(retriesInt >= 0));
  9214. }
  9215. else
  9216. {
  9217. sscanf(host,"%[^/]%s",host1, path1);
  9218. if(strlen(path) > 0)
  9219. sprintf(ftppath,"/%s", path);
  9220. else
  9221. sprintf(ftppath,"/%s", path1);
  9222. int ftppathlen=strlen(ftppath);
  9223. int i=1;
  9224. char filenametemp[50];
  9225. while(i < ftppathlen)
  9226. {
  9227. int len=ftppathlen-i;
  9228. if(ftppath[len]== 47) // '/' ascll code: 47
  9229. {
  9230. DEBUG_INFO("find '/' all right\n");
  9231. break;
  9232. }
  9233. i=i+1;
  9234. }
  9235. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9236. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9237. filenametemp[i+1] = 0;
  9238. if(port == 0)
  9239. port = 21;
  9240. do
  9241. {
  9242. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9243. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9244. sleep(3);
  9245. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9246. if(!isSuccess)
  9247. {
  9248. DEBUG_INFO("Diagnostics fail.\n");
  9249. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9250. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9251. sleep(retryIntervalInt);
  9252. }
  9253. else
  9254. {
  9255. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9256. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9257. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9258. }
  9259. retriesInt--;
  9260. }while((!isSuccess)&&(retriesInt >= 0));
  9261. }
  9262. end:
  9263. system("rm -f /mnt/*");
  9264. sleep(5);
  9265. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9266. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9267. interLock.isGetDiagnosticGoing = 0;
  9268. pthread_exit(NULL);
  9269. }
  9270. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9271. {
  9272. mtrace();
  9273. int result = FAIL;
  9274. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9275. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9276. {
  9277. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9278. locallistVersion = -1;
  9279. }
  9280. else
  9281. {
  9282. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9283. OCPP_getListVerion();
  9284. }
  9285. //from db.OCPP_getListVerion
  9286. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9287. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9288. sendGetLocalListVersionConfirmation(uuid,"");
  9289. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9290. return result;
  9291. }
  9292. int handleRemoteStartRequest(char *uuid, char *payload)
  9293. {
  9294. mtrace();
  9295. int result = FAIL;
  9296. int connectorIdInt=-1;
  9297. int tempIndex = 0;
  9298. int connectorIdIsNULL, chargingProfileIsNULL;
  9299. char comfirmstr[20]={0};
  9300. char cmdBuf[512];
  9301. json_object *RemoteStartTransaction;
  9302. FILE *fp;
  9303. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9304. if(server_pending == TRUE)
  9305. {
  9306. return 0;
  9307. }
  9308. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9309. RemoteStartTransaction = json_tokener_parse(payload);
  9310. if(!is_error(RemoteStartTransaction))
  9311. {
  9312. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9313. {
  9314. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9315. }
  9316. else
  9317. {
  9318. connectorIdIsNULL = TRUE;
  9319. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9320. {
  9321. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9322. {
  9323. connectorIdIsNULL = FALSE;
  9324. connectorIdInt = (gun_index+1);
  9325. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9326. break;
  9327. }
  9328. }
  9329. }
  9330. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9331. {
  9332. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9333. // Required data
  9334. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9335. // Optional data
  9336. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9337. {
  9338. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9339. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9340. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9341. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9342. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9343. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9344. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9345. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9346. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9347. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9348. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9349. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9350. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9351. {
  9352. 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")));
  9353. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9354. 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"));
  9355. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9356. 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"));
  9357. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9358. 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")));
  9359. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9360. {
  9361. 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++)
  9362. {
  9363. 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"));
  9364. 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"));
  9365. 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)
  9366. 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"));
  9367. }
  9368. }
  9369. }
  9370. }
  9371. else
  9372. {
  9373. chargingProfileIsNULL = TRUE;
  9374. }
  9375. }
  9376. }
  9377. else
  9378. {
  9379. connectorIdIsNULL = TRUE;
  9380. }
  9381. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9382. {
  9383. DEBUG_WARN("Connector id is NULL\n.");
  9384. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9385. goto end;
  9386. }
  9387. /*
  9388. enum _SYSTEM_STATUS
  9389. {
  9390. S_BOOTING = 0,
  9391. S_IDLE, = 1
  9392. S_AUTHORIZING, = 2
  9393. S_REASSIGN_CHECK, = 3
  9394. S_REASSIGN, = 4
  9395. S_PRECHARGE, = 5
  9396. S_PREPARING_FOR_EV, = 6
  9397. S_PREPARING_FOR_EVSE, = 7
  9398. S_CHARGING, = 8
  9399. S_TERMINATING, = 9
  9400. S_COMPLETE, = 10
  9401. S_ALARM, = 11
  9402. S_FAULT = 12
  9403. }
  9404. */
  9405. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9406. {
  9407. //check Transaction active
  9408. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9409. {
  9410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9411. {
  9412. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9413. }
  9414. else
  9415. {
  9416. tempIndex = connectorIdInt -1;
  9417. }
  9418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9419. {
  9420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9421. {
  9422. 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))
  9423. {
  9424. //Reserved
  9425. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9426. }
  9427. 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))
  9428. {
  9429. //Reserved
  9430. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9431. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9432. goto end;
  9433. }
  9434. else
  9435. {
  9436. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9437. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9438. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9439. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9440. {
  9441. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9442. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9443. goto end;
  9444. }
  9445. }//END FOR ELSE
  9446. }
  9447. }// END FOR CHAdeMO_QUANTITY
  9448. }
  9449. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9450. {
  9451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9452. {
  9453. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9454. }
  9455. else
  9456. {
  9457. tempIndex = connectorIdInt -1;
  9458. }
  9459. for (int index = 0; index < CCS_QUANTITY; index++)
  9460. {
  9461. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9462. {
  9463. 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))
  9464. {
  9465. //Reserved
  9466. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9467. }
  9468. 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))
  9469. {
  9470. //Reserved
  9471. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9472. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9473. goto end;
  9474. }
  9475. else
  9476. {
  9477. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9478. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9479. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9480. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9481. {
  9482. DEBUG_WARN("CCS connector not allow start\n.");
  9483. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9484. goto end;
  9485. }
  9486. }// END FOR ELSE
  9487. }
  9488. }// END FOR CCS_QUANTITY
  9489. }
  9490. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9491. {
  9492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9493. {
  9494. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9495. }
  9496. else
  9497. {
  9498. tempIndex = connectorIdInt -1;
  9499. }
  9500. for (int index = 0; index < GB_QUANTITY; index++)
  9501. {
  9502. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9503. {
  9504. 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))
  9505. {
  9506. //Reserved
  9507. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9508. }
  9509. 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))
  9510. {
  9511. //Reserved
  9512. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9513. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9514. goto end;
  9515. }
  9516. else
  9517. {
  9518. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9519. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9520. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9521. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9522. {
  9523. DEBUG_WARN("GB connector not allow start\n.");
  9524. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9525. goto end;
  9526. }
  9527. }// END FOR ELSE
  9528. }
  9529. } // END FOR GB_QUANTITY
  9530. }
  9531. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9532. {
  9533. tempIndex = connectorIdInt -1;
  9534. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9535. {
  9536. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9537. {
  9538. 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))
  9539. {
  9540. //Reserved
  9541. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9542. }
  9543. 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))
  9544. {
  9545. //Reserved
  9546. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9547. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9548. goto end;
  9549. }
  9550. else
  9551. {
  9552. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9553. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9554. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9555. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9556. {
  9557. DEBUG_WARN("GB connector not allow start\n.");
  9558. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9559. goto end;
  9560. }
  9561. }// END FOR ELSE
  9562. }
  9563. } // END FOR GB_QUANTITY
  9564. }
  9565. else
  9566. {
  9567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9568. {
  9569. tempIndex = 2;
  9570. }
  9571. else
  9572. {
  9573. tempIndex = connectorIdInt -1;
  9574. }
  9575. for (int index = 0; index < AC_QUANTITY; index++)
  9576. {
  9577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9578. {
  9579. 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))
  9580. {
  9581. //Reserved
  9582. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9583. }
  9584. 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))
  9585. {
  9586. //Reserved
  9587. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9588. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9589. goto end;
  9590. }
  9591. else
  9592. {
  9593. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9594. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9595. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9596. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9597. {
  9598. DEBUG_WARN("AC connector not allow start\n.");
  9599. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9600. goto end;
  9601. }
  9602. }//END FOR ELSE
  9603. }
  9604. }// END FOR AC_QUANTITY
  9605. }
  9606. if(chargingProfileIsNULL == FALSE)
  9607. {
  9608. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9609. {
  9610. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9611. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9612. //memset idTag
  9613. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9614. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9615. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9616. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9617. // Save profile to file
  9618. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9619. system(cmdBuf);
  9620. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9621. fp = fopen(cmdBuf, "w");
  9622. 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));
  9623. fclose(fp);
  9624. }
  9625. else
  9626. {
  9627. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9628. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9629. }
  9630. }
  9631. else
  9632. {
  9633. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9634. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9635. //memset idTag
  9636. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9637. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9638. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9639. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9640. }
  9641. }
  9642. else
  9643. {
  9644. DEBUG_WARN("Connector id over\n.");
  9645. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9646. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9647. }
  9648. end:
  9649. json_object_put(RemoteStartTransaction);
  9650. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9651. {
  9652. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9653. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9654. }
  9655. //OCPP send RemoteStartConfirmation by first.
  9656. sendRemoteStartConfirmation(uuid, comfirmstr);
  9657. return result;
  9658. }
  9659. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9660. {
  9661. mtrace();
  9662. int result = FAIL;
  9663. int match = FALSE;
  9664. int GunNO = 0;
  9665. int tempIndex = 0;
  9666. int transactionIdInt=0;
  9667. int transactionIdIsNULL= TRUE;
  9668. char comfirmstr[20];
  9669. json_object *RemoteStopTransaction;
  9670. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9671. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9672. if(server_pending == TRUE)
  9673. {
  9674. return 0;
  9675. }
  9676. RemoteStopTransaction = json_tokener_parse(payload);
  9677. if(!is_error(RemoteStopTransaction))
  9678. {
  9679. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9680. {
  9681. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9682. transactionIdIsNULL = FALSE;
  9683. }
  9684. }
  9685. json_object_put(RemoteStopTransaction);
  9686. if(transactionIdIsNULL == FALSE)
  9687. {
  9688. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9689. {
  9690. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9691. {
  9692. //check Transaction active
  9693. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9694. {
  9695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9696. {
  9697. tempIndex = ((gun_index==2) ? 1: 0);
  9698. }
  9699. else
  9700. {
  9701. tempIndex = gun_index;
  9702. }
  9703. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9704. {
  9705. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9706. {
  9707. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9708. {
  9709. match = TRUE;
  9710. GunNO = gun_index;
  9711. }
  9712. }
  9713. }// END FOR CHAdeMO_QUANTITY
  9714. }
  9715. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9716. {
  9717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9718. {
  9719. tempIndex = ((gun_index==2) ? 1: 0);
  9720. }
  9721. else
  9722. {
  9723. tempIndex = gun_index;
  9724. }
  9725. for (int index = 0; index < CCS_QUANTITY; index++)
  9726. {
  9727. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9728. {
  9729. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9730. {
  9731. match = TRUE;
  9732. GunNO = gun_index;
  9733. }
  9734. }
  9735. }// END FOR CCS_QUANTITY
  9736. }
  9737. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9738. {
  9739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9740. {
  9741. tempIndex = ((gun_index==2) ? 1: 0);
  9742. }
  9743. else
  9744. {
  9745. tempIndex = gun_index;
  9746. }
  9747. for (int index = 0; index < GB_QUANTITY; index++)
  9748. {
  9749. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9750. {
  9751. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9752. {
  9753. match = TRUE;
  9754. GunNO = gun_index;
  9755. }
  9756. }
  9757. }// END FOR GB_QUANTITY
  9758. }
  9759. else if(gunType[gun_index] == GUN_TYPE_DO)
  9760. {
  9761. tempIndex = gun_index;
  9762. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9763. {
  9764. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9765. {
  9766. 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
  9767. {
  9768. match = TRUE;
  9769. GunNO = gun_index;
  9770. }
  9771. }
  9772. }// END FOR GB_QUANTITY
  9773. }
  9774. else
  9775. {
  9776. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9777. {
  9778. tempIndex = 2;
  9779. }
  9780. else
  9781. {
  9782. tempIndex = gun_index;
  9783. }
  9784. for (int index = 0; index < AC_QUANTITY; index++)
  9785. {
  9786. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9787. {
  9788. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9789. {
  9790. match = TRUE;
  9791. GunNO = gun_index;
  9792. }
  9793. }
  9794. }// END FOR CHAdeMO_QUANTITY
  9795. } // END FOR AC ELSE
  9796. }// CHECK IF ResponseTransactionId == transactionIdInt
  9797. }//END FOR
  9798. if( match == TRUE)
  9799. {
  9800. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9801. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9802. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9803. }
  9804. else
  9805. {
  9806. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9807. }
  9808. }
  9809. else
  9810. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9811. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9812. return result;
  9813. }
  9814. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9815. {
  9816. mtrace();
  9817. int result = FAIL;
  9818. int connectorIdInt=0, reservationIdInt=0;
  9819. int tempIndex = 0;
  9820. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9821. char comfirmstr[20]={0};
  9822. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9823. int c = 0;
  9824. char *loc;
  9825. //char *ptr;
  9826. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9827. strcpy(sstrtemp, stringtrimspace(payload));
  9828. //***(1)connectorId ****/
  9829. c=0;
  9830. loc = strstr(sstrtemp, "connectorId");
  9831. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9832. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9833. {
  9834. sstr[c] = loc[strlen("connectorId")+2+c];
  9835. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9836. c++;
  9837. }
  9838. sstr[c] = '\0';
  9839. connectorIdInt = atoi(sstr);
  9840. //***(2)expiryDate ****/
  9841. loc = strstr(sstrtemp, "expiryDate");
  9842. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9843. c = 0;
  9844. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9845. {
  9846. sstr[c] = loc[3+strlen("expiryDate")+c];
  9847. c++;
  9848. }
  9849. sstr[c] = '\0';
  9850. strcpy(expiryDatestr, sstr);
  9851. //***(3)idTag ****/
  9852. loc = strstr(sstrtemp, "idTag");
  9853. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9854. c = 0;
  9855. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9856. {
  9857. sstr[c] = loc[3+strlen("idTag")+c];
  9858. c++;
  9859. }
  9860. sstr[c] = '\0';
  9861. strcpy(idTagstr, sstr);
  9862. //***(4)parentIdTag ****/
  9863. loc = strstr(sstrtemp, "parentIdTag");
  9864. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9865. c = 0;
  9866. if(loc == NULL)
  9867. {
  9868. strcpy(parentIdTagstr, "");
  9869. }
  9870. else
  9871. {
  9872. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9873. {
  9874. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9875. c++;
  9876. }
  9877. sstr[c] = '\0';
  9878. strcpy(parentIdTagstr, sstr);
  9879. }
  9880. //***(5)reservationId ****/
  9881. c=0;
  9882. loc = strstr(sstrtemp, "reservationId");
  9883. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9884. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9885. {
  9886. sstr[c] = loc[strlen("reservationId")+2+c];
  9887. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9888. c++;
  9889. }
  9890. sstr[c] = '\0';
  9891. reservationIdInt = atoi(sstr);
  9892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9893. /*
  9894. enum SYSTEM_STATUS
  9895. {
  9896. SYS_MODE_BOOTING = 0,
  9897. SYS_MODE_IDLE = 1,
  9898. SYS_MODE_AUTHORIZING = 2,
  9899. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9900. SYS_MODE_REASSIGN = 4,
  9901. SYS_MODE_PREPARING = 5,
  9902. SYS_MODE_PREPARE_FOR_EV = 6,
  9903. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9904. SYS_MODE_CHARGING = 8,
  9905. SYS_MODE_TERMINATING = 9,
  9906. SYS_MODE_COMPLETE = 10,
  9907. SYS_MODE_ALARM = 11,
  9908. SYS_MODE_FAULT = 12,
  9909. SYS_MODE_RESERVATION = 13,
  9910. SYS_MODE_BOOKING = 14,
  9911. SYS_MODE_MAINTAIN = 15,
  9912. SYS_MODE_DEBUG = 16,
  9913. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9914. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9915. SYS_MODE_UPDATE = 19
  9916. };
  9917. */
  9918. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9919. {
  9920. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9921. goto end;
  9922. }
  9923. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9924. {
  9925. //check Transaction active
  9926. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9927. {
  9928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9929. {
  9930. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9931. }
  9932. else
  9933. {
  9934. tempIndex = connectorIdInt -1;
  9935. }
  9936. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9937. {
  9938. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9939. {
  9940. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9941. {
  9942. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9943. {
  9944. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9945. {
  9946. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9948. }
  9949. 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'))
  9950. {
  9951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9952. }
  9953. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9954. {
  9955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9956. }
  9957. else
  9958. {
  9959. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9960. }
  9961. }
  9962. 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
  9963. {
  9964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9965. }
  9966. }
  9967. else
  9968. {
  9969. //replace reservation
  9970. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9972. }
  9973. }
  9974. } // END FOR CHAdeMO_QUANTITY
  9975. }
  9976. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9977. {
  9978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9979. {
  9980. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9981. }
  9982. else
  9983. {
  9984. tempIndex = connectorIdInt -1;
  9985. }
  9986. for (int index = 0; index < CCS_QUANTITY; index++)
  9987. {
  9988. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9989. {
  9990. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9991. {
  9992. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9993. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9994. {
  9995. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9996. {
  9997. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9999. }
  10000. 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'))
  10001. {
  10002. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10003. }
  10004. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10005. {
  10006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10007. }
  10008. else
  10009. {
  10010. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10011. }
  10012. }
  10013. 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
  10014. {
  10015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10016. }
  10017. }
  10018. else
  10019. {
  10020. //replace reservation
  10021. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10023. }
  10024. }
  10025. } // END FOR CCS_QUANTITY
  10026. }
  10027. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10028. {
  10029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10030. {
  10031. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10032. }
  10033. else
  10034. {
  10035. tempIndex = connectorIdInt -1;
  10036. }
  10037. for (int index = 0; index < GB_QUANTITY; index++)
  10038. {
  10039. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10040. {
  10041. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10042. {
  10043. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10044. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10045. {
  10046. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10047. {
  10048. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10049. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10050. }
  10051. 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'))
  10052. {
  10053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10054. }
  10055. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10056. {
  10057. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10058. }
  10059. else
  10060. {
  10061. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10062. }
  10063. }
  10064. 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
  10065. {
  10066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10067. }
  10068. }
  10069. else
  10070. {
  10071. //replace reservation
  10072. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10074. }
  10075. }
  10076. }// END FOR GB_QUANTITY
  10077. }
  10078. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10079. {
  10080. tempIndex = connectorIdInt -1;
  10081. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10082. {
  10083. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10084. {
  10085. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10086. {
  10087. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10088. 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
  10089. {
  10090. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10091. {
  10092. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10093. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10094. }
  10095. 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'))
  10096. {
  10097. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10098. }
  10099. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10100. {
  10101. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10102. }
  10103. else
  10104. {
  10105. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10106. }
  10107. }
  10108. 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
  10109. {
  10110. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10111. }
  10112. }
  10113. else
  10114. {
  10115. //replace reservation
  10116. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10118. }
  10119. }
  10120. }// END FOR GB_QUANTITY
  10121. }
  10122. else
  10123. {
  10124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10125. {
  10126. tempIndex = 2;
  10127. }
  10128. else
  10129. {
  10130. tempIndex = (connectorIdInt -1);
  10131. }
  10132. for (int index = 0; index < AC_QUANTITY; index++)
  10133. {
  10134. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10135. {
  10136. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10137. {
  10138. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10139. {
  10140. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10141. {
  10142. 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))
  10143. {
  10144. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10145. }
  10146. else
  10147. {
  10148. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10150. }
  10151. }
  10152. 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'))
  10153. {
  10154. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10155. }
  10156. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10157. {
  10158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10159. }
  10160. else
  10161. {
  10162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10163. }
  10164. }
  10165. 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
  10166. {
  10167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10168. }
  10169. }
  10170. else
  10171. {
  10172. //replace reservation
  10173. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10174. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10175. }
  10176. }
  10177. } // END FOR AC_QUANTITY
  10178. }
  10179. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10180. }
  10181. else if(connectorIdInt == 0)
  10182. {
  10183. //check Transaction active
  10184. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10185. {
  10186. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10187. {
  10188. 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'))
  10189. {
  10190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10191. goto end;
  10192. }
  10193. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10194. {
  10195. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10196. goto end;
  10197. }
  10198. 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
  10199. {
  10200. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10201. goto end;
  10202. }
  10203. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10204. {
  10205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10206. goto end;
  10207. }
  10208. }
  10209. }// END FOR CHAdeMO_QUANTITY
  10210. for (int index = 0; index < CCS_QUANTITY; index++)
  10211. {
  10212. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10213. {
  10214. 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'))
  10215. {
  10216. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10217. goto end;
  10218. }
  10219. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10220. {
  10221. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10222. goto end;
  10223. }
  10224. 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
  10225. {
  10226. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10227. goto end;
  10228. }
  10229. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10230. {
  10231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10232. goto end;
  10233. }
  10234. }
  10235. } // END FOR CCS_QUANTITY
  10236. for (int index = 0; index < GB_QUANTITY; index++)
  10237. {
  10238. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10239. {
  10240. 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'))
  10241. {
  10242. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10243. goto end;
  10244. }
  10245. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10246. {
  10247. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10248. goto end;
  10249. }
  10250. 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
  10251. {
  10252. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10253. goto end;
  10254. }
  10255. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10256. {
  10257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10258. goto end;
  10259. }
  10260. }
  10261. } // END FOR GB_QUANTITY
  10262. for (int index = 0; index < AC_QUANTITY; index++)
  10263. {
  10264. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10265. {
  10266. 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'))
  10267. {
  10268. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10269. goto end;
  10270. }
  10271. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10272. {
  10273. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10274. goto end;
  10275. }
  10276. 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
  10277. {
  10278. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10279. goto end;
  10280. }
  10281. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10282. {
  10283. 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))
  10284. {
  10285. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10286. goto end;
  10287. }
  10288. }
  10289. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10290. {
  10291. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10292. goto end;
  10293. }
  10294. }
  10295. }// END FOR AC_QUANTITY
  10296. //The connectorId is 0
  10297. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10299. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10300. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10301. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10302. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10303. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10304. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10305. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10306. result = TRUE;
  10307. return result;
  10308. }
  10309. else
  10310. {
  10311. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10312. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10313. }
  10314. if(strcmp(comfirmstr,"Accepted") == 0)
  10315. {
  10316. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10317. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10318. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10319. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10320. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10321. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10322. result = TRUE;
  10323. return result;
  10324. }
  10325. end:
  10326. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10327. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10328. return result;
  10329. }
  10330. int handleResetRequest(char *uuid, char *payload)
  10331. {
  10332. mtrace();
  10333. int result = FAIL;
  10334. char sstr[10]={0},sstrtemp[30]={ 0 };
  10335. char typestr[10]={0};
  10336. char comfirmstr[20]={0};
  10337. int c = 0;
  10338. char *loc;
  10339. DEBUG_INFO("handleResetRequest...\n");
  10340. strcpy(sstrtemp, stringtrimspace(payload));
  10341. loc = strstr(sstrtemp, "type");
  10342. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10343. c = 0;
  10344. while (loc[3+strlen("type")+c] != '\"')
  10345. {
  10346. sstr[c] = loc[3+strlen("type")+c];
  10347. c++;
  10348. }
  10349. sstr[c] = '\0';
  10350. strcpy(typestr,sstr);
  10351. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10352. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10353. {
  10354. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10355. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10356. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10357. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10358. }
  10359. else
  10360. {
  10361. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10362. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10363. result = PASS;
  10364. }
  10365. sendResetConfirmation(uuid, comfirmstr);
  10366. return result;
  10367. }
  10368. int handleSendLocalListRequest(char *uuid, char *payload)
  10369. {
  10370. mtrace();
  10371. int result = FAIL;
  10372. char comfirmstr[20];
  10373. int checkState_Faulted = FALSE;
  10374. json_object *SendLocalList;
  10375. DEBUG_INFO("handleSendLocalListRequest...\n");
  10376. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10377. {
  10378. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10379. goto end;
  10380. }
  10381. //check Charge Point state
  10382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10383. {
  10384. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10385. {
  10386. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10387. }
  10388. }
  10389. for (int index = 0; index < CCS_QUANTITY; index++)
  10390. {
  10391. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10392. {
  10393. checkState_Faulted = TRUE; //OCPP Status
  10394. }
  10395. }
  10396. for (int index = 0; index < GB_QUANTITY; index++)
  10397. {
  10398. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10399. {
  10400. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10401. }
  10402. }
  10403. //check Charge Point state
  10404. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10405. {
  10406. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10407. {
  10408. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10409. }
  10410. }
  10411. //check Charge Point state
  10412. for (int index = 0; index < AC_QUANTITY; index++)
  10413. {
  10414. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10415. {
  10416. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10417. }
  10418. }
  10419. if(checkState_Faulted == TRUE)
  10420. {
  10421. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10422. goto end;
  10423. }
  10424. // Parsing payload
  10425. SendLocalList = json_tokener_parse(payload);
  10426. if(!is_error(SendLocalList))
  10427. {
  10428. // Required data
  10429. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10430. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10431. // Optional data
  10432. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10433. {
  10434. //Check UpdateType
  10435. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10436. {
  10437. //Local list full update
  10438. DEBUG_INFO("Local list full update.\n");
  10439. OCPP_getListVerion();
  10440. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10441. {
  10442. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10443. goto end;
  10444. }
  10445. OCPP_cleanLocalList();
  10446. }
  10447. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10448. {
  10449. //Local list different update
  10450. DEBUG_INFO("Local list different update.\n");
  10451. OCPP_getListVerion();
  10452. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10453. {
  10454. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10455. goto end;
  10456. }
  10457. }
  10458. else
  10459. {
  10460. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10461. goto end;
  10462. }
  10463. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10464. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10465. {
  10466. 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")));
  10467. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10468. {
  10469. 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")));
  10470. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10471. 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")));
  10472. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10473. 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")));
  10474. }
  10475. // Add to db
  10476. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10477. {
  10478. //Local list full update
  10479. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10480. idx,
  10481. ShmOCPP16Data->SendLocalList.ListVersion,
  10482. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10483. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10484. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10485. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10486. // update list
  10487. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10488. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10489. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10490. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10491. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10492. }
  10493. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10494. {
  10495. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10496. idx,
  10497. ShmOCPP16Data->SendLocalList.ListVersion,
  10498. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10499. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10500. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10501. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10502. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10503. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10504. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10505. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10506. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10507. }
  10508. }
  10509. }
  10510. else
  10511. {
  10512. //Check UpdateType
  10513. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10514. {
  10515. //Local list full update
  10516. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10517. OCPP_cleanLocalList();
  10518. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10519. goto end;
  10520. }
  10521. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10522. {
  10523. //Local list different update
  10524. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10525. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10526. goto end;
  10527. }
  10528. }
  10529. result = PASS;
  10530. }
  10531. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10532. end:
  10533. json_object_put(SendLocalList);
  10534. sendSendLocalListConfirmation(uuid, comfirmstr);
  10535. return result;
  10536. }
  10537. #define MAX 200
  10538. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10539. {
  10540. mtrace();
  10541. int result = FAIL;
  10542. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10543. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10544. char chargingProfilePurposeStr[30]={0};
  10545. char chargingProfileKindStr[16]={0};
  10546. char recurrencyKindStr[10]={0};
  10547. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10548. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10549. int chargingSchedulePeriodCount = 0;
  10550. char comfirmstr[20]={0};
  10551. int meet= FALSE;
  10552. FILE *fptr1;
  10553. char filename[MAX]={0};
  10554. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10555. char rmFileCmd[50]={0};
  10556. char tempchargingProfilePurposeStr[30]={0};
  10557. char word[1600]={0};
  10558. int n_chargingProfile = 0;
  10559. json_object *SetChargingProfile;
  10560. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10561. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10562. SetChargingProfile = json_tokener_parse(payload);
  10563. if(!is_error(SetChargingProfile))
  10564. {
  10565. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10566. {
  10567. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10568. if(connectorIdInt == 0)
  10569. {
  10570. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10571. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10572. }
  10573. else
  10574. {
  10575. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10576. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10577. }
  10578. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10579. }
  10580. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10581. {
  10582. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10583. {
  10584. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10585. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10586. {
  10587. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10588. }
  10589. else
  10590. {
  10591. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10592. }
  10593. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10594. }
  10595. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10596. {
  10597. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10598. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10599. {
  10600. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10601. }
  10602. else
  10603. {
  10604. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10605. }
  10606. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10607. }
  10608. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10609. {
  10610. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10611. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10612. {
  10613. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10614. }
  10615. else
  10616. {
  10617. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10618. }
  10619. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10620. }
  10621. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10622. {
  10623. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10624. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10625. {
  10626. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10627. }
  10628. else
  10629. {
  10630. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10631. }
  10632. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10633. }
  10634. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10635. {
  10636. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10637. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10638. {
  10639. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10640. }
  10641. else
  10642. {
  10643. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10644. }
  10645. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10646. }
  10647. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10648. {
  10649. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10650. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10651. {
  10652. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10653. }
  10654. else
  10655. {
  10656. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10657. }
  10658. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10659. }
  10660. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10661. {
  10662. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10663. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10664. {
  10665. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10666. }
  10667. else
  10668. {
  10669. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10670. }
  10671. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10672. }
  10673. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10674. {
  10675. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10676. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10677. {
  10678. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10679. }
  10680. else
  10681. {
  10682. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10683. }
  10684. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10685. }
  10686. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10687. {
  10688. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10689. {
  10690. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10691. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10692. {
  10693. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10694. }
  10695. else
  10696. {
  10697. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10698. }
  10699. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10700. }
  10701. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10702. {
  10703. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10704. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10705. {
  10706. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10707. }
  10708. else
  10709. {
  10710. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10711. }
  10712. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10713. }
  10714. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10715. {
  10716. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10717. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10718. {
  10719. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10720. }
  10721. else
  10722. {
  10723. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10724. }
  10725. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10726. }
  10727. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10728. {
  10729. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10730. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10731. {
  10732. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10733. }
  10734. else
  10735. {
  10736. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10737. }
  10738. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10739. }
  10740. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10741. {
  10742. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10743. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10744. if(chargingSchedulePeriodCount <= 10)
  10745. {
  10746. 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++)
  10747. {
  10748. 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)
  10749. {
  10750. 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"));
  10751. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10752. {
  10753. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10754. }
  10755. else
  10756. {
  10757. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10758. }
  10759. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10760. }
  10761. 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)
  10762. {
  10763. 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"));
  10764. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10765. {
  10766. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10767. }
  10768. else
  10769. {
  10770. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10771. }
  10772. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10773. }
  10774. 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)
  10775. {
  10776. 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"));
  10777. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10778. {
  10779. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10780. }
  10781. else
  10782. {
  10783. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10784. }
  10785. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10786. }
  10787. }
  10788. }
  10789. }
  10790. }
  10791. }
  10792. }
  10793. json_object_put(SetChargingProfile);
  10794. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10795. {
  10796. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10797. goto end;
  10798. }
  10799. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10800. {
  10801. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10802. if(connectorIdInt != 0)
  10803. {
  10804. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10805. goto end;
  10806. }
  10807. strcpy(filename, ChargePointMaxProfile_JSON );
  10808. fptr1 = fopen(filename, "r");
  10809. if (!fptr1)
  10810. {
  10811. //file not exist
  10812. DEBUG_INFO("Unable to open the input file!!\n");
  10813. fptr1 = fopen(filename, "w+");
  10814. }
  10815. else
  10816. {
  10817. //Check Charging Profile Count
  10818. while(fscanf(fptr1, "%s", word) != EOF)
  10819. {
  10820. //DEBUG_INFO("word=%s\n",word);
  10821. if(strstr(word, "chargingProfileId")!= NULL)
  10822. {
  10823. //DEBUG_INFO("test chargingProfileId \n");
  10824. n_chargingProfile = n_chargingProfile + 1;
  10825. //DEBUG_INFO("chargingProfileId Found\n");
  10826. }
  10827. }
  10828. }
  10829. fclose(fptr1);
  10830. }
  10831. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10832. {
  10833. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10834. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10835. {
  10836. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10837. goto end;
  10838. }
  10839. memset(filename, 0, ARRAY_SIZE(filename));
  10840. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10841. fptr1 = fopen(filename, "r");
  10842. if (!fptr1)
  10843. {
  10844. //file not exist
  10845. //DEBUG_INFO("Unable to open the input file!!\n");
  10846. fptr1 = fopen(filename, "w+");
  10847. }
  10848. else
  10849. {
  10850. //Check Charging Profile Count
  10851. while(fscanf(fptr1, "%s", word) != EOF)
  10852. {
  10853. //DEBUG_INFO("word=%s\n",word);
  10854. if(strstr(word, "chargingProfileId")!= NULL)
  10855. {
  10856. //DEBUG_INFO("test chargingProfileId \n");
  10857. n_chargingProfile = n_chargingProfile + 1;
  10858. //DEBUG_INFO("chargingProfileId Found\n");
  10859. }
  10860. }
  10861. }
  10862. fclose(fptr1);
  10863. }
  10864. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10865. {
  10866. //printf("set chargingProfile 1-4\n");
  10867. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10868. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10869. if(connectorIdInt == 0)
  10870. {
  10871. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10872. goto end;
  10873. }
  10874. int tempIndex = 0;
  10875. //check Transaction active
  10876. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10877. {
  10878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10879. {
  10880. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10881. }
  10882. else
  10883. {
  10884. tempIndex = connectorIdInt -1;
  10885. }
  10886. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10887. {
  10888. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10889. {
  10890. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10891. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10892. {
  10893. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10894. {
  10895. meet = TRUE;
  10896. break;
  10897. }
  10898. }
  10899. }
  10900. }
  10901. }
  10902. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10903. {
  10904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10905. {
  10906. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10907. }
  10908. else
  10909. {
  10910. tempIndex = connectorIdInt -1;
  10911. }
  10912. for (int index = 0; index < CCS_QUANTITY; index++)
  10913. {
  10914. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10915. {
  10916. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10917. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10918. {
  10919. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10920. {
  10921. meet = TRUE;
  10922. break;
  10923. }
  10924. }
  10925. }
  10926. }
  10927. }
  10928. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10929. {
  10930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10931. {
  10932. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10933. }
  10934. else
  10935. {
  10936. tempIndex = connectorIdInt -1;
  10937. }
  10938. for (int index = 0; index < GB_QUANTITY; index++)
  10939. {
  10940. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10941. {
  10942. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10943. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10944. {
  10945. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10946. {
  10947. meet = TRUE;
  10948. break;
  10949. }
  10950. }
  10951. }
  10952. }
  10953. }
  10954. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10955. {
  10956. tempIndex = connectorIdInt -1;
  10957. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10958. {
  10959. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10960. {
  10961. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10962. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10963. {
  10964. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10965. {
  10966. meet = TRUE;
  10967. break;
  10968. }
  10969. }
  10970. }
  10971. }
  10972. }
  10973. else
  10974. {
  10975. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10976. {
  10977. tempIndex = 2;
  10978. }
  10979. else
  10980. {
  10981. tempIndex = (connectorIdInt -1);
  10982. }
  10983. for (int index = 0; index < AC_QUANTITY; index++)
  10984. {
  10985. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10986. {
  10987. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10988. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10989. {
  10990. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10991. {
  10992. meet = TRUE;
  10993. break;
  10994. }
  10995. }
  10996. }
  10997. }
  10998. }
  10999. //check Transaction active
  11000. if(meet == FALSE)
  11001. {
  11002. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11003. goto end;
  11004. }
  11005. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  11006. {
  11007. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11008. goto end;
  11009. }
  11010. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11011. fptr1 = fopen(filename, "r");
  11012. if (!fptr1)
  11013. {
  11014. //file not exist
  11015. DEBUG_INFO("Unable to open the input file!!\n");
  11016. fptr1 = fopen(filename, "w+");
  11017. }
  11018. else
  11019. {
  11020. //Check Charging Profile Count
  11021. while(fscanf(fptr1, "%s", word) != EOF)
  11022. {
  11023. //DEBUG_INFO("word=%s\n",word);
  11024. if(strstr(word, "chargingProfileId")!= NULL)
  11025. {
  11026. //DEBUG_INFO("test chargingProfileId \n");
  11027. n_chargingProfile = n_chargingProfile + 1;
  11028. //DEBUG_INFO("chargingProfileId Found\n");
  11029. }
  11030. }
  11031. }
  11032. fclose(fptr1);
  11033. }
  11034. // Check ChargeProfileMaxStackLevel
  11035. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11036. {
  11037. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11038. goto end;
  11039. }
  11040. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11041. {
  11042. int i = 0;
  11043. char fnametemp[200]={0};
  11044. n_chargingProfile = 0;
  11045. //Check ChargePointMaxProfile.json exit
  11046. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11047. {
  11048. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11049. //Check Charging Profile Count
  11050. while(fscanf(fptr1, "%s", word) != EOF)
  11051. {
  11052. //DEBUG_INFO("word=%s\n",word);
  11053. if(strstr(word, "chargingProfileId")!= NULL)
  11054. {
  11055. //DEBUG_INFO("test chargingProfileId \n");
  11056. n_chargingProfile = n_chargingProfile + 1;
  11057. i = i + 1;
  11058. //DEBUG_INFO("chargingProfileId Found\n");
  11059. }
  11060. memset(word, 0, ARRAY_SIZE(word));
  11061. }
  11062. fclose(fptr1);
  11063. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  11064. }
  11065. //Check TxDefaultProfile_0.json exit
  11066. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  11067. {
  11068. i = 0;
  11069. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  11070. //Check Charging Profile Count
  11071. while(fscanf(fptr1, "%s", word) != EOF)
  11072. {
  11073. //DEBUG_INFO("word=%s\n",word);
  11074. if(strstr(word, "chargingProfileId")!= NULL)
  11075. {
  11076. //DEBUG_INFO("test chargingProfileId \n");
  11077. n_chargingProfile = n_chargingProfile + 1;
  11078. i = i + 1;
  11079. //DEBUG_INFO("chargingProfileId Found\n");
  11080. }
  11081. memset(word, 0, ARRAY_SIZE(word));
  11082. }
  11083. fclose(fptr1);
  11084. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  11085. }
  11086. //Check TxDefaultProfile_%d.json
  11087. for(int j=1; j <= gunTotalNumber; j++)
  11088. {
  11089. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11090. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  11091. if((access(fnametemp,F_OK))!=-1)
  11092. {
  11093. i = 0;
  11094. fptr1 = fopen(fnametemp, "r");
  11095. //Check Charging Profile Count
  11096. while(fscanf(fptr1, "%s", word) != EOF)
  11097. {
  11098. //DEBUG_INFO("word=%s\n",word);
  11099. if(strstr(word, "chargingProfileId")!= NULL)
  11100. {
  11101. //DEBUG_INFO("test chargingProfileId \n");
  11102. n_chargingProfile = n_chargingProfile + 1;
  11103. i = i + 1;
  11104. //DEBUG_INFO("chargingProfileId Found\n");
  11105. }
  11106. memset(word, 0, ARRAY_SIZE(word));
  11107. }
  11108. fclose(fptr1);
  11109. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11110. }
  11111. }
  11112. //Check TxProfile_%d.json
  11113. for(int j=1; j <= gunTotalNumber; j++)
  11114. {
  11115. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11116. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  11117. if((access(fnametemp,F_OK))!=-1)
  11118. {
  11119. i = 0;
  11120. fptr1 = fopen(fnametemp, "r");
  11121. //Check Charging Profile Count
  11122. while(fscanf(fptr1, "%s", word) != EOF)
  11123. {
  11124. //DEBUG_INFO("word=%s\n",word);
  11125. if(strstr(word, "chargingProfileId")!= NULL)
  11126. {
  11127. //DEBUG_INFO("test chargingProfileId \n");
  11128. n_chargingProfile = n_chargingProfile + 1;
  11129. i = i + 1;
  11130. //DEBUG_INFO("chargingProfileId Found\n");
  11131. }
  11132. memset(word, 0, ARRAY_SIZE(word));
  11133. }
  11134. fclose(fptr1);
  11135. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11136. }
  11137. }
  11138. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11139. {
  11140. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11141. goto end;
  11142. }
  11143. }
  11144. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11145. //**********************************Write to File********************************************************/
  11146. FILE *infile;
  11147. FILE *outfile;
  11148. infile = fopen (filename, "r");
  11149. outfile = fopen (tempfile, "w");
  11150. int d =0;
  11151. d = fgetc(infile);
  11152. rewind(infile);
  11153. if(d == EOF)
  11154. {
  11155. // Profile is empty
  11156. fprintf(outfile,"%s\n",payload);
  11157. fclose(infile);
  11158. fclose(outfile);
  11159. sprintf(rmFileCmd,"rm -f %s",filename);
  11160. system(rmFileCmd);
  11161. rename(tempfile, filename);
  11162. }
  11163. else
  11164. {
  11165. // Profile is not empty
  11166. char buf[2048]={0};
  11167. int ChargingProfileAdded = FALSE;
  11168. while (fgets(buf, sizeof(buf), infile) != NULL)
  11169. {
  11170. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  11171. json_object *tmpChargingProfile;
  11172. tmpChargingProfile = json_tokener_parse(buf);
  11173. if(!is_error(SetChargingProfile))
  11174. {
  11175. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  11176. {
  11177. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  11178. }
  11179. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11180. {
  11181. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11182. {
  11183. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11184. }
  11185. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11186. {
  11187. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  11188. }
  11189. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11190. {
  11191. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11192. }
  11193. }
  11194. }
  11195. json_object_put(tmpChargingProfile);
  11196. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  11197. {
  11198. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  11199. {
  11200. //DEBUG_INFO("update set chargingProfile to file -0\n");
  11201. if(ChargingProfileAdded == FALSE)
  11202. {
  11203. fprintf(outfile,"%s\n",payload);
  11204. ChargingProfileAdded = TRUE;
  11205. }
  11206. }
  11207. else
  11208. {
  11209. if(tempstackLevelInt < stackLevelInt)
  11210. {
  11211. if(ChargingProfileAdded == FALSE)
  11212. {
  11213. fprintf(outfile,"%s\n",buf);
  11214. fprintf(outfile,"%s\n",payload);
  11215. ChargingProfileAdded = TRUE;
  11216. }
  11217. else
  11218. {
  11219. fprintf(outfile,"%s\n",buf);
  11220. }
  11221. }
  11222. else
  11223. {
  11224. if(ChargingProfileAdded == FALSE)
  11225. {
  11226. fprintf(outfile,"%s\n",buf);
  11227. fprintf(outfile,"%s\n",payload);
  11228. ChargingProfileAdded = TRUE;
  11229. }
  11230. else
  11231. {
  11232. fprintf(outfile,"%s\n",buf);
  11233. }
  11234. }
  11235. }
  11236. }
  11237. else
  11238. {
  11239. if(tempchargingProfileIdInt < chargingProfileIdInt)
  11240. {
  11241. if(ChargingProfileAdded == FALSE)
  11242. {
  11243. fprintf(outfile,"%s\n",buf);
  11244. fprintf(outfile,"%s\n",payload);
  11245. ChargingProfileAdded = TRUE;
  11246. }
  11247. else
  11248. {
  11249. fprintf(outfile,"%s\n",buf);
  11250. }
  11251. }
  11252. else if(tempstackLevelInt < stackLevelInt)
  11253. {
  11254. if(ChargingProfileAdded == FALSE)
  11255. {
  11256. fprintf(outfile,"%s\n",buf);
  11257. fprintf(outfile,"%s\n",payload);
  11258. ChargingProfileAdded = TRUE;
  11259. }
  11260. else
  11261. {
  11262. fprintf(outfile,"%s\n",buf);
  11263. }
  11264. }
  11265. else
  11266. {
  11267. if(ChargingProfileAdded == FALSE)
  11268. {
  11269. fprintf(outfile,"%s\n",buf);
  11270. fprintf(outfile,"%s\n",payload);
  11271. ChargingProfileAdded = TRUE;
  11272. }
  11273. else
  11274. {
  11275. fprintf(outfile,"%s\n",buf);
  11276. }
  11277. }
  11278. }
  11279. } // end of while loop
  11280. fclose(infile);
  11281. fclose(outfile);
  11282. sprintf(rmFileCmd,"rm -f %s",filename);
  11283. system(rmFileCmd);
  11284. rename(tempfile, filename);
  11285. }
  11286. sleep(1);
  11287. result = TRUE;
  11288. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11289. end:
  11290. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11291. {
  11292. if(connectorIdInt == 0)
  11293. {
  11294. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11295. {
  11296. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11297. }
  11298. }
  11299. else
  11300. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  11301. }
  11302. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11303. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11304. return result;
  11305. }
  11306. int handleTriggerMessageRequest(char *uuid, char *payload)
  11307. {
  11308. mtrace();
  11309. int result = FAIL;
  11310. int connectorIdIsNULL = FALSE;
  11311. int connectorIdInt =0;
  11312. char sstr[40]={0},sstrtemp[100]={ 0 };
  11313. char requestedMessagestr[40]={0};
  11314. char comfirmstr[20]={0};
  11315. int c = 0;
  11316. char *loc;
  11317. DEBUG_INFO("handleTriggerMessageRequest\n");
  11318. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11319. strcpy(sstrtemp, stringtrimspace(payload));
  11320. c = 0;
  11321. loc = strstr(sstrtemp, "requestedMessage");
  11322. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11323. {
  11324. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11325. c++;
  11326. }
  11327. sstr[c] = '\0';
  11328. strcpy(requestedMessagestr, sstr);
  11329. c = 0;
  11330. loc = strstr(sstrtemp, "connectorId");
  11331. if(loc == NULL)
  11332. {
  11333. connectorIdIsNULL = TRUE;
  11334. }
  11335. else
  11336. {
  11337. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11338. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11339. {
  11340. sstr[c] = loc[strlen("connectorId")+2+c];
  11341. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11342. c++;
  11343. }
  11344. sstr[c] = '\0';
  11345. connectorIdInt = atoi(sstr);
  11346. }
  11347. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11348. {
  11349. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11350. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11351. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11352. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11353. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11354. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11355. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11356. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11357. {
  11358. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11359. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11360. return TRUE;
  11361. }
  11362. else
  11363. {
  11364. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11365. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11366. }
  11367. }
  11368. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11369. {
  11370. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11371. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11372. return TRUE;
  11373. }
  11374. //==========================
  11375. // Trigger message
  11376. //==========================
  11377. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11378. {
  11379. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11380. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11381. {
  11382. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11383. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11384. }
  11385. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11386. }
  11387. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11388. {
  11389. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11390. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11391. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11392. }
  11393. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11394. {
  11395. //sendBootNotificationRequest();
  11396. server_sign = FALSE;
  11397. }
  11398. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11399. {
  11400. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11401. }
  11402. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11403. {
  11404. if(connectorIdIsNULL == FALSE)
  11405. {
  11406. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11407. {
  11408. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11409. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11410. }
  11411. }
  11412. else
  11413. {
  11414. for(int idx=0;idx< gunTotalNumber;idx++)
  11415. {
  11416. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11417. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11418. }
  11419. }
  11420. }
  11421. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11422. {
  11423. if(connectorIdIsNULL == FALSE)
  11424. {
  11425. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11426. {
  11427. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11428. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11429. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11430. }
  11431. }
  11432. else
  11433. {
  11434. for(int idx=0;idx< gunTotalNumber;idx++)
  11435. {
  11436. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11437. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11438. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11439. }
  11440. }
  11441. }
  11442. return result;
  11443. }
  11444. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11445. {
  11446. mtrace();
  11447. int result = FAIL;
  11448. int connectorIdInt =0;
  11449. char comfirmstr[20]={0};
  11450. int tempIndex = 0;
  11451. json_object *UnlockConnector;
  11452. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11453. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11454. UnlockConnector = json_tokener_parse(payload);
  11455. if(!is_error(UnlockConnector))
  11456. {
  11457. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11458. {
  11459. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11460. }
  11461. }
  11462. json_object_put(UnlockConnector);
  11463. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11464. if(gunTotalNumber == 0)
  11465. {
  11466. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11467. goto end;
  11468. }
  11469. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11470. {
  11471. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11472. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11473. goto end;
  11474. }
  11475. else
  11476. {
  11477. //check Transaction active
  11478. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11479. {
  11480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11481. {
  11482. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11483. }
  11484. else
  11485. {
  11486. tempIndex = connectorIdInt -1;
  11487. }
  11488. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11489. {
  11490. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11491. {
  11492. //stop Transaction
  11493. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11494. }
  11495. }
  11496. }
  11497. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11498. {
  11499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11500. {
  11501. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11502. }
  11503. else
  11504. {
  11505. tempIndex = connectorIdInt -1;
  11506. }
  11507. for (int index = 0; index < CCS_QUANTITY; index++)
  11508. {
  11509. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11510. {
  11511. //stop Transaction
  11512. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11513. }
  11514. }
  11515. }
  11516. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11517. {
  11518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11519. {
  11520. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11521. }
  11522. else
  11523. {
  11524. tempIndex = connectorIdInt -1;
  11525. }
  11526. for (int index = 0; index < GB_QUANTITY; index++)
  11527. {
  11528. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11529. {
  11530. //stop Transaction
  11531. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11532. }
  11533. }
  11534. }
  11535. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11536. {
  11537. tempIndex = connectorIdInt -1;
  11538. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11539. {
  11540. 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)))
  11541. {
  11542. //stop Transaction
  11543. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11544. }
  11545. }
  11546. }
  11547. else
  11548. {
  11549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11550. {
  11551. tempIndex = 2;
  11552. }
  11553. else
  11554. {
  11555. tempIndex = connectorIdInt-1;
  11556. }
  11557. for (int index = 0; index < AC_QUANTITY; index++)
  11558. {
  11559. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11560. {
  11561. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11562. }
  11563. }
  11564. }
  11565. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11566. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11567. result = TRUE;
  11568. return result;
  11569. }
  11570. end:
  11571. //json_object_put(obj); --- remove temporally
  11572. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11573. return result;
  11574. }
  11575. static char UpdateFirmwarepayloadData[300]={0};
  11576. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11577. {
  11578. mtrace();
  11579. int result = FAIL;
  11580. pthread_t t;
  11581. sendUpdateFirmwareConfirmation(uuid);
  11582. memset(UpdateFirmwarepayloadData, 0, 300);
  11583. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11584. if(!interLock.isUpdateFirmwareGoing)
  11585. {
  11586. interLock.isUpdateFirmwareGoing = 1;
  11587. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11588. }
  11589. else
  11590. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11591. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11592. return result;
  11593. }
  11594. void *UpdateFirmwareProcess(void *data)
  11595. {
  11596. pthread_detach(pthread_self());
  11597. mtrace();
  11598. int retriesInt =0, retryIntervalInt=0;
  11599. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11600. int port=0;
  11601. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11602. int isSuccess = 0;
  11603. char ftpbuf[1024];
  11604. char temp[1024];
  11605. char * pch;
  11606. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11607. json_object *UpdateFirmware;
  11608. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11609. if(!is_error(UpdateFirmware))
  11610. {
  11611. // Required data
  11612. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11613. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11614. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11615. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11616. // Optional data
  11617. if(json_object_object_get(UpdateFirmware, "retries"))
  11618. {
  11619. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11620. }
  11621. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11622. {
  11623. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11624. }
  11625. }
  11626. json_object_put(UpdateFirmware);
  11627. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11628. memset(path, 0, ARRAY_SIZE(path));
  11629. // Wait retrieveData
  11630. if(strlen(retrieveDatestr) > 10)
  11631. {
  11632. do
  11633. {
  11634. sleep(1);
  11635. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11636. }
  11637. // Ready to download
  11638. system("rm -f /mnt/*");
  11639. if(strncmp(locationstr,"http", 4) == 0)
  11640. {
  11641. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11642. sprintf(ftppath,"/%s", path);
  11643. DEBUG_INFO("locationstr: %s\n", locationstr);
  11644. DEBUG_INFO("protocol: %s\n",protocol);
  11645. DEBUG_INFO("host: %s\n",host);
  11646. DEBUG_INFO("path: %s\n",path);
  11647. DEBUG_INFO("ftppath: %s\n",ftppath);
  11648. int ftppathlen=strlen(ftppath);
  11649. int i=1;
  11650. char filenametemp[50];
  11651. while(i < ftppathlen)
  11652. {
  11653. int len=ftppathlen-i;
  11654. if(ftppath[len]== 47) // '/' ascll code: 47
  11655. {
  11656. DEBUG_INFO("compare '/' all right\n");
  11657. break;
  11658. }
  11659. i=i+1;
  11660. }
  11661. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11662. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11663. filenametemp[i+1] = 0;
  11664. do
  11665. {
  11666. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11667. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11668. sleep(1);
  11669. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11670. if(!isSuccess)
  11671. {
  11672. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11673. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11674. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11675. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11676. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11677. }
  11678. else
  11679. {
  11680. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11681. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11682. }
  11683. retriesInt--;
  11684. }while((isSuccess == 0)&&(retriesInt >= 0));
  11685. }
  11686. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11687. {
  11688. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11689. memset(temp, 0, ARRAY_SIZE(temp));
  11690. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11691. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11692. int ftppathlen=strlen(ftpbuf);
  11693. int i=1;
  11694. char filenametemp[50];
  11695. while(i < ftppathlen)
  11696. {
  11697. int len=ftppathlen-i;
  11698. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11699. {
  11700. DEBUG_INFO(" compare '/' all right\n");
  11701. break;
  11702. }
  11703. i=i+1;
  11704. }
  11705. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11706. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11707. filenametemp[i+1] = 0;
  11708. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11709. pch=strchr(temp,'@');
  11710. if(pch==NULL)
  11711. {
  11712. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11713. protocol, host, &port, path);
  11714. strcpy(user,"anonymous");
  11715. strcpy(password,"");
  11716. }
  11717. else
  11718. {
  11719. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11720. protocol, user, password, host, &port, path);
  11721. }
  11722. sscanf(host,"%[^/]%s",host1, path1);
  11723. sprintf(ftppath,"%s", path1);
  11724. //DEBUG_INFO("protocol =%s\n",protocol);
  11725. //DEBUG_INFO("user =%s\n",user);
  11726. //DEBUG_INFO("password =%s\n",password);
  11727. //DEBUG_INFO("host1 =%s\n",host1);
  11728. //DEBUG_INFO("port =%d\n",port);
  11729. //DEBUG_INFO("path1 =%s\n",path1);
  11730. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11731. //ftpFile(host, user, password, port, ftppath, fname);
  11732. //download firmware pthred
  11733. if(port == 0)
  11734. {
  11735. port = 21;
  11736. }
  11737. do
  11738. {
  11739. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11740. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11741. sleep(1);
  11742. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11743. if(!isSuccess)
  11744. {
  11745. //BulldogUtil.sleepMs(interval*1000);
  11746. DEBUG_INFO("Update firmware request and download file fail.\n");
  11747. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11748. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11749. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11750. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11751. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11752. }
  11753. else
  11754. {
  11755. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11756. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11757. }
  11758. retriesInt--;
  11759. }while((!isSuccess)&&(retriesInt >= 0));
  11760. }
  11761. else
  11762. {
  11763. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11764. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11765. sleep(1);
  11766. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11767. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11768. }
  11769. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11770. interLock.isUpdateFirmwareGoing = 0;
  11771. pthread_exit(NULL);
  11772. }
  11773. int handleCertificateSignedRequest(char *uuid, char *payload)
  11774. {
  11775. mtrace();
  11776. int result = PASS;
  11777. json_object *CertificateSigned;
  11778. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11779. CertificateSigned = json_tokener_parse(payload);
  11780. if(!is_error(CertificateSigned))
  11781. {
  11782. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11783. }
  11784. json_object_put(CertificateSigned);
  11785. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11786. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11787. fclose(fp);
  11788. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11789. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11790. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11791. sendCertificateSignedConfirmation(uuid);
  11792. return result;
  11793. }
  11794. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11795. {
  11796. mtrace();
  11797. int result = PASS;
  11798. json_object *DeleteCertificate;
  11799. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11800. DeleteCertificate = json_tokener_parse(payload);
  11801. if(!is_error(DeleteCertificate))
  11802. {
  11803. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11804. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11805. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11806. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11807. }
  11808. json_object_put(DeleteCertificate);
  11809. /*
  11810. * TODO: Delete certificateSigned process
  11811. */
  11812. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11813. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11814. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11815. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11816. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11817. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11818. sendDeleteCertificateConfirmation(uuid);
  11819. return result;
  11820. }
  11821. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11822. {
  11823. mtrace();
  11824. int result = PASS;
  11825. json_object *ExtendedTriggerMessage;
  11826. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11827. ExtendedTriggerMessage = json_tokener_parse(payload);
  11828. if(!is_error(ExtendedTriggerMessage))
  11829. {
  11830. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11831. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11832. {
  11833. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11834. }
  11835. else
  11836. {
  11837. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11838. }
  11839. }
  11840. json_object_put(ExtendedTriggerMessage);
  11841. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11842. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11843. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11844. {
  11845. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11846. }
  11847. else
  11848. {
  11849. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11850. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11851. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11852. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11853. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11854. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11855. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11856. {
  11857. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11858. }
  11859. else
  11860. {
  11861. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11862. }
  11863. }
  11864. sendExtendedTriggerMessageConfirmation(uuid);
  11865. //==========================
  11866. // Trigger message
  11867. //==========================
  11868. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11869. {
  11870. //sendBootNotificationRequest();
  11871. server_sign = FALSE;
  11872. }
  11873. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11874. {
  11875. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11876. }
  11877. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11878. {
  11879. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11880. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11881. {
  11882. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11883. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11884. }
  11885. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11886. }
  11887. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11888. {
  11889. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11890. }
  11891. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11892. {
  11893. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11894. {
  11895. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11896. }
  11897. else
  11898. {
  11899. for(int idx=0;idx< gunTotalNumber;idx++)
  11900. {
  11901. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11902. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11903. }
  11904. }
  11905. }
  11906. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11907. {
  11908. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11909. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11910. {
  11911. 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\" &");
  11912. }
  11913. }
  11914. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11915. {
  11916. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11917. {
  11918. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11919. }
  11920. else
  11921. {
  11922. for(int idx=0;idx< gunTotalNumber;idx++)
  11923. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11924. }
  11925. }
  11926. return result;
  11927. }
  11928. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11929. {
  11930. mtrace();
  11931. int result = PASS;
  11932. json_object *GetInstalledCertificateIds;
  11933. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11934. GetInstalledCertificateIds = json_tokener_parse(payload);
  11935. if(!is_error(GetInstalledCertificateIds))
  11936. {
  11937. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11938. }
  11939. json_object_put(GetInstalledCertificateIds);
  11940. /*
  11941. * TODO: Return installed certificate process
  11942. */
  11943. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11944. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11945. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11946. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11947. sendGetInstalledCertificateIdsConfirmation(uuid);
  11948. return result;
  11949. }
  11950. int handleGetLogRequest(char *uuid, char *payload)
  11951. {
  11952. mtrace();
  11953. int result = PASS;
  11954. json_object *GetLog;
  11955. DEBUG_INFO("handleGetLogRequest...\n");
  11956. GetLog = json_tokener_parse(payload);
  11957. if(!is_error(GetLog))
  11958. {
  11959. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11960. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11961. if(json_object_object_get(GetLog, "retries") != NULL)
  11962. {
  11963. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11964. }
  11965. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11966. {
  11967. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11968. }
  11969. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11970. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11971. {
  11972. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11973. }
  11974. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11975. {
  11976. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11977. }
  11978. }
  11979. json_object_put(GetLog);
  11980. /*
  11981. * TODO: Upload log process
  11982. */
  11983. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11984. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11985. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11986. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11987. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11988. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11989. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11990. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11991. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11992. sendGetLogConfirmation(uuid);
  11993. return result;
  11994. }
  11995. int handleInstallCertificateRequest(char *uuid, char *payload)
  11996. {
  11997. mtrace();
  11998. int result = PASS;
  11999. json_object *InstallCertificate;
  12000. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12001. InstallCertificate = json_tokener_parse(payload);
  12002. if(!is_error(InstallCertificate))
  12003. {
  12004. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12005. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12006. /*
  12007. * TODO: Install certificate process
  12008. */
  12009. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12010. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12011. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12012. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12013. sendInstallCertificateConfirmation(uuid);
  12014. }
  12015. json_object_put(InstallCertificate);
  12016. return result;
  12017. }
  12018. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12019. {
  12020. mtrace();
  12021. int result = PASS;
  12022. json_object *SignedUpdateFirmware;
  12023. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12024. SignedUpdateFirmware = json_tokener_parse(payload);
  12025. if(!is_error(SignedUpdateFirmware))
  12026. {
  12027. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12028. {
  12029. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12030. }
  12031. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12032. {
  12033. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12034. }
  12035. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12036. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12037. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12038. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12039. {
  12040. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12041. }
  12042. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12043. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12044. }
  12045. json_object_put(SignedUpdateFirmware);
  12046. /*
  12047. * TODO: Upgrade firmware process
  12048. */
  12049. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12050. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  12051. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  12052. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  12053. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  12054. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  12055. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  12056. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  12057. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  12058. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  12059. sendInstallCertificateConfirmation(uuid);
  12060. return result;
  12061. }
  12062. int handleUnknownRequest(char *uuid, char *payload)
  12063. {
  12064. mtrace();
  12065. int result = PASS;
  12066. DEBUG_INFO("handleUnknownRequest...\n");
  12067. sendUnknownConfirmation(uuid);
  12068. result = PASS;
  12069. return result;
  12070. }
  12071. //==========================================
  12072. // Handle server response routine
  12073. //==========================================
  12074. void handleAuthorizeResponse(char *payload, int gun_index)
  12075. {
  12076. mtrace();
  12077. char expiryDatestr[30]={0};
  12078. char parentIdTagstr[20]={0};
  12079. char statusstr[20]={0};
  12080. int expiryDateISNULL=FALSE;
  12081. int parentIdTagISNULL=FALSE;
  12082. DEBUG_INFO("handleAuthorizeResponse...\n");
  12083. json_object *Authorize;
  12084. Authorize = json_tokener_parse(payload);
  12085. if(!is_error(Authorize))
  12086. {
  12087. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12088. {
  12089. // Required data
  12090. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12091. // Optional data
  12092. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12093. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12094. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12095. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12096. }
  12097. }
  12098. json_object_put(Authorize);
  12099. if(expiryDateISNULL == FALSE)
  12100. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12101. if(parentIdTagISNULL == FALSE)
  12102. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12103. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12104. //Update idTag information to authorization cache if supproted
  12105. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12106. {
  12107. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12108. }
  12109. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12110. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12111. authorizeRetryTimes = 0;
  12112. }
  12113. void handleBootNotificationResponse(char *payload, int gun_index)
  12114. {
  12115. mtrace();
  12116. char statusStr[12]={0};
  12117. char currentTimeStr[30]={0};
  12118. int intervalInt = 0;
  12119. DEBUG_INFO("handleBootNotificationResponse...\n");
  12120. json_object *BootNotification;
  12121. BootNotification = json_tokener_parse(payload);
  12122. if(!is_error(BootNotification))
  12123. {
  12124. // Required data
  12125. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12126. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12127. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12128. }
  12129. json_object_put(BootNotification);
  12130. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12131. BootNotificationInterval = intervalInt;
  12132. HeartBeatWaitTime = intervalInt;
  12133. //write back to ShmOCPP16Data->BootNotification
  12134. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12135. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12136. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12137. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12138. {
  12139. server_sign = TRUE;
  12140. server_pending =FALSE;
  12141. }
  12142. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12143. {
  12144. server_pending = TRUE;
  12145. }
  12146. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12147. srand(time(NULL));
  12148. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12149. SetOcppConnStatus(TRUE);
  12150. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12151. }
  12152. void handleDataTransferResponse(char *payload, int gun_index)
  12153. {
  12154. char sstr[160]={0};//sstr[200]={ 0 };
  12155. int c = 0;
  12156. char *loc;
  12157. DEBUG_INFO("handleDataTransferResponse ...\n");
  12158. loc = strstr(payload, "status");
  12159. c = 0;
  12160. while (loc[3+strlen("status")+c] != '\"')
  12161. {
  12162. sstr[c] = loc[3+strlen("status")+c];
  12163. c++;
  12164. }
  12165. sstr[c] = '\0';
  12166. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12167. }
  12168. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12169. {
  12170. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12171. //struct json_object *obj;
  12172. // obj = json_tokener_parse(payload);
  12173. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12174. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12175. //No fields are defined.
  12176. }
  12177. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12178. {
  12179. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12180. //struct json_object *obj;
  12181. // obj = json_tokener_parse(payload);
  12182. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12183. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12184. //No fields are defined.
  12185. }
  12186. void handleHeartbeatResponse(char *payload, int gun_index)
  12187. {
  12188. mtrace();
  12189. DEBUG_INFO("handleHeartbeatResponse...\n");
  12190. json_object *Heartbeat;
  12191. Heartbeat = json_tokener_parse(payload);
  12192. if(!is_error(Heartbeat))
  12193. {
  12194. // Required data
  12195. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12196. }
  12197. json_object_put(Heartbeat);
  12198. if(FirstHeartBeat == 0)
  12199. {
  12200. FirstHeartBeat = 1;
  12201. DEBUG_INFO("FirstHeartBeat \n");
  12202. }
  12203. HeartBeatWithNOResponse = 0;
  12204. clientTime.Heartbeat=time((time_t*)NULL);
  12205. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12206. }
  12207. void handleMeterValuesResponse(char *payload, int gun_index)
  12208. {
  12209. mtrace();
  12210. DEBUG_INFO("handleMeterValuesResponse...\n");
  12211. }
  12212. void handleStartTransactionResponse(char *payload, int gun_index)
  12213. {
  12214. mtrace();
  12215. //int transactionIdInt = 0;
  12216. FILE *outfile;
  12217. char data[100]={0};
  12218. DEBUG_INFO("handleStartTransactionResponse...\n");
  12219. json_object *StartTransaction;
  12220. StartTransaction = json_tokener_parse(payload);
  12221. if(!is_error(StartTransaction))
  12222. {
  12223. // Required data
  12224. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12225. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12226. // Optional data
  12227. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12228. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12229. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12230. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12231. }
  12232. json_object_put(StartTransaction);
  12233. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12234. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12235. //-----------Start : write to the Queue TransactionId file -----------------//
  12236. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12237. {}
  12238. else
  12239. {
  12240. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12241. if(log == NULL)
  12242. {
  12243. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12244. return ;
  12245. }
  12246. else
  12247. {
  12248. fclose(log);
  12249. }
  12250. }
  12251. // open file for writing
  12252. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12253. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12254. {
  12255. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12256. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12257. fputs(data, outfile);
  12258. fclose (outfile);
  12259. }
  12260. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12261. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12262. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12263. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12264. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12265. }
  12266. void handleStatusNotificationResponse(char *payload, int gun_index)
  12267. {
  12268. mtrace();
  12269. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12270. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12271. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12272. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12273. }
  12274. void handleStopTransactionnResponse(char *payload, int gun_index)
  12275. {
  12276. mtrace();
  12277. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12278. json_object *StopTransaction;
  12279. StopTransaction = json_tokener_parse(payload);
  12280. if(!is_error(StopTransaction))
  12281. {
  12282. // Optional data
  12283. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12284. {
  12285. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12286. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12287. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12288. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12289. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12290. }
  12291. }
  12292. json_object_put(StopTransaction);
  12293. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12294. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12295. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12296. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12297. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12298. }
  12299. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12300. {
  12301. mtrace();
  12302. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12303. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12304. }
  12305. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12306. {
  12307. mtrace();
  12308. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12309. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12310. }
  12311. void handleSignCertificateResponse(char *payload, int gun_index)
  12312. {
  12313. mtrace();
  12314. DEBUG_INFO("handleSignCertificateResponse...\n");
  12315. json_object *SignCertificate;
  12316. SignCertificate = json_tokener_parse(payload);
  12317. if(!is_error(SignCertificate))
  12318. {
  12319. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12320. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12321. }
  12322. json_object_put(SignCertificate);
  12323. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12324. }
  12325. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12326. {
  12327. mtrace();
  12328. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12329. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12330. }
  12331. //==========================================
  12332. // Handle Error routine
  12333. //==========================================
  12334. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12335. {
  12336. mtrace();
  12337. #ifdef SystemLogMessage
  12338. DEBUG_INFO("errorCode: %s\n", errorCode);
  12339. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12340. DEBUG_INFO("errorDetails: %s\n", payload);
  12341. #endif
  12342. }
  12343. //===============================================
  12344. // Common routine
  12345. //===============================================
  12346. int initialConfigurationTable(void)
  12347. {
  12348. //clock_t start_t, end_t, total_t;
  12349. FILE *fp;
  12350. FILE *outfile;
  12351. char str[512]={0};
  12352. char sstr[256]={0};
  12353. int c = 0;
  12354. char *loc;
  12355. int confVersion = 8;
  12356. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12357. //start_t = clock();
  12358. //printf("Starting of the program, start_t = %ld\n", start_t);
  12359. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12360. // Check configuration file size is correct
  12361. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12362. {
  12363. struct stat st;
  12364. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12365. if(st.st_size < 3100)
  12366. {
  12367. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12368. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12369. }
  12370. }
  12371. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12372. {
  12373. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12374. if(outfile == NULL)
  12375. {
  12376. DEBUG_INFO("Error opening file\n");
  12377. return FALSE;
  12378. }
  12379. /*Core Profile*/
  12380. //AllowOfflineTxForUnknownId
  12381. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12385. //AuthorizationCacheEnabled
  12386. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12390. //AuthorizeRemoteTxRequests
  12391. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12395. //BlinkRepeat
  12396. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12400. //ClockAlignedDataInterval
  12401. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12405. //ConnectionTimeOut
  12406. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12410. //GetConfigurationMaxKeys
  12411. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12415. // HeartbeatInterval
  12416. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12420. // LightIntensity
  12421. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12425. // LocalAuthorizeOffline
  12426. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12430. // LocalPreAuthorize
  12431. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12435. // MaxEnergyOnInvalidId
  12436. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12440. // MeterValuesAlignedData
  12441. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12444. 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" );
  12445. else
  12446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12448. // MeterValuesAlignedDataMaxLength
  12449. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12451. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12453. else
  12454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12456. // MeterValuesSampledData
  12457. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12460. 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" );
  12461. else
  12462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12464. // MeterValuesSampledDataMaxLength
  12465. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12469. else
  12470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12472. // MeterValueSampleInterval
  12473. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12477. // MinimumStatusDuration
  12478. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12481. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12483. // NumberOfConnectors
  12484. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12487. {
  12488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12489. }
  12490. else
  12491. {
  12492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12493. }
  12494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12495. // ResetRetries
  12496. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12500. // ConnectorPhaseRotation
  12501. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12505. // ConnectorPhaseRotationMaxLength
  12506. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12510. // StopTransactionOnEVSideDisconnect
  12511. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12515. // StopTransactionOnInvalidId
  12516. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12520. // StopTxnAlignedData
  12521. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12525. // StopTxnAlignedDataMaxLength
  12526. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12530. // StopTxnSampledData
  12531. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12535. else
  12536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12538. // StopTxnSampledDataMaxLength
  12539. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12542. {
  12543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12544. }
  12545. else
  12546. {
  12547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12548. }
  12549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12550. // SupportedFeatureProfiles
  12551. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12555. // SupportedFeatureProfilesMaxLength
  12556. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12560. // TransactionMessageAttempts
  12561. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12564. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12566. // TransactionMessageRetryInterval
  12567. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12570. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12572. // UnlockConnectorOnEVSideDisconnect
  12573. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12577. // WebSocketPingInterval
  12578. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12582. // QueueOffLineMeterValues
  12583. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12587. // AuthorizationKey
  12588. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12592. // SecurityProfile
  12593. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12597. // DefaultPrice
  12598. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12602. // CustomDisplayCostAndPrice
  12603. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12607. // CustomIdleFeeAfterStop
  12608. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12612. // TimeOffset
  12613. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12617. // NextTimeOffsetTransitionDateTime
  12618. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12622. // TimeOffsetNextTransition
  12623. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12627. // Configuration Version
  12628. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12632. //* Local Auth List Management Profile*/
  12633. #if 0
  12634. //For OCTT Test Case
  12635. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12638. #endif
  12639. #if 1
  12640. //LocalAuthListEnabled
  12641. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12645. #endif
  12646. //LocalAuthListMaxLength
  12647. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12651. //SendLocalListMaxLength
  12652. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12656. //ReserveConnectorZeroSupported
  12657. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12661. //* Smart Charging Profile */
  12662. //ChargeProfileMaxStackLevel
  12663. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12667. // ChargingScheduleAllowedChargingRateUnit
  12668. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12672. // ChargingScheduleMaxPeriods
  12673. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12677. // ConnectorSwitch3to1PhaseSupported
  12678. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12682. // MaxChargingProfilesInstalled
  12683. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12687. fclose(outfile);
  12688. }
  12689. else
  12690. {
  12691. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12692. char keystr[60]={0};
  12693. char readonlystr[10]={0};
  12694. char valuestr[256]={0};
  12695. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12696. if(fp == NULL) {
  12697. DEBUG_INFO("Error opening file");
  12698. return FALSE;
  12699. }
  12700. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12701. {
  12702. //DEBUG_INFO("Get Configuration \n");
  12703. if(strlen(str) > 0)
  12704. {
  12705. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12706. //*************************key*********************************/
  12707. if(strstr(str, "key") != NULL)
  12708. {
  12709. loc = strstr(str, "key");
  12710. c = 0;
  12711. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12712. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12713. {
  12714. sstr[c] = loc[strlen("key")+3+c];
  12715. c++;
  12716. }
  12717. sstr[c] = '\0';
  12718. strcpy(keystr,sstr);
  12719. }
  12720. //*************************readonly*********************************/
  12721. if(strstr(str, "readonly") != NULL)
  12722. {
  12723. loc = strstr(str, "readonly");
  12724. c = 0;
  12725. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12726. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12727. {
  12728. sstr[c] = loc[strlen("readonly")+2+c];
  12729. c++;
  12730. }
  12731. sstr[c] = '\0';
  12732. strcpy(readonlystr,sstr);
  12733. }
  12734. //*************************value*********************************/
  12735. if(strstr(str, "value") != NULL)
  12736. {
  12737. loc = strstr(str, "value");
  12738. c = 0;
  12739. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12740. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12741. {
  12742. sstr[c] = loc[strlen("value")+3+c];
  12743. c++;
  12744. }
  12745. sstr[c] = '\0';
  12746. strcpy(valuestr,sstr);
  12747. }
  12748. // DEBUG_INFO("keystr=%s\n",keystr);
  12749. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12750. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12751. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12752. {
  12753. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12754. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12756. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12757. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12758. }
  12759. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12760. {
  12761. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12762. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12764. }
  12765. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12766. {
  12767. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12769. }
  12770. if(strcmp(keystr, "BlinkRepeat") == 0)
  12771. {
  12772. //Charger.BlinkRepeat = Integer.parseInt(value);
  12773. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12775. }
  12776. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12777. {
  12778. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12780. }
  12781. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12782. {
  12783. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12785. }
  12786. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12787. {
  12788. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12790. }
  12791. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12792. {
  12793. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12795. HeartBeatWaitTime = atoi(valuestr);
  12796. }
  12797. if(strcmp(keystr, "LightIntensity") == 0)
  12798. {
  12799. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12801. }
  12802. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12803. {
  12804. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12806. }
  12807. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12808. {
  12809. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12811. }
  12812. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12813. {
  12814. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12816. }
  12817. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12818. {
  12819. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12821. }
  12822. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12823. {
  12824. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12826. }
  12827. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12828. {
  12829. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12831. }
  12832. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12833. {
  12834. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12836. }
  12837. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12838. {
  12839. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12841. }
  12842. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12843. {
  12844. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12846. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12847. }
  12848. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12849. {
  12850. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12852. }
  12853. if(strcmp(keystr, "ResetRetries") == 0)
  12854. {
  12855. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12857. }
  12858. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12859. {
  12860. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12862. }
  12863. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12864. {
  12865. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12867. }
  12868. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12869. {
  12870. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12872. }
  12873. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12874. {
  12875. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12877. }
  12878. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12879. {
  12880. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12882. }
  12883. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12884. {
  12885. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12887. }
  12888. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12889. {
  12890. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12892. }
  12893. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12894. {
  12895. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12897. }
  12898. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12899. {
  12900. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12902. }
  12903. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12904. {
  12905. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12907. }
  12908. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12909. {
  12910. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12912. TransactionMessageAttemptsValue = atoi(valuestr);
  12913. }
  12914. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12915. {
  12916. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12918. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12919. }
  12920. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12921. {
  12922. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12924. }
  12925. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12926. {
  12927. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12929. }
  12930. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12931. {
  12932. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12934. }
  12935. if(strcmp(keystr, "AuthorizationKey") == 0)
  12936. {
  12937. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12938. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12940. }
  12941. if(strcmp(keystr, "SecurityProfile") == 0)
  12942. {
  12943. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12945. }
  12946. if(strcmp(keystr, "DefaultPrice") == 0)
  12947. {
  12948. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12950. }
  12951. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12952. {
  12953. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12955. }
  12956. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12957. {
  12958. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12960. }
  12961. if(strcmp(keystr, "TimeOffset") == 0)
  12962. {
  12963. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12965. }
  12966. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12967. {
  12968. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12970. }
  12971. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12972. {
  12973. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12975. }
  12976. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12977. {
  12978. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12980. }
  12981. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12982. {
  12983. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12985. }
  12986. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12987. {
  12988. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12990. }
  12991. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12992. {
  12993. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12995. }
  12996. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12997. {
  12998. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13000. }
  13001. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13002. {
  13003. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13005. }
  13006. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13007. {
  13008. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13010. }
  13011. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13012. {
  13013. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13015. }
  13016. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13017. {
  13018. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13020. }
  13021. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13022. {
  13023. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13025. }
  13026. }
  13027. }
  13028. fclose(fp);
  13029. }
  13030. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13031. {
  13032. return PASS;
  13033. }
  13034. else
  13035. {
  13036. return FAIL;
  13037. }
  13038. }
  13039. void StoreConfigurationTable(void)
  13040. {
  13041. FILE *outfile;
  13042. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13043. if(outfile == NULL)
  13044. {
  13045. DEBUG_INFO("Error opening file");
  13046. return ;
  13047. }
  13048. /*Core Profile*/
  13049. //AllowOfflineTxForUnknownId
  13050. /*
  13051. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13052. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13055. */
  13056. //DEBUG_INFO("data=%s\n",data);
  13057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13058. //AuthorizationCacheEnabled
  13059. /*
  13060. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13063. */
  13064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13065. //AuthorizeRemoteTxRequests
  13066. /*
  13067. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13070. */
  13071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13072. //BlinkRepeat
  13073. /*
  13074. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13077. */
  13078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13079. //ClockAlignedDataInterval
  13080. /*
  13081. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13084. */
  13085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13086. //ConnectionTimeOut
  13087. /*
  13088. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13091. */
  13092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13093. //GetConfigurationMaxKeys
  13094. /*
  13095. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13098. */
  13099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13100. // HeartbeatInterval
  13101. /*
  13102. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13105. */
  13106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13107. // LightIntensity
  13108. /*
  13109. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13112. */
  13113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13114. // LocalAuthorizeOffline
  13115. /*
  13116. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13119. */
  13120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13121. // LocalPreAuthorize
  13122. /*
  13123. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13126. */
  13127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13128. // MaxEnergyOnInvalidId
  13129. /*
  13130. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13133. */
  13134. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13136. // MeterValuesAlignedData
  13137. /*
  13138. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13141. */
  13142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13143. // MeterValuesAlignedDataMaxLength
  13144. /*
  13145. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13148. */
  13149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13150. // MeterValuesSampledData
  13151. /*
  13152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13155. */
  13156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13157. // MeterValuesSampledDataMaxLength
  13158. /*
  13159. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13162. */
  13163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13164. // MeterValueSampleInterval
  13165. /*
  13166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13169. */
  13170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13171. // MinimumStatusDuration
  13172. /*
  13173. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13176. */
  13177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13178. // NumberOfConnectors
  13179. /*
  13180. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13183. {
  13184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13185. }
  13186. else
  13187. {
  13188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13189. }
  13190. */
  13191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13192. // ResetRetries
  13193. /*
  13194. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13197. */
  13198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13199. // ConnectorPhaseRotation
  13200. /*
  13201. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13204. */
  13205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13206. // ConnectorPhaseRotationMaxLength
  13207. /*
  13208. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13211. */
  13212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13213. // StopTransactionOnEVSideDisconnect
  13214. /*
  13215. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13218. */
  13219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13220. // StopTransactionOnInvalidId
  13221. /*
  13222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13225. */
  13226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13227. // StopTxnAlignedData
  13228. /*
  13229. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13232. */
  13233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13234. // StopTxnAlignedDataMaxLength
  13235. /*
  13236. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13239. */
  13240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13241. // StopTxnSampledData
  13242. /*
  13243. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13246. */
  13247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13248. // StopTxnSampledDataMaxLength
  13249. /*
  13250. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13253. */
  13254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13255. // SupportedFeatureProfiles
  13256. /*
  13257. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13260. */
  13261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13262. // SupportedFeatureProfilesMaxLength
  13263. /*
  13264. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13267. */
  13268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13269. // TransactionMessageAttempts
  13270. /*
  13271. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13274. */
  13275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13276. // TransactionMessageRetryInterval
  13277. /*
  13278. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13281. */
  13282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13283. // UnlockConnectorOnEVSideDisconnect
  13284. /*
  13285. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13288. */
  13289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13290. // WebSocketPingInterval
  13291. /*
  13292. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13295. */
  13296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13297. // QueueOffLineMeterValues
  13298. /*
  13299. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13302. */
  13303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13304. // AuthorizationKey
  13305. /*
  13306. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13309. */
  13310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13311. // SecurityProfile
  13312. /*
  13313. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13316. */
  13317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13318. // DefaultPrice
  13319. /*
  13320. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13323. */
  13324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13325. // CustomDisplayCostAndPrice
  13326. /*
  13327. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13330. */
  13331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13332. // CustomIdleFeeAfterStop
  13333. /*
  13334. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13337. */
  13338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13339. // TimeOffset
  13340. /*
  13341. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13344. */
  13345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13346. // NextTimeOffsetTransitionDateTime
  13347. /*
  13348. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13351. */
  13352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13353. // TimeOffsetNextTransition
  13354. /*
  13355. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13358. */
  13359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13360. // ConfigurationVersion
  13361. /*
  13362. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13365. */
  13366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13367. //* Local Auth List Management Profile*/
  13368. //LocalAuthListEnabled
  13369. /*
  13370. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13373. */
  13374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13375. //LocalAuthListMaxLength
  13376. /*
  13377. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13380. */
  13381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13382. //SendLocalListMaxLength
  13383. /*
  13384. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13387. */
  13388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13389. //ReserveConnectorZeroSupported
  13390. /*
  13391. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13394. */
  13395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13396. //* Smart Charging Profile */
  13397. //ChargeProfileMaxStackLevel
  13398. /*
  13399. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13402. */
  13403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13404. // ChargingScheduleAllowedChargingRateUnit
  13405. /*
  13406. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13409. */
  13410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13411. // ChargingScheduleMaxPeriods
  13412. /*
  13413. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13416. */
  13417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13418. // ConnectorSwitch3to1PhaseSupported
  13419. /*
  13420. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13423. */
  13424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13425. // MaxChargingProfilesInstalled
  13426. /*
  13427. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13430. */
  13431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13432. fclose(outfile);
  13433. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13434. }
  13435. void getKeyValue(char *keyReq)
  13436. {
  13437. int isEmpty = FALSE;
  13438. int isKnowKey = FALSE;
  13439. DEBUG_INFO("keyReq = %s\n", keyReq);
  13440. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13441. isEmpty = TRUE;
  13442. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13443. {
  13444. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13446. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13447. {
  13448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13449. }
  13450. else
  13451. {
  13452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13453. }
  13454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13455. isKnowKey = TRUE;
  13456. }
  13457. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13458. {
  13459. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13462. {
  13463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13464. }
  13465. else
  13466. {
  13467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13468. }
  13469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13470. isKnowKey = TRUE;
  13471. }
  13472. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13473. {
  13474. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13477. {
  13478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13479. }
  13480. else
  13481. {
  13482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13483. }
  13484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13485. isKnowKey = TRUE;
  13486. }
  13487. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13488. {
  13489. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13491. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13492. {
  13493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13494. }
  13495. else
  13496. {
  13497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13498. }
  13499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13500. isKnowKey = TRUE;
  13501. }
  13502. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13503. {
  13504. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13507. {
  13508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13509. }
  13510. else
  13511. {
  13512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13513. }
  13514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13515. isKnowKey = TRUE;
  13516. }
  13517. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13518. {
  13519. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13521. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13522. {
  13523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13524. }
  13525. else
  13526. {
  13527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13528. }
  13529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13530. isKnowKey = TRUE;
  13531. }
  13532. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13533. {
  13534. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13537. {
  13538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13539. }
  13540. else
  13541. {
  13542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13543. }
  13544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13545. isKnowKey = TRUE;
  13546. }
  13547. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13548. {
  13549. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13552. {
  13553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13554. }
  13555. else
  13556. {
  13557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13558. }
  13559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13560. isKnowKey = TRUE;
  13561. }
  13562. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13563. {
  13564. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13566. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13567. {
  13568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13569. }
  13570. else
  13571. {
  13572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13573. }
  13574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13575. isKnowKey = TRUE;
  13576. }
  13577. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13578. {
  13579. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13581. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13582. {
  13583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13584. }
  13585. else
  13586. {
  13587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13588. }
  13589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13590. isKnowKey = TRUE;
  13591. }
  13592. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13593. {
  13594. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13597. {
  13598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13599. }
  13600. else
  13601. {
  13602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13603. }
  13604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13605. isKnowKey = TRUE;
  13606. }
  13607. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13608. {
  13609. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13612. {
  13613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13614. }
  13615. else
  13616. {
  13617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13618. }
  13619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13620. isKnowKey = TRUE;
  13621. }
  13622. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13623. {
  13624. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13626. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13627. {
  13628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13629. }
  13630. else
  13631. {
  13632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13633. }
  13634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13635. isKnowKey = TRUE;
  13636. }
  13637. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13638. {
  13639. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13642. {
  13643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13644. }
  13645. else
  13646. {
  13647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13648. }
  13649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13650. isKnowKey = TRUE;
  13651. }
  13652. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13653. {
  13654. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13657. {
  13658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13659. }
  13660. else
  13661. {
  13662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13663. }
  13664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13665. isKnowKey = TRUE;
  13666. }
  13667. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13668. {
  13669. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13672. {
  13673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13674. }
  13675. else
  13676. {
  13677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13678. }
  13679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13680. isKnowKey = TRUE;
  13681. }
  13682. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13683. {
  13684. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13687. {
  13688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13689. }
  13690. else
  13691. {
  13692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13693. }
  13694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13695. isKnowKey = TRUE;
  13696. }
  13697. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13698. {
  13699. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13702. {
  13703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13704. }
  13705. else
  13706. {
  13707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13708. }
  13709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13710. isKnowKey = TRUE;
  13711. }
  13712. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13713. {
  13714. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13716. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13717. {
  13718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13719. }
  13720. else
  13721. {
  13722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13723. }
  13724. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13726. isKnowKey = TRUE;
  13727. }
  13728. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13729. {
  13730. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13733. {
  13734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13735. }
  13736. else
  13737. {
  13738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13739. }
  13740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13741. isKnowKey = TRUE;
  13742. }
  13743. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13744. {
  13745. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13748. {
  13749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13750. }
  13751. else
  13752. {
  13753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13754. }
  13755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13756. isKnowKey = TRUE;
  13757. }
  13758. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13759. {
  13760. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13762. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13763. {
  13764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13765. }
  13766. else
  13767. {
  13768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13769. }
  13770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13771. isKnowKey = TRUE;
  13772. }
  13773. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13774. {
  13775. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13778. {
  13779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13780. }
  13781. else
  13782. {
  13783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13784. }
  13785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13786. isKnowKey = TRUE;
  13787. }
  13788. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13789. {
  13790. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13792. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13793. {
  13794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13795. }
  13796. else
  13797. {
  13798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13799. }
  13800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13801. isKnowKey = TRUE;
  13802. }
  13803. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13804. {
  13805. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13808. {
  13809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13810. }
  13811. else
  13812. {
  13813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13814. }
  13815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13816. isKnowKey = TRUE;
  13817. }
  13818. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13819. {
  13820. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13823. {
  13824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13825. }
  13826. else
  13827. {
  13828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13829. }
  13830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13831. isKnowKey = TRUE;
  13832. }
  13833. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13834. {
  13835. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13838. {
  13839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13840. }
  13841. else
  13842. {
  13843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13844. }
  13845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13846. isKnowKey = TRUE;
  13847. }
  13848. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13849. {
  13850. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13853. {
  13854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13855. }
  13856. else
  13857. {
  13858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13859. }
  13860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13861. isKnowKey = TRUE;
  13862. }
  13863. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13864. {
  13865. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13868. {
  13869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13870. }
  13871. else
  13872. {
  13873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13874. }
  13875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13876. isKnowKey = TRUE;
  13877. }
  13878. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13879. {
  13880. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13883. {
  13884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13885. }
  13886. else
  13887. {
  13888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13889. }
  13890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13891. isKnowKey = TRUE;
  13892. }
  13893. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13894. {
  13895. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13898. {
  13899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13900. }
  13901. else
  13902. {
  13903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13904. }
  13905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13906. isKnowKey = TRUE;
  13907. }
  13908. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13909. {
  13910. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13913. {
  13914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13915. }
  13916. else
  13917. {
  13918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13919. }
  13920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13921. isKnowKey = TRUE;
  13922. }
  13923. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13924. {
  13925. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13928. {
  13929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13930. }
  13931. else
  13932. {
  13933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13934. }
  13935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13936. isKnowKey = TRUE;
  13937. }
  13938. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13939. {
  13940. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13942. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13943. {
  13944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13945. }
  13946. else
  13947. {
  13948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13949. }
  13950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13951. isKnowKey = TRUE;
  13952. }
  13953. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13954. {
  13955. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13958. {
  13959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13960. }
  13961. else
  13962. {
  13963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13964. }
  13965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13966. isKnowKey = TRUE;
  13967. }
  13968. /*
  13969. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13970. {
  13971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13974. {
  13975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13976. }
  13977. else
  13978. {
  13979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13980. }
  13981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13982. isKnowKey = TRUE;
  13983. }*/
  13984. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13985. {
  13986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13989. {
  13990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13991. }
  13992. else
  13993. {
  13994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13995. }
  13996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13997. isKnowKey = TRUE;
  13998. }
  13999. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14000. {
  14001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14004. {
  14005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14006. }
  14007. else
  14008. {
  14009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14010. }
  14011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14012. isKnowKey = TRUE;
  14013. }
  14014. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14015. {
  14016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14019. {
  14020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14021. }
  14022. else
  14023. {
  14024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14025. }
  14026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14027. isKnowKey = TRUE;
  14028. }
  14029. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14030. {
  14031. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14034. {
  14035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14036. }
  14037. else
  14038. {
  14039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14040. }
  14041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14042. isKnowKey = TRUE;
  14043. }
  14044. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14045. {
  14046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14049. {
  14050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14051. }
  14052. else
  14053. {
  14054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14055. }
  14056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14057. isKnowKey = TRUE;
  14058. }
  14059. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14060. {
  14061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14064. {
  14065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14066. }
  14067. else
  14068. {
  14069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14070. }
  14071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14072. isKnowKey = TRUE;
  14073. }
  14074. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14075. {
  14076. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14079. {
  14080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14081. }
  14082. else
  14083. {
  14084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14085. }
  14086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14087. isKnowKey = TRUE;
  14088. }
  14089. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14090. {
  14091. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14094. {
  14095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14096. }
  14097. else
  14098. {
  14099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14100. }
  14101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14102. isKnowKey = TRUE;
  14103. }
  14104. #if 1
  14105. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14106. {
  14107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14109. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14110. {
  14111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14112. }
  14113. else
  14114. {
  14115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14116. }
  14117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14118. isKnowKey = TRUE;
  14119. }
  14120. #endif
  14121. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14122. {
  14123. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14125. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14126. {
  14127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14128. }
  14129. else
  14130. {
  14131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14132. }
  14133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14134. isKnowKey = TRUE;
  14135. }
  14136. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14137. {
  14138. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14140. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14141. {
  14142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14143. }
  14144. else
  14145. {
  14146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14147. }
  14148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14149. isKnowKey = TRUE;
  14150. }
  14151. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14152. {
  14153. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14155. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14156. {
  14157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14158. }
  14159. else
  14160. {
  14161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14162. }
  14163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14164. isKnowKey = TRUE;
  14165. }
  14166. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14167. {
  14168. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14170. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14171. {
  14172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14173. }
  14174. else
  14175. {
  14176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14177. }
  14178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14179. isKnowKey = TRUE;
  14180. }
  14181. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14182. {
  14183. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14185. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14186. {
  14187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14188. }
  14189. else
  14190. {
  14191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14192. }
  14193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14194. isKnowKey = TRUE;
  14195. }
  14196. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14197. {
  14198. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14200. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14201. {
  14202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14203. }
  14204. else
  14205. {
  14206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14207. }
  14208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14209. isKnowKey = TRUE;
  14210. }
  14211. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14212. {
  14213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14215. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14216. {
  14217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14218. }
  14219. else
  14220. {
  14221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14222. }
  14223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14224. isKnowKey = TRUE;
  14225. }
  14226. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14227. {
  14228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14230. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14231. {
  14232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14233. }
  14234. else
  14235. {
  14236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14237. }
  14238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14239. isKnowKey = TRUE;
  14240. }
  14241. //=========================================================
  14242. if(!isEmpty && !isKnowKey)
  14243. {
  14244. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14245. strcpy(unknownkey[UnknownKeynum], keyReq);
  14246. UnknownKeynum = UnknownKeynum + 1;
  14247. }
  14248. }
  14249. void processUnkownKey(void)
  14250. {
  14251. DEBUG_INFO("processUnkownKey...\n");
  14252. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14253. for(int index=0; index < UnknownKeynum; index++)
  14254. {
  14255. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14256. {
  14257. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14258. }
  14259. }
  14260. }
  14261. int setKeyValue(char *key, char *value)
  14262. {
  14263. int isSuccess = NotSupported;
  14264. int check_ascii=0;
  14265. char str[256]={0};
  14266. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14267. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14268. {
  14269. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14271. {
  14272. strcpy(str, (const char*)value);
  14273. for(int i = 0; str[i]; i++){
  14274. str[i] = tolower(str[i]);
  14275. }
  14276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14277. isSuccess = ConfigurationStatus_Accepted;
  14278. }
  14279. else
  14280. {
  14281. isSuccess = ConfigurationStatus_Rejected;
  14282. }
  14283. }
  14284. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14285. {
  14286. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14287. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14288. {
  14289. strcpy(str, (const char*)value);
  14290. for(int i = 0; str[i]; i++){
  14291. str[i] = tolower(str[i]);
  14292. }
  14293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14294. isSuccess = ConfigurationStatus_Accepted;
  14295. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14296. }
  14297. else
  14298. {
  14299. isSuccess = ConfigurationStatus_Rejected;
  14300. }
  14301. }
  14302. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14303. {
  14304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14305. {
  14306. strcpy(str, (const char*)value);
  14307. for(int i = 0; str[i]; i++)
  14308. {
  14309. str[i] = tolower(str[i]);
  14310. }
  14311. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14313. isSuccess = ConfigurationStatus_Accepted;
  14314. }
  14315. else
  14316. {
  14317. isSuccess = ConfigurationStatus_Rejected;
  14318. }
  14319. }
  14320. if(strcmp(key, "BlinkRepeat") == 0)
  14321. {
  14322. //Charger.BlinkRepeat = Integer.parseInt(value);
  14323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14324. {
  14325. check_ascii = value[0];
  14326. if( (check_ascii < 48) || (check_ascii > 57) )
  14327. {
  14328. isSuccess = ConfigurationStatus_Rejected;
  14329. }
  14330. else
  14331. {
  14332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14333. isSuccess = ConfigurationStatus_Accepted;
  14334. }
  14335. }
  14336. else
  14337. {
  14338. isSuccess = ConfigurationStatus_Rejected;
  14339. }
  14340. }
  14341. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14342. {
  14343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14344. {
  14345. check_ascii = value[0];
  14346. if( (check_ascii < 48) || (check_ascii > 57) )
  14347. {
  14348. isSuccess = ConfigurationStatus_Rejected;
  14349. }
  14350. else
  14351. {
  14352. if((atoi(value) == 0) || (atoi(value) >= 10))
  14353. {
  14354. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14356. isSuccess = ConfigurationStatus_Accepted;
  14357. }
  14358. else
  14359. isSuccess = ConfigurationStatus_Rejected;
  14360. }
  14361. }
  14362. else
  14363. {
  14364. isSuccess = ConfigurationStatus_Rejected;
  14365. }
  14366. }
  14367. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14368. {
  14369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14370. {
  14371. check_ascii = value[0];
  14372. if( (check_ascii < 48) || (check_ascii > 57) )
  14373. {
  14374. isSuccess = ConfigurationStatus_Rejected;
  14375. }
  14376. else
  14377. {
  14378. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14380. isSuccess = ConfigurationStatus_Accepted;
  14381. }
  14382. }
  14383. else
  14384. {
  14385. isSuccess = ConfigurationStatus_Rejected;
  14386. }
  14387. }
  14388. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14389. {
  14390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14391. {
  14392. check_ascii = value[0];
  14393. if( (check_ascii < 48) || (check_ascii > 57) )
  14394. {
  14395. isSuccess = ConfigurationStatus_Rejected;
  14396. }
  14397. else
  14398. {
  14399. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14401. isSuccess = ConfigurationStatus_Accepted;
  14402. }
  14403. }
  14404. else
  14405. {
  14406. isSuccess = ConfigurationStatus_Rejected;
  14407. }
  14408. }
  14409. if(strcmp(key, "HeartbeatInterval") == 0)
  14410. {
  14411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14412. {
  14413. check_ascii = value[0];
  14414. if( (check_ascii < 48) || (check_ascii > 57) )
  14415. {
  14416. isSuccess = ConfigurationStatus_Rejected;
  14417. }
  14418. else
  14419. {
  14420. if((atoi(value) == 0) || (atoi(value) >= 10))
  14421. {
  14422. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14424. HeartBeatWaitTime = atoi(value);
  14425. isSuccess = ConfigurationStatus_Accepted;
  14426. }
  14427. else
  14428. {
  14429. isSuccess = ConfigurationStatus_Rejected;
  14430. }
  14431. }
  14432. }
  14433. else
  14434. {
  14435. isSuccess = ConfigurationStatus_Rejected;
  14436. }
  14437. }
  14438. if(strcmp(key, "LightIntensity") == 0)
  14439. {
  14440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14441. {
  14442. check_ascii = value[0];
  14443. if( (check_ascii < 48) || (check_ascii > 57) )
  14444. {
  14445. isSuccess = ConfigurationStatus_Rejected;
  14446. }
  14447. else
  14448. {
  14449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14450. isSuccess = ConfigurationStatus_Accepted;
  14451. }
  14452. }
  14453. else
  14454. {
  14455. isSuccess = ConfigurationStatus_Rejected;
  14456. }
  14457. }
  14458. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14459. {
  14460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14461. {
  14462. strcpy(str, (const char*)value);
  14463. for(int i = 0; str[i]; i++)
  14464. {
  14465. str[i] = tolower(str[i]);
  14466. }
  14467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14468. isSuccess = ConfigurationStatus_Accepted;
  14469. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14470. }
  14471. else
  14472. {
  14473. isSuccess = ConfigurationStatus_Rejected;
  14474. }
  14475. }
  14476. if(strcmp(key, "LocalPreAuthorize") == 0)
  14477. {
  14478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14479. {
  14480. strcpy(str, (const char*)value);
  14481. for(int i = 0; str[i]; i++)
  14482. {
  14483. str[i] = tolower(str[i]);
  14484. }
  14485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14486. isSuccess = ConfigurationStatus_Accepted;
  14487. }
  14488. else
  14489. {
  14490. isSuccess = ConfigurationStatus_Rejected;
  14491. }
  14492. }
  14493. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14494. {
  14495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14496. {
  14497. check_ascii = value[0];
  14498. if( (check_ascii < 48) || (check_ascii > 57) )
  14499. {
  14500. isSuccess = ConfigurationStatus_Rejected;
  14501. }
  14502. else
  14503. {
  14504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14505. isSuccess = ConfigurationStatus_Accepted;
  14506. }
  14507. }
  14508. else
  14509. {
  14510. isSuccess = ConfigurationStatus_Rejected;
  14511. }
  14512. }
  14513. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14514. {
  14515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14516. {
  14517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14518. isSuccess = ConfigurationStatus_Accepted;
  14519. }
  14520. else
  14521. {
  14522. isSuccess = ConfigurationStatus_Rejected;
  14523. }
  14524. }
  14525. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14526. {
  14527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14528. {
  14529. check_ascii = value[0];
  14530. if( (check_ascii < 48) || (check_ascii > 57) )
  14531. {
  14532. isSuccess = ConfigurationStatus_Rejected;
  14533. }
  14534. else
  14535. {
  14536. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14538. isSuccess = ConfigurationStatus_Accepted;
  14539. }
  14540. }
  14541. else
  14542. {
  14543. isSuccess = ConfigurationStatus_Rejected;
  14544. }
  14545. }
  14546. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14547. {
  14548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14549. {
  14550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14551. isSuccess = ConfigurationStatus_Accepted;
  14552. }
  14553. else
  14554. {
  14555. isSuccess = ConfigurationStatus_Rejected;
  14556. }
  14557. }
  14558. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14559. {
  14560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14561. {
  14562. check_ascii = value[0];
  14563. if( (check_ascii < 48) || (check_ascii > 57) )
  14564. {
  14565. isSuccess = ConfigurationStatus_Rejected;
  14566. }
  14567. else
  14568. {
  14569. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14571. isSuccess = ConfigurationStatus_Accepted;
  14572. }
  14573. }
  14574. else
  14575. {
  14576. isSuccess = ConfigurationStatus_Rejected;
  14577. }
  14578. }
  14579. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14580. {
  14581. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14582. {
  14583. check_ascii = value[0];
  14584. if( (check_ascii < 48) || (check_ascii > 57) )
  14585. {
  14586. isSuccess = ConfigurationStatus_Rejected;
  14587. }
  14588. else
  14589. {
  14590. if((atoi(value) == 0) || (atoi(value) >= 10))
  14591. {
  14592. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14594. isSuccess = ConfigurationStatus_Accepted;
  14595. }
  14596. else
  14597. {
  14598. isSuccess = ConfigurationStatus_Rejected;
  14599. }
  14600. }
  14601. }
  14602. else
  14603. {
  14604. isSuccess = ConfigurationStatus_Rejected;
  14605. }
  14606. }
  14607. if(strcmp(key, "MinimumStatusDuration") == 0)
  14608. {
  14609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14610. {
  14611. check_ascii = value[0];
  14612. if( (check_ascii < 48) || (check_ascii > 57) )
  14613. {
  14614. isSuccess = ConfigurationStatus_Rejected;
  14615. }
  14616. else
  14617. {
  14618. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14619. {
  14620. isSuccess = ConfigurationStatus_Rejected;
  14621. }
  14622. else
  14623. {
  14624. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14626. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14627. isSuccess = ConfigurationStatus_Accepted;
  14628. }
  14629. }
  14630. }
  14631. else
  14632. {
  14633. isSuccess = ConfigurationStatus_Rejected;
  14634. }
  14635. }
  14636. if(strcmp(key, "NumberOfConnectors") == 0)
  14637. {
  14638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14639. {
  14640. check_ascii = value[0];
  14641. if( (check_ascii < 48) || (check_ascii > 57) )
  14642. {
  14643. isSuccess = ConfigurationStatus_Rejected;
  14644. }
  14645. else
  14646. {
  14647. //Charger.ResetRetries = Integer.parseInt(value);
  14648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14649. isSuccess = ConfigurationStatus_Accepted;
  14650. }
  14651. }
  14652. else
  14653. {
  14654. isSuccess = ConfigurationStatus_Rejected;
  14655. }
  14656. }
  14657. if(strcmp(key, "ResetRetries") == 0)
  14658. {
  14659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14660. {
  14661. check_ascii = value[0];
  14662. if( (check_ascii < 48) || (check_ascii > 57) )
  14663. {
  14664. isSuccess = ConfigurationStatus_Rejected;
  14665. }
  14666. else
  14667. {
  14668. //Charger.ResetRetries = Integer.parseInt(value);
  14669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14670. isSuccess = ConfigurationStatus_Accepted;
  14671. }
  14672. }
  14673. else
  14674. {
  14675. isSuccess = ConfigurationStatus_Rejected;
  14676. }
  14677. }
  14678. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14679. {
  14680. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14681. {
  14682. strcpy(str, (const char*)value);
  14683. for(int i = 0; str[i]; i++)
  14684. {
  14685. str[i] = tolower(str[i]);
  14686. }
  14687. if(strcmp(str, "notapplicable")== 0)
  14688. {
  14689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14690. isSuccess = ConfigurationStatus_Accepted;
  14691. }
  14692. else if(strcmp(str, "unknown")== 0)
  14693. {
  14694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14695. isSuccess = ConfigurationStatus_Accepted;
  14696. }
  14697. else if(strcmp(str, "rst")== 0)
  14698. {
  14699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14700. isSuccess = ConfigurationStatus_Accepted;
  14701. }
  14702. else if(strcmp(str, "rts")== 0)
  14703. {
  14704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14705. isSuccess = ConfigurationStatus_Accepted;
  14706. }
  14707. else if(strcmp(str, "srt")== 0)
  14708. {
  14709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14710. isSuccess = ConfigurationStatus_Accepted;
  14711. }
  14712. else if(strcmp(str, "str")== 0)
  14713. {
  14714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14715. isSuccess = ConfigurationStatus_Accepted;
  14716. }
  14717. else if(strcmp(str, "trs")== 0)
  14718. {
  14719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14720. isSuccess = ConfigurationStatus_Accepted;
  14721. }
  14722. else if(strcmp(str, "tsr")== 0)
  14723. {
  14724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14725. isSuccess = ConfigurationStatus_Accepted;
  14726. }
  14727. else
  14728. {
  14729. isSuccess = ConfigurationStatus_Rejected;
  14730. }
  14731. }
  14732. else
  14733. {
  14734. isSuccess = ConfigurationStatus_Rejected;
  14735. }
  14736. }
  14737. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14738. {
  14739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14740. {
  14741. check_ascii = value[0];
  14742. if( (check_ascii < 48) || (check_ascii > 57) )
  14743. {
  14744. isSuccess = ConfigurationStatus_Rejected;
  14745. }
  14746. else
  14747. {
  14748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14749. isSuccess = ConfigurationStatus_Accepted;
  14750. }
  14751. }
  14752. else
  14753. {
  14754. isSuccess = ConfigurationStatus_Rejected;
  14755. }
  14756. }
  14757. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14758. {
  14759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14760. {
  14761. strcpy(str, (const char*)value);
  14762. for(int i = 0; str[i]; i++)
  14763. {
  14764. str[i] = tolower(str[i]);
  14765. }
  14766. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14768. isSuccess = ConfigurationStatus_Accepted;
  14769. }
  14770. else
  14771. {
  14772. isSuccess = ConfigurationStatus_Rejected;
  14773. }
  14774. }
  14775. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14776. {
  14777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14778. {
  14779. strcpy(str, (const char*)value);
  14780. for(int i = 0; str[i]; i++)
  14781. {
  14782. str[i] = tolower(str[i]);
  14783. }
  14784. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14786. isSuccess = ConfigurationStatus_Accepted;
  14787. }
  14788. else
  14789. {
  14790. isSuccess = ConfigurationStatus_Rejected;
  14791. }
  14792. }
  14793. if(strcmp(key, "StopTxnAlignedData") == 0)
  14794. {
  14795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14796. {
  14797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14798. isSuccess = ConfigurationStatus_Accepted;
  14799. }
  14800. else
  14801. {
  14802. isSuccess = ConfigurationStatus_Rejected;
  14803. }
  14804. }
  14805. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14806. {
  14807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14808. {
  14809. check_ascii = value[0];
  14810. if( (check_ascii < 48) || (check_ascii > 57) )
  14811. {
  14812. isSuccess = ConfigurationStatus_Rejected;
  14813. }
  14814. else
  14815. {
  14816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14817. isSuccess = ConfigurationStatus_Accepted;
  14818. }
  14819. }
  14820. else
  14821. {
  14822. isSuccess = ConfigurationStatus_Rejected;
  14823. }
  14824. }
  14825. if(strcmp(key, "StopTxnSampledData") == 0)
  14826. {
  14827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14828. {
  14829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14830. isSuccess = ConfigurationStatus_Accepted;
  14831. }
  14832. else
  14833. {
  14834. isSuccess = ConfigurationStatus_Rejected;
  14835. }
  14836. }
  14837. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14838. {
  14839. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14840. {
  14841. check_ascii = value[0];
  14842. if( (check_ascii < 48) || (check_ascii > 57) )
  14843. {
  14844. isSuccess = ConfigurationStatus_Rejected;
  14845. }
  14846. else
  14847. {
  14848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14849. isSuccess = ConfigurationStatus_Accepted;
  14850. }
  14851. }
  14852. else
  14853. {
  14854. isSuccess = ConfigurationStatus_Rejected;
  14855. }
  14856. }
  14857. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14858. {
  14859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14860. {
  14861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14862. isSuccess = ConfigurationStatus_Accepted;
  14863. }
  14864. else
  14865. {
  14866. isSuccess = ConfigurationStatus_Rejected;
  14867. }
  14868. }
  14869. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14870. {
  14871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14872. {
  14873. check_ascii = value[0];
  14874. if( (check_ascii < 48) || (check_ascii > 57) )
  14875. {
  14876. isSuccess = ConfigurationStatus_Rejected;
  14877. }
  14878. else
  14879. {
  14880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14881. isSuccess = ConfigurationStatus_Accepted;
  14882. }
  14883. }
  14884. else
  14885. {
  14886. isSuccess = ConfigurationStatus_Rejected;
  14887. }
  14888. }
  14889. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14890. {
  14891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14892. {
  14893. check_ascii = value[0];
  14894. if( (check_ascii < 48) || (check_ascii > 57) )
  14895. {
  14896. isSuccess = ConfigurationStatus_Rejected;
  14897. }
  14898. else
  14899. {
  14900. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14902. TransactionMessageAttemptsValue = atoi(value);
  14903. isSuccess = ConfigurationStatus_Accepted;
  14904. }
  14905. }
  14906. else
  14907. {
  14908. isSuccess = ConfigurationStatus_Rejected;
  14909. }
  14910. }
  14911. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14912. {
  14913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14914. {
  14915. check_ascii = value[0];
  14916. if( (check_ascii < 48) || (check_ascii > 57) )
  14917. {
  14918. isSuccess = ConfigurationStatus_Rejected;
  14919. }
  14920. else
  14921. {
  14922. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14924. TransactionMessageRetryIntervalValue = atoi(value);
  14925. isSuccess = ConfigurationStatus_Accepted;
  14926. }
  14927. }
  14928. else
  14929. {
  14930. isSuccess = ConfigurationStatus_Rejected;
  14931. }
  14932. }
  14933. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14934. {
  14935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14936. {
  14937. strcpy(str, (const char*)value);
  14938. for(int i = 0; str[i]; i++)
  14939. {
  14940. str[i] = tolower(str[i]);
  14941. }
  14942. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14944. isSuccess = ConfigurationStatus_Accepted;
  14945. }
  14946. else
  14947. {
  14948. isSuccess = ConfigurationStatus_Rejected;
  14949. }
  14950. }
  14951. if(strcmp(key, "WebSocketPingInterval") == 0)
  14952. {
  14953. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14954. {
  14955. check_ascii = value[0];
  14956. if( (check_ascii < 48) || (check_ascii > 57) )
  14957. {
  14958. isSuccess = ConfigurationStatus_Rejected;
  14959. }
  14960. else
  14961. {
  14962. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14963. isSuccess = ConfigurationStatus_Accepted;
  14964. }
  14965. }
  14966. else
  14967. {
  14968. isSuccess = ConfigurationStatus_Rejected;
  14969. }
  14970. }
  14971. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14972. {
  14973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14974. {
  14975. strcpy(str, (const char*)value);
  14976. for(int i = 0; str[i]; i++)
  14977. {
  14978. str[i] = tolower(str[i]);
  14979. }
  14980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14981. isSuccess = ConfigurationStatus_Accepted;
  14982. }
  14983. else
  14984. {
  14985. isSuccess = ConfigurationStatus_Rejected;
  14986. }
  14987. }
  14988. if(strcmp(key, "AuthorizationKey") == 0)
  14989. {
  14990. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14991. {
  14992. strcpy(str, (const char*)value);
  14993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14994. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14995. isSuccess = ConfigurationStatus_Accepted;
  14996. }
  14997. else
  14998. {
  14999. isSuccess = ConfigurationStatus_Rejected;
  15000. }
  15001. }
  15002. if(strcmp(key, "SecurityProfile") == 0)
  15003. {
  15004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15005. {
  15006. check_ascii = value[0];
  15007. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15008. {
  15009. isSuccess = ConfigurationStatus_Rejected;
  15010. }
  15011. else if(check_ascii == 0x33)
  15012. {
  15013. isSuccess = NotSupported;
  15014. }
  15015. else
  15016. {
  15017. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15018. {
  15019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15020. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15021. isSuccess = ConfigurationStatus_Accepted;
  15022. }
  15023. else
  15024. isSuccess = ConfigurationStatus_Rejected;
  15025. }
  15026. }
  15027. else
  15028. {
  15029. isSuccess = ConfigurationStatus_Rejected;
  15030. }
  15031. }
  15032. if(strcmp(key, "DefaultPrice") == 0)
  15033. {
  15034. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15035. {
  15036. strcpy(str, (const char*)value);
  15037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15038. isSuccess = ConfigurationStatus_Accepted;
  15039. }
  15040. else
  15041. {
  15042. isSuccess = ConfigurationStatus_Rejected;
  15043. }
  15044. }
  15045. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15046. {
  15047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15048. {
  15049. strcpy(str, (const char*)value);
  15050. for(int i = 0; str[i]; i++)
  15051. {
  15052. str[i] = tolower(str[i]);
  15053. }
  15054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15055. isSuccess = ConfigurationStatus_Accepted;
  15056. }
  15057. else
  15058. {
  15059. isSuccess = ConfigurationStatus_Rejected;
  15060. }
  15061. }
  15062. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15063. {
  15064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15065. {
  15066. strcpy(str, (const char*)value);
  15067. for(int i = 0; str[i]; i++)
  15068. {
  15069. str[i] = tolower(str[i]);
  15070. }
  15071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15072. isSuccess = ConfigurationStatus_Accepted;
  15073. }
  15074. else
  15075. {
  15076. isSuccess = ConfigurationStatus_Rejected;
  15077. }
  15078. }
  15079. if(strcmp(key, "TimeOffset") == 0)
  15080. {
  15081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15082. {
  15083. strcpy(str, (const char*)value);
  15084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15085. isSuccess = ConfigurationStatus_Accepted;
  15086. }
  15087. else
  15088. {
  15089. isSuccess = ConfigurationStatus_Rejected;
  15090. }
  15091. }
  15092. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15093. {
  15094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15095. {
  15096. strcpy(str, (const char*)value);
  15097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15098. isSuccess = ConfigurationStatus_Accepted;
  15099. }
  15100. else
  15101. {
  15102. isSuccess = ConfigurationStatus_Rejected;
  15103. }
  15104. }
  15105. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15106. {
  15107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15108. {
  15109. strcpy(str, (const char*)value);
  15110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15111. isSuccess = ConfigurationStatus_Accepted;
  15112. }
  15113. else
  15114. {
  15115. isSuccess = ConfigurationStatus_Rejected;
  15116. }
  15117. }
  15118. #if 0
  15119. //For OCPP Test Case
  15120. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15121. {
  15122. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15123. {
  15124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  15125. isSuccess = ConfigurationStatus_Accepted;
  15126. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15127. }
  15128. else
  15129. {
  15130. isSuccess = ConfigurationStatus_Rejected;
  15131. }
  15132. }
  15133. #endif
  15134. #if 1
  15135. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15136. {
  15137. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15138. {
  15139. strcpy(str, (const char*)value);
  15140. for(int i = 0; str[i]; i++)
  15141. {
  15142. str[i] = tolower(str[i]);
  15143. }
  15144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15145. isSuccess = ConfigurationStatus_Accepted;
  15146. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15147. }
  15148. else
  15149. {
  15150. isSuccess = ConfigurationStatus_Rejected;
  15151. }
  15152. }
  15153. #endif
  15154. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15155. {
  15156. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15157. {
  15158. check_ascii = value[0];
  15159. if( (check_ascii < 48) || (check_ascii > 57) )
  15160. {
  15161. isSuccess = ConfigurationStatus_Rejected;
  15162. }
  15163. else
  15164. {
  15165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15166. isSuccess = ConfigurationStatus_Accepted;
  15167. }
  15168. }
  15169. else
  15170. {
  15171. isSuccess = ConfigurationStatus_Rejected;
  15172. }
  15173. }
  15174. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15175. {
  15176. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15177. {
  15178. check_ascii = value[0];
  15179. if( (check_ascii < 48) || (check_ascii > 57) )
  15180. {
  15181. isSuccess = ConfigurationStatus_Rejected;
  15182. }
  15183. else
  15184. {
  15185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15186. isSuccess = ConfigurationStatus_Accepted;
  15187. }
  15188. }
  15189. else
  15190. {
  15191. isSuccess = ConfigurationStatus_Rejected;
  15192. }
  15193. }
  15194. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15195. {
  15196. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15197. {
  15198. strcpy(str, (const char*)value);
  15199. for(int i = 0; str[i]; i++)
  15200. {
  15201. str[i] = tolower(str[i]);
  15202. }
  15203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15204. isSuccess = ConfigurationStatus_Accepted;
  15205. }
  15206. else
  15207. {
  15208. isSuccess = ConfigurationStatus_Rejected;
  15209. }
  15210. }
  15211. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15212. {
  15213. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15214. {
  15215. check_ascii = value[0];
  15216. if( (check_ascii < 48) || (check_ascii > 57) )
  15217. {
  15218. isSuccess = ConfigurationStatus_Rejected;
  15219. }
  15220. else
  15221. {
  15222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15223. isSuccess = ConfigurationStatus_Accepted;
  15224. }
  15225. }
  15226. else
  15227. {
  15228. isSuccess = ConfigurationStatus_Rejected;
  15229. }
  15230. }
  15231. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15232. {
  15233. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15234. {
  15235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15236. isSuccess = ConfigurationStatus_Accepted;
  15237. }
  15238. else
  15239. {
  15240. isSuccess = ConfigurationStatus_Rejected;
  15241. }
  15242. }
  15243. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15244. {
  15245. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15246. {
  15247. check_ascii = value[0];
  15248. if( (check_ascii < 48) || (check_ascii > 57) )
  15249. {
  15250. isSuccess = ConfigurationStatus_Rejected;
  15251. }
  15252. else
  15253. {
  15254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15255. isSuccess = ConfigurationStatus_Accepted;
  15256. }
  15257. }
  15258. else
  15259. {
  15260. isSuccess = ConfigurationStatus_Rejected;
  15261. }
  15262. }
  15263. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15264. {
  15265. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15266. {
  15267. strcpy(str, (const char*)value);
  15268. for(int i = 0; str[i]; i++)
  15269. {
  15270. str[i] = tolower(str[i]);
  15271. }
  15272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15273. isSuccess = ConfigurationStatus_Accepted;
  15274. }
  15275. else
  15276. {
  15277. isSuccess = ConfigurationStatus_Rejected;
  15278. }
  15279. }
  15280. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15281. {
  15282. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15283. {
  15284. check_ascii = value[0];
  15285. if( (check_ascii < 48) || (check_ascii > 57) )
  15286. {
  15287. isSuccess = ConfigurationStatus_Rejected;
  15288. }
  15289. else
  15290. {
  15291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15292. isSuccess = ConfigurationStatus_Accepted;
  15293. }
  15294. }
  15295. else
  15296. {
  15297. isSuccess = ConfigurationStatus_Rejected;
  15298. }
  15299. }
  15300. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15301. return isSuccess;
  15302. }
  15303. int TransactionMessageAttemptsGet(void)
  15304. {
  15305. return TransactionMessageAttemptsValue;
  15306. }
  15307. int FirstHeartBeatResponse(void)
  15308. {
  15309. return FirstHeartBeat;
  15310. }
  15311. int TransactionMessageRetryIntervalGet(void)
  15312. {
  15313. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15314. }
  15315. int ReadHttpStatus(int sock)
  15316. {
  15317. //char c;
  15318. char buff[1024]="",*ptr=buff+1;
  15319. int bytes_received, status;
  15320. DEBUG_INFO("Begin Response ..\n");
  15321. while((bytes_received = recv(sock, ptr, 1, 0))){
  15322. if(bytes_received==-1){
  15323. perror("ReadHttpStatus");
  15324. exit(1);
  15325. }
  15326. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15327. ptr++;
  15328. }
  15329. *ptr=0;
  15330. ptr=buff+1;
  15331. sscanf(ptr,"%*s %d ", &status);
  15332. DEBUG_INFO("%s\n",ptr);
  15333. DEBUG_INFO("status=%d\n",status);
  15334. DEBUG_INFO("End Response ..\n");
  15335. return (bytes_received>0)?status:0;
  15336. }
  15337. //the only filed that it parsed is 'Content-Length'
  15338. int ParseHeader(int sock)
  15339. {
  15340. //char c;
  15341. char buff[1024]="",*ptr=buff+4;
  15342. int bytes_received;
  15343. DEBUG_INFO("Begin HEADER ..\n");
  15344. while((bytes_received = recv(sock, ptr, 1, 0))){
  15345. if(bytes_received==-1){
  15346. perror("Parse Header");
  15347. exit(1);
  15348. }
  15349. if(
  15350. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15351. (ptr[-1]=='\r') && (*ptr=='\n' )
  15352. ) break;
  15353. ptr++;
  15354. }
  15355. *ptr=0;
  15356. ptr=buff+4;
  15357. //printf("%s",ptr);
  15358. if(bytes_received){
  15359. ptr=strstr(ptr,"Content-Length:");
  15360. if(ptr){
  15361. sscanf(ptr,"%*s %d",&bytes_received);
  15362. }else
  15363. bytes_received=-1; //unknown size
  15364. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15365. }
  15366. DEBUG_INFO("End HEADER ..\n");
  15367. return bytes_received ;
  15368. }
  15369. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15370. {
  15371. int result = TRUE;
  15372. char rmFileCmd[100]={0};
  15373. char FilePath[100]={0};
  15374. char ftpbuf[200];
  15375. int systemresult;
  15376. sprintf(FilePath,"/mnt/%s",filename);
  15377. system("ping 8.8.8.8 &");
  15378. if((access(FilePath,F_OK))!=-1)
  15379. {
  15380. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15381. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15382. system(rmFileCmd);
  15383. }
  15384. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15385. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15386. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15387. systemresult = system(ftpbuf);
  15388. if(systemresult != 0)
  15389. {
  15390. DEBUG_INFO("http DownLoad error!\n");
  15391. result = FALSE;
  15392. }
  15393. system("pkill ping");
  15394. return result;
  15395. }
  15396. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15397. {
  15398. int result = TRUE;
  15399. char rmFileCmd[100]={0};
  15400. char FilePath[100]={0};
  15401. char ftpbuf[200];
  15402. int systemresult;
  15403. sprintf(FilePath,"/mnt/%s",filename);
  15404. system("ping 8.8.8.8 &");
  15405. if((access(FilePath,F_OK))!=-1)
  15406. {
  15407. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15408. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15409. system(rmFileCmd);
  15410. }
  15411. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15412. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15413. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15414. systemresult = system(ftpbuf);
  15415. if(systemresult != 0)
  15416. {
  15417. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15418. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15419. systemresult = system(ftpbuf);
  15420. if(systemresult != 0)
  15421. {
  15422. DEBUG_WARN("wget error!\n");
  15423. result = FALSE;
  15424. }
  15425. }
  15426. system("pkill ping");
  15427. return result;
  15428. }
  15429. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15430. {
  15431. char rmFileCmd[100]={0};
  15432. char FilePath[100]={0};
  15433. char buf[512];
  15434. int systemresult = 0;
  15435. //DEBUG_INFO("filename=%s\n",filename);
  15436. //DEBUG_INFO("url=%s\n",url);
  15437. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15438. if((access(FilePath,F_OK))!=-1)
  15439. {
  15440. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15441. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15442. system(rmFileCmd);
  15443. }
  15444. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15445. if(fp == NULL)
  15446. {
  15447. DEBUG_INFO("log is NULL\n");
  15448. return FALSE;
  15449. }
  15450. else
  15451. {
  15452. fprintf(fp, "%s\n", url);
  15453. fprintf(fp, "%s\n", filename);
  15454. fclose(fp);
  15455. }
  15456. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15457. if(phpFP == NULL)
  15458. {
  15459. DEBUG_INFO("PHP upload fail.\n");
  15460. return FALSE;
  15461. }
  15462. else
  15463. {
  15464. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15465. {
  15466. if(strstr(buf, "result") != NULL)
  15467. {
  15468. sscanf(buf, "result: %d", &systemresult);
  15469. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15470. }
  15471. }
  15472. pclose(phpFP);
  15473. }
  15474. if(systemresult != 1)
  15475. {
  15476. DEBUG_INFO("HTTP upload error!\n");
  15477. return FALSE;
  15478. }
  15479. return TRUE;
  15480. }
  15481. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15482. {
  15483. struct hostent* server;
  15484. char *IPbuffer;
  15485. char ftpbuf[200];
  15486. int systemresult;
  15487. // To retrieve host information
  15488. server = gethostbyname(location);
  15489. // To convert an Internet network
  15490. // address into ASCII string
  15491. IPbuffer = inet_ntoa(*((struct in_addr*)
  15492. server->h_addr_list[0]));
  15493. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15494. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15495. /* format : ftpput -u username -p passwd IP target source*/
  15496. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15497. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15498. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15499. systemresult = system(ftpbuf);
  15500. DEBUG_INFO("systemresult=%d\n",systemresult);
  15501. if(systemresult != 0)
  15502. {
  15503. DEBUG_INFO("ftpput error!\n");
  15504. return FALSE;
  15505. }
  15506. return TRUE;
  15507. }
  15508. int GetOcppServerURL()
  15509. {
  15510. int result = FALSE;
  15511. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15512. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15513. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15514. struct yuarel url;
  15515. char urlStr[512];
  15516. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15517. {
  15518. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15519. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15520. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15521. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15522. if(yuarel_parse(&url, urlStr) != -1)
  15523. {
  15524. sprintf(OcppProtocol, "%s", url.scheme);
  15525. sprintf(OcppHost, "%s", url.host);
  15526. if(url.path == NULL)
  15527. OcppTempPath[0] = '\0';
  15528. else
  15529. {
  15530. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15531. {
  15532. sprintf(OcppTempPath, "%s/", url.path);
  15533. }
  15534. else
  15535. {
  15536. sprintf(OcppTempPath, "%s", url.path);
  15537. }
  15538. }
  15539. if(url.port == 0)
  15540. {
  15541. if(strcmp(OcppProtocol, "wss") == 0)
  15542. OcppPort = 443;
  15543. else
  15544. OcppPort = 80;
  15545. }
  15546. else
  15547. OcppPort = url.port;
  15548. result = TRUE;
  15549. }
  15550. }
  15551. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15552. {
  15553. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15554. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15555. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15556. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15557. if(yuarel_parse(&url, urlStr) != -1)
  15558. {
  15559. sprintf(OcppProtocol, "%s", url.scheme);
  15560. sprintf(OcppHost, "%s", url.host);
  15561. if(url.path == NULL)
  15562. OcppTempPath[0] = '\0';
  15563. else
  15564. sprintf(OcppTempPath, "%s", url.path);
  15565. if(url.port == 0)
  15566. {
  15567. if(strcmp(OcppProtocol, "wss") == 0)
  15568. OcppPort = 443;
  15569. else
  15570. OcppPort = 80;
  15571. }
  15572. else
  15573. OcppPort = url.port;
  15574. result = TRUE;
  15575. }
  15576. }
  15577. else
  15578. {
  15579. strcpy(OcppHost,"");
  15580. }
  15581. return result;
  15582. }
  15583. int GetOcppPath()
  15584. {
  15585. int result = FALSE;
  15586. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15587. {
  15588. if(OcppTempPath == NULL)
  15589. {
  15590. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15591. }
  15592. else
  15593. {
  15594. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15595. }
  15596. result = TRUE;
  15597. goto End;
  15598. }
  15599. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15600. {
  15601. if(OcppTempPath == NULL)
  15602. {
  15603. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15604. }
  15605. else
  15606. {
  15607. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15608. }
  15609. result = TRUE;
  15610. goto End;
  15611. }
  15612. else
  15613. {
  15614. strcpy(OcppPath,"");
  15615. }
  15616. End:
  15617. return result;
  15618. }
  15619. int GetOcppPort()
  15620. {
  15621. return OcppPort;
  15622. }
  15623. int GetOcppConnStatus(void)
  15624. {
  15625. return ShmOCPP16Data->OcppConnStatus;
  15626. }
  15627. void SetOcppConnStatus(uint8_t status)
  15628. {
  15629. ShmOCPP16Data->OcppConnStatus = status;
  15630. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15631. }
  15632. int GetHeartBeatWithNOResponse(void)
  15633. {
  15634. return HeartBeatWithNOResponse;
  15635. }
  15636. void SetHeartBeatWithNOResponse(void)
  15637. {
  15638. HeartBeatWithNOResponse = 0;
  15639. }
  15640. void GetStartTransactionIdTag(int gun_index)
  15641. {
  15642. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15643. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15644. }
  15645. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15646. {
  15647. char ch;
  15648. FILE *fptr1;
  15649. int temptransactionId;
  15650. char str[100]={0};
  15651. temptransactionId = 0;
  15652. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15653. {
  15654. DEBUG_INFO("IdTag is empty.\n");
  15655. return temptransactionId;
  15656. }
  15657. /*------ Read the file ----------------*/
  15658. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15659. if (!fptr1)
  15660. {
  15661. DEBUG_INFO("QueueTransactionId file open error.\n");
  15662. //printf(" File not found or unable to open the input file!!\n");
  15663. return temptransactionId;
  15664. }
  15665. ch=fgetc(fptr1);
  15666. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15667. rewind(fptr1);
  15668. if(ch!=EOF)
  15669. {
  15670. // printf("%c",ch);
  15671. while (fgets(str, 100, fptr1) != NULL)
  15672. {
  15673. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15674. if(str[0]=='\0')
  15675. {
  15676. break;
  15677. }
  15678. char *revbuf[8] = {0}; // Variable store string split
  15679. int num = 0;// Quantity after string split
  15680. DEBUG_INFO("Transaction queue data= %s\n", str);
  15681. splitstring(str,",",revbuf,&num); // String split
  15682. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15683. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15684. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15685. DEBUG_INFO("------------------------------\n");
  15686. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15687. {
  15688. if(isStopTransaction)
  15689. {
  15690. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15691. {
  15692. temptransactionId = atoi(revbuf[2]);
  15693. //break;
  15694. }
  15695. }
  15696. else
  15697. {
  15698. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15699. {
  15700. temptransactionId = atoi(revbuf[2]);
  15701. //break;
  15702. }
  15703. }
  15704. }
  15705. }
  15706. }
  15707. else
  15708. DEBUG_INFO("EOF\n");
  15709. fclose(fptr1);
  15710. /*------- End of reading ---------------*/
  15711. return temptransactionId;
  15712. }
  15713. void SetTransactionIdZero(int transactionId)
  15714. {
  15715. char ch;
  15716. FILE *fptr1, *fptr2;
  15717. int temptransactionId = 0;
  15718. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15719. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15720. if (!fptr1)
  15721. {
  15722. //printf(" File not found or unable to open the input file!!\n");
  15723. return ;
  15724. }
  15725. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15726. if (!fptr2)
  15727. {
  15728. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15729. fclose(fptr1);
  15730. return ;
  15731. }
  15732. ch=fgetc(fptr1);
  15733. rewind(fptr1);
  15734. if(ch!=EOF)
  15735. {
  15736. // copy all contents to the temporary file except the specific line
  15737. while (fgets(str, 100, fptr1) != NULL)
  15738. {
  15739. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15740. if(str[0]=='\0')
  15741. {
  15742. break;
  15743. }
  15744. char *revbuf[8] = {0};
  15745. int num = 0;
  15746. strcpy(strtemp, str);
  15747. splitstring(str,",",revbuf,&num);
  15748. if(revbuf[2][0] != '\0')
  15749. {
  15750. temptransactionId = atoi(revbuf[2]);
  15751. if(transactionId != temptransactionId)
  15752. {
  15753. fprintf(fptr2, "%s\n", strtemp);
  15754. }
  15755. }
  15756. }
  15757. }
  15758. fclose(fptr1);
  15759. fclose(fptr2);
  15760. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15761. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15762. /*------ Read the file ----------------*/
  15763. }
  15764. int InternetDisconnect(void)
  15765. {
  15766. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15767. }
  15768. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15769. void storeTempStopTransaction(int gun_index)
  15770. {
  15771. char guid[37]={0};
  15772. int tempIndex = 0;
  15773. char TempStopTransaction[256];
  15774. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15775. DEBUG_INFO("storeTempStopTransaction...\n");
  15776. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15777. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15778. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15779. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15780. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15781. {
  15782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15783. {
  15784. tempIndex = ((gun_index==2) ? 1: 0);
  15785. }
  15786. else
  15787. {
  15788. tempIndex = gun_index;
  15789. }
  15790. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15791. {
  15792. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15793. {
  15794. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15795. }
  15796. }// END OF CHAdeMO_QUANTITY
  15797. }
  15798. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15799. {
  15800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15801. {
  15802. tempIndex = ((gun_index==2) ? 1: 0);
  15803. }
  15804. else
  15805. {
  15806. tempIndex = gun_index;
  15807. }
  15808. for (int index = 0; index < CCS_QUANTITY; index++)
  15809. {
  15810. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15811. {
  15812. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15813. }
  15814. }// END OF CCS_QUANTITY
  15815. }
  15816. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15817. {
  15818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15819. {
  15820. tempIndex = ((gun_index==2) ? 1: 0);
  15821. }
  15822. else
  15823. {
  15824. tempIndex = gun_index;
  15825. }
  15826. for (int index = 0; index < GB_QUANTITY; index++)
  15827. {
  15828. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15829. {
  15830. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15831. }
  15832. }// END OF GB_QUANTITY
  15833. }
  15834. else if(gunType[gun_index] == GUN_TYPE_DO)
  15835. {
  15836. tempIndex = gun_index;
  15837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15838. {
  15839. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15840. {
  15841. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15842. }
  15843. }
  15844. }
  15845. else
  15846. {
  15847. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15848. {
  15849. tempIndex = 2;
  15850. }
  15851. else
  15852. {
  15853. tempIndex = gun_index;
  15854. }
  15855. for (int index = 0; index < AC_QUANTITY; index++)
  15856. {
  15857. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15858. {
  15859. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15860. }
  15861. }// END OF AC_QUANTITY
  15862. }
  15863. //Stop Transaction Time
  15864. struct timeval tmnow;
  15865. struct tm *tm;
  15866. char buf[28];//, usec_buf[6];
  15867. gettimeofday(&tmnow, NULL);
  15868. time_t t;
  15869. t = time(NULL);
  15870. /*UTC time and date*/
  15871. tm = gmtime(&t);
  15872. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15874. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15876. random_uuid(guid);
  15877. /***********************************transactionData******************************************************/
  15878. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15880. //=================================
  15881. //1. Transaction_Begin
  15882. //=================================
  15883. //============================== Energy.Active.Import.Interval ===========================================
  15884. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15885. {
  15886. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15889. 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*/]);
  15890. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15891. 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))
  15892. {
  15893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15894. }
  15895. else
  15896. {
  15897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15898. }
  15899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15901. }
  15902. //=================================
  15903. //2. Transaction_End
  15904. //=================================
  15905. //2.1====================================== Current.Import L1 ==============================================
  15906. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15907. {
  15908. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15909. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15910. {
  15911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15912. {
  15913. tempIndex = ((gun_index==2) ? 1: 0);
  15914. }
  15915. else
  15916. {
  15917. tempIndex = gun_index;
  15918. }
  15919. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15920. {
  15921. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15922. {
  15923. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15924. }
  15925. }// End of for CHAdeMO_QUANTITY
  15926. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15927. }
  15928. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15929. {
  15930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15931. {
  15932. tempIndex = ((gun_index==2) ? 1: 0);
  15933. }
  15934. else
  15935. {
  15936. tempIndex = gun_index;
  15937. }
  15938. for (int index = 0; index < CCS_QUANTITY; index++)
  15939. {
  15940. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15941. {
  15942. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15943. }
  15944. }// End of for CCS_QUANTITY
  15945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15946. }
  15947. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15948. {
  15949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15950. {
  15951. tempIndex = ((gun_index==2) ? 1: 0);
  15952. }
  15953. else
  15954. {
  15955. tempIndex = gun_index;
  15956. }
  15957. for (int index = 0; index < GB_QUANTITY; index++)
  15958. {
  15959. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15960. {
  15961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15962. }
  15963. }// End of for GB_QUANTITY
  15964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15965. }
  15966. else if(gunType[gun_index] == GUN_TYPE_DO)
  15967. {
  15968. tempIndex = gun_index;
  15969. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15970. {
  15971. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15972. {
  15973. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15974. }
  15975. }
  15976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15977. }
  15978. else
  15979. {
  15980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15981. {
  15982. tempIndex = 2;
  15983. }
  15984. else
  15985. {
  15986. tempIndex = gun_index;
  15987. }
  15988. for (int index = 0; index < AC_QUANTITY; index++)
  15989. {
  15990. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15991. {
  15992. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15993. }
  15994. }// End of for AC_QUANTITY
  15995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15996. }
  15997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16000. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16003. }
  16004. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16005. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16006. {
  16007. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16008. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16009. {
  16010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16011. {
  16012. tempIndex = ((gun_index==2) ? 1: 0);
  16013. }
  16014. else
  16015. {
  16016. tempIndex = gun_index;
  16017. }
  16018. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16019. {
  16020. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16021. {
  16022. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16023. }
  16024. }// END OF CHAdeMO_QUANTITY
  16025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16026. }
  16027. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16028. {
  16029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16030. {
  16031. tempIndex = ((gun_index==2) ? 1: 0);
  16032. }
  16033. else
  16034. {
  16035. tempIndex = gun_index;
  16036. }
  16037. for (int index = 0; index < CCS_QUANTITY; index++)
  16038. {
  16039. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16040. {
  16041. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16042. }
  16043. }// END OF CCS_QUANTITY
  16044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16045. }
  16046. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16047. {
  16048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16049. {
  16050. tempIndex = ((gun_index==2) ? 1: 0);
  16051. }
  16052. else
  16053. {
  16054. tempIndex = gun_index;
  16055. }
  16056. for (int index = 0; index < GB_QUANTITY; index++)
  16057. {
  16058. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16059. {
  16060. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16061. }
  16062. }// END OF GB_QUANTITY
  16063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16064. }
  16065. else if(gunType[gun_index] == GUN_TYPE_DO)
  16066. {
  16067. tempIndex = gun_index;
  16068. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16069. {
  16070. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16071. {
  16072. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16073. }
  16074. }
  16075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16076. }
  16077. else
  16078. {
  16079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16080. {
  16081. tempIndex = 2;
  16082. }
  16083. else
  16084. {
  16085. tempIndex = gun_index;
  16086. }
  16087. for (int index = 0; index < AC_QUANTITY; index++)
  16088. {
  16089. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16090. {
  16091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16092. }
  16093. }// END OF AC_QUANTITY
  16094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16095. }
  16096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16099. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16102. }
  16103. //2.3====================================== Power.Active.Import =========================================
  16104. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16105. {
  16106. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16107. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16108. {
  16109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16110. {
  16111. tempIndex = ((gun_index==2) ? 1: 0);
  16112. }
  16113. else
  16114. {
  16115. tempIndex = gun_index;
  16116. }
  16117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16118. {
  16119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16120. {
  16121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16122. }
  16123. } // End for CHAdeMO_QUANTITY
  16124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16125. }
  16126. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16127. {
  16128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16129. {
  16130. tempIndex = ((gun_index==2) ? 1: 0);
  16131. }
  16132. else
  16133. {
  16134. tempIndex = gun_index;
  16135. }
  16136. for (int index = 0; index < CCS_QUANTITY; index++)
  16137. {
  16138. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16139. {
  16140. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16141. }
  16142. } // END for CCS_QUANTITY
  16143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16144. }
  16145. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16146. {
  16147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16148. {
  16149. tempIndex = ((gun_index==2) ? 1: 0);
  16150. }
  16151. else
  16152. {
  16153. tempIndex = gun_index;
  16154. }
  16155. for (int index = 0; index < GB_QUANTITY; index++)
  16156. {
  16157. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16158. {
  16159. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16160. }
  16161. }// END for GB_QUANTITY
  16162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16163. }
  16164. else if(gunType[gun_index] == GUN_TYPE_DO)
  16165. {
  16166. tempIndex = gun_index;
  16167. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16168. {
  16169. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16170. {
  16171. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16172. }
  16173. }
  16174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16175. }
  16176. else
  16177. {
  16178. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16179. {
  16180. tempIndex = 2;
  16181. }
  16182. else
  16183. {
  16184. tempIndex = gun_index;
  16185. }
  16186. for (int index = 0; index < AC_QUANTITY; index++)
  16187. {
  16188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16189. {
  16190. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16191. }
  16192. } // END for AC_QUANTITY
  16193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16194. }
  16195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16198. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16201. }
  16202. //2.4====================================== Voltage L1 ====================================================
  16203. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16204. {
  16205. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16206. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16207. {
  16208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16209. {
  16210. tempIndex = ((gun_index==2) ? 1: 0);
  16211. }
  16212. else
  16213. {
  16214. tempIndex = gun_index;
  16215. }
  16216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16217. {
  16218. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16219. {
  16220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16221. }
  16222. } // END OF FOR CHAdeMO_QUANTITY
  16223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16224. }
  16225. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16226. {
  16227. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16228. {
  16229. tempIndex = ((gun_index==2) ? 1: 0);
  16230. }
  16231. else
  16232. {
  16233. tempIndex = gun_index;
  16234. }
  16235. for (int index = 0; index < CCS_QUANTITY; index++)
  16236. {
  16237. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16238. {
  16239. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16240. }
  16241. } // END OF FOR CCS_QUANTITY
  16242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16243. }
  16244. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16245. {
  16246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16247. {
  16248. tempIndex = ((gun_index==2) ? 1: 0);
  16249. }
  16250. else
  16251. {
  16252. tempIndex = gun_index;
  16253. }
  16254. for (int index = 0; index < GB_QUANTITY; index++)
  16255. {
  16256. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16257. {
  16258. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16259. }
  16260. } // END OF FOR GB_QUANTITY
  16261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16262. }
  16263. else if(gunType[gun_index] == GUN_TYPE_DO)
  16264. {
  16265. tempIndex = gun_index;
  16266. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16267. {
  16268. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16269. {
  16270. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16271. }
  16272. }
  16273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16274. }
  16275. else
  16276. {
  16277. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16278. {
  16279. tempIndex = 2;
  16280. }
  16281. else
  16282. {
  16283. tempIndex = gun_index;
  16284. }
  16285. for (int index = 0; index < AC_QUANTITY; index++)
  16286. {
  16287. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16288. {
  16289. 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
  16290. }
  16291. } // END OF FOR AC_QUANTITY
  16292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16293. }
  16294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16297. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16300. }
  16301. //2.5============================================== End SoC =========================================================
  16302. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16303. {
  16304. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16305. 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))
  16306. {
  16307. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16308. {
  16309. tempIndex = ((gun_index==2) ? 1: 0);
  16310. }
  16311. else
  16312. {
  16313. tempIndex = gun_index;
  16314. }
  16315. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16316. {
  16317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16318. {
  16319. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16320. {
  16321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16322. }
  16323. }
  16324. }
  16325. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16326. {
  16327. for (int index = 0; index < CCS_QUANTITY; index++)
  16328. {
  16329. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16330. {
  16331. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16332. }
  16333. }
  16334. }
  16335. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16336. {
  16337. for (int index = 0; index < GB_QUANTITY; index++)
  16338. {
  16339. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16340. {
  16341. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16342. }
  16343. }
  16344. }
  16345. else if(gunType[gun_index] == GUN_TYPE_DO)
  16346. {
  16347. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16348. {
  16349. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16350. {
  16351. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16352. }
  16353. }
  16354. }
  16355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16361. } // END FOR DC CASE
  16362. }
  16363. //2.6====================================== Current.Import L2 ==============================================
  16364. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16365. {
  16366. // AC 3 phase L2 current
  16367. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16368. {
  16369. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16370. {
  16371. tempIndex = 2;
  16372. }
  16373. else
  16374. {
  16375. tempIndex = gun_index;
  16376. }
  16377. for (int index = 0; index < AC_QUANTITY; index++)
  16378. {
  16379. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16380. {
  16381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16382. }
  16383. }// End of for AC_QUANTITY
  16384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16385. }
  16386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16391. }
  16392. //2.7====================================== Current.Import L3 ==============================================
  16393. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16394. {
  16395. // AC 3 phase L3 current
  16396. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16397. {
  16398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16399. {
  16400. tempIndex = 2;
  16401. }
  16402. else
  16403. {
  16404. tempIndex = gun_index;
  16405. }
  16406. for (int index = 0; index < AC_QUANTITY; index++)
  16407. {
  16408. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16409. {
  16410. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16411. }
  16412. }// End of for AC_QUANTITY
  16413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16414. }
  16415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16420. }
  16421. //2.9====================================== Voltage L2 ====================================================
  16422. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16423. {
  16424. // AC 3 phase L2 volatge
  16425. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16426. {
  16427. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16428. {
  16429. tempIndex = 2;
  16430. }
  16431. else
  16432. {
  16433. tempIndex = gun_index;
  16434. }
  16435. for (int index = 0; index < AC_QUANTITY; index++)
  16436. {
  16437. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16438. {
  16439. 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
  16440. }
  16441. } // END OF FOR AC_QUANTITY
  16442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16443. }
  16444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16449. }
  16450. //2.10====================================== Voltage L3 ====================================================
  16451. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16452. {
  16453. // AC 3 phase L3 volatge
  16454. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16455. {
  16456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16457. {
  16458. tempIndex = 2;
  16459. }
  16460. else
  16461. {
  16462. tempIndex = gun_index;
  16463. }
  16464. for (int index = 0; index < AC_QUANTITY; index++)
  16465. {
  16466. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16467. {
  16468. 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
  16469. }
  16470. } // END OF FOR AC_QUANTITY
  16471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16472. }
  16473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16478. }
  16479. //====================== Start SoC ================================
  16480. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16481. {
  16482. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16483. 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))
  16484. {
  16485. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16486. {
  16487. tempIndex = ((gun_index==2) ? 1: 0);
  16488. }
  16489. else
  16490. {
  16491. tempIndex = gun_index;
  16492. }
  16493. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16494. {
  16495. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16496. {
  16497. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16498. {
  16499. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16500. }
  16501. }
  16502. }
  16503. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16504. {
  16505. for (int index = 0; index < CCS_QUANTITY; index++)
  16506. {
  16507. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16508. {
  16509. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16510. }
  16511. }
  16512. }
  16513. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16514. {
  16515. for (int index = 0; index < GB_QUANTITY; index++)
  16516. {
  16517. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16518. {
  16519. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16520. }
  16521. }
  16522. }
  16523. else if(gunType[gun_index] == GUN_TYPE_DO)
  16524. {
  16525. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16526. {
  16527. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16528. {
  16529. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16530. }
  16531. }
  16532. }
  16533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16539. } // END FOR DC CASE
  16540. }
  16541. //======================================== Message create ==============================================
  16542. json_object *StopTransaction = json_object_new_object();
  16543. json_object *transactionDatas = json_object_new_array();
  16544. json_object *sampledValues = json_object_new_array();
  16545. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16546. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16547. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16548. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16549. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16550. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16551. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16552. {
  16553. json_object *transactionData = json_object_new_object();
  16554. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16555. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16556. {
  16557. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16558. {
  16559. json_object *sampledValue = json_object_new_object();
  16560. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16561. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16562. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16563. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16564. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16565. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16566. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16567. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16568. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16569. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16570. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16571. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16572. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16573. json_object_array_add(sampledValues, sampledValue);
  16574. }
  16575. }
  16576. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16577. json_object_array_add(transactionDatas, transactionData);
  16578. }
  16579. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16580. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16581. ,MESSAGE_TYPE_CALL
  16582. ,guid
  16583. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16584. json_object_put(StopTransaction);
  16585. // Check File "TempStopTransaction" Exist
  16586. if((access(TempStopTransaction,F_OK))!=-1)
  16587. {
  16588. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16589. fclose(fopen(TempStopTransaction, "w"));
  16590. }
  16591. else
  16592. {
  16593. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16594. FILE *log = fopen(TempStopTransaction, "w+");
  16595. if(log == NULL)
  16596. {
  16597. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16598. return ;
  16599. }
  16600. else
  16601. {
  16602. fclose(log);
  16603. }
  16604. }
  16605. //Add TempStopTransaction | Update TempStopTransaction
  16606. // open file for writing
  16607. FILE *outfile;
  16608. outfile = fopen (TempStopTransaction, "a");
  16609. //DEBUG_INFO("data = %s\n", queuedata);
  16610. fputs(queuedata, outfile);
  16611. fputs("\n", outfile);
  16612. fclose (outfile);
  16613. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16614. }
  16615. void checkTempStopTransaction(int gun_index)
  16616. {
  16617. FILE *fptr1;
  16618. char ch;
  16619. char str[QUEUE_MESSAGE_LENGTH]={0};
  16620. char guid[37]={0};
  16621. char tempdata[65]={0};
  16622. char connectorStr[2]={0};
  16623. char TempStopTransaction[256];
  16624. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16625. fptr1 = fopen(TempStopTransaction, "r");
  16626. //TempStopTransaction格式: 槍號,StopTransaction封包
  16627. if (!fptr1)
  16628. {
  16629. //printf(" File not found or unable to open the input file!!\n");
  16630. return ;
  16631. }
  16632. ch=fgetc(fptr1);
  16633. //printf(" Now the content of the file %s is : \n",fname);
  16634. rewind(fptr1);
  16635. if(ch!=EOF)
  16636. {
  16637. // copy all contents to the temporary file except the specific line
  16638. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16639. {
  16640. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16641. if(str[0]=='\0')
  16642. {
  16643. break;
  16644. }
  16645. //TempStopTransaction格式: 槍號,StopTransaction封包
  16646. strncpy(connectorStr, str, 1);
  16647. if(atoi(connectorStr) != (gun_index+1))
  16648. {
  16649. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16650. fclose(fptr1);
  16651. return ;
  16652. }
  16653. //random_uuid(guid);
  16654. strncpy(guid, str+6, 36); //copy guid
  16655. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16656. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16657. {
  16658. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16659. }
  16660. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16661. OCPP_insert_transaction_msg(NO, str);
  16662. memset(str,0,ARRAY_SIZE(str));
  16663. }
  16664. }
  16665. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16666. fclose(fptr1);
  16667. remove(TempStopTransaction); // remove the original file
  16668. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16669. }
  16670. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16671. {
  16672. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16673. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16674. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16675. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16676. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16677. }
  16678. int GetWebSocketPingInterval(void)
  16679. {
  16680. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16681. }
  16682. int GetServerSign(void)
  16683. {
  16684. return server_sign;
  16685. }
  16686. uint8_t GetOcppSecurityProfile()
  16687. {
  16688. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16689. }
  16690. void GetOcppChargerBoxId(uint8_t *data)
  16691. {
  16692. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16693. }
  16694. void GetOcppSecurityPassword(uint8_t *data)
  16695. {
  16696. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16697. }
  16698. void SetOcppVersion(uint8_t *version)
  16699. {
  16700. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16701. DEBUG_INFO("ocpp version: %s\n", version);
  16702. if(strstr((char*)version, "ocpp1.6") != NULL)
  16703. {
  16704. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16705. }
  16706. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16707. {
  16708. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16709. system("pkill OcppBackend");
  16710. }
  16711. }
  16712. void SetServerSign(int value)
  16713. {
  16714. server_sign = value;
  16715. }
  16716. int GetBootNotificationInterval(void)
  16717. {
  16718. return BootNotificationInterval;
  16719. }
  16720. int GetInternetConn(void)
  16721. {
  16722. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16723. }
  16724. int GetBackendConnectionTimeout(void)
  16725. {
  16726. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16727. }
  16728. int isConnectorInitMode(int gun_index)
  16729. {
  16730. int tempIndex = 0;
  16731. int result = TRUE;
  16732. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16733. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16734. {
  16735. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16736. {
  16737. tempIndex = ((gun_index==2) ? 1: 0);
  16738. }
  16739. else
  16740. {
  16741. tempIndex = gun_index;
  16742. }
  16743. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16744. {
  16745. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16746. {
  16747. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16748. } //end of the same index
  16749. }//end of for CHAdeMO_QUANTITY
  16750. }
  16751. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16752. {
  16753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16754. {
  16755. tempIndex = ((gun_index==2) ? 1: 0);
  16756. }
  16757. else
  16758. {
  16759. tempIndex = gun_index;
  16760. }
  16761. for (int index = 0; index < CCS_QUANTITY; index++)
  16762. {
  16763. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16764. {
  16765. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16766. } //end of the same index
  16767. } // end of for CCS_QUANTITY
  16768. }
  16769. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16770. {
  16771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16772. {
  16773. tempIndex = ((gun_index==2) ? 1: 0);
  16774. }
  16775. else
  16776. {
  16777. tempIndex = gun_index;
  16778. }
  16779. for (int index = 0; index < GB_QUANTITY; index++)
  16780. {
  16781. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16782. {
  16783. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16784. } //end of the same index
  16785. } // end of for GB_QUANTITY
  16786. }
  16787. else if(gunType[gun_index] == GUN_TYPE_DO)
  16788. {
  16789. tempIndex = gun_index;
  16790. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16791. {
  16792. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16793. {
  16794. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16795. } //end of the same index
  16796. }
  16797. }
  16798. else
  16799. {
  16800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16801. {
  16802. tempIndex = 2;
  16803. }
  16804. else
  16805. {
  16806. tempIndex = gun_index;
  16807. }
  16808. for (int index = 0; index < AC_QUANTITY; index++)
  16809. {
  16810. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16811. {
  16812. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16813. }//end of the same index
  16814. }//end of for AC_QUANTITY
  16815. }
  16816. return result;
  16817. }
  16818. void refreshProcDogTimer()
  16819. {
  16820. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16821. }
  16822. void InitialSystemValue(void)
  16823. {
  16824. int connectorIndex = 0;
  16825. //int valueASCII = 0;
  16826. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16827. gunTotalNumber=0;
  16828. SystemInitial = 0;
  16829. locallistVersion=0;
  16830. BootNotificationInterval = 0;
  16831. authorizeRetryTimes = 0;
  16832. GunStatusInterval = 10;
  16833. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16834. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16835. //Hear Beat
  16836. HeartBeatWithNOResponse = 0;
  16837. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16838. FirstHeartBeat = 0;
  16839. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16840. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16841. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16842. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16843. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16844. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16845. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16846. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16847. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16848. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16849. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16850. memset(gunType, 0, ARRAY_SIZE(gunType));
  16851. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16852. {
  16853. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16854. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16855. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16856. {
  16857. // DO series
  16858. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16859. {
  16860. SystemInitial = SystemInitial + 1;
  16861. gunTotalNumber = gunTotalNumber + 1;
  16862. gunType[connectorIndex] = GUN_TYPE_DO;
  16863. connectorIndex = connectorIndex + 1;
  16864. }
  16865. }
  16866. else
  16867. {
  16868. // DM, DW, DS series
  16869. //check connector / socket type (index: 8, 9, 10)
  16870. for(int index=7; index <10 ; index++)
  16871. {
  16872. if(index != 8)
  16873. {
  16874. // DC Connector
  16875. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16876. {
  16877. SystemInitial = SystemInitial + 1;
  16878. gunTotalNumber = gunTotalNumber + 1;
  16879. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16880. connectorIndex = connectorIndex + 1;
  16881. }
  16882. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16883. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16884. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16885. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16886. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16887. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16888. {
  16889. SystemInitial = SystemInitial + 1;
  16890. gunTotalNumber = gunTotalNumber + 1;
  16891. gunType[connectorIndex] = GUN_TYPE_CCS;
  16892. connectorIndex = connectorIndex + 1;
  16893. }
  16894. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16895. {
  16896. SystemInitial = SystemInitial + 1;
  16897. gunTotalNumber = gunTotalNumber + 1;
  16898. gunType[connectorIndex] = GUN_TYPE_GBT;
  16899. connectorIndex = connectorIndex + 1;
  16900. }
  16901. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16902. {
  16903. SystemInitial = SystemInitial + 1;
  16904. gunTotalNumber = gunTotalNumber + 1;
  16905. gunType[connectorIndex] = GUN_TYPE_DO;
  16906. connectorIndex = connectorIndex + 1;
  16907. }
  16908. }
  16909. else
  16910. {
  16911. // AC Connector
  16912. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16913. {
  16914. SystemInitial = SystemInitial + 1;
  16915. gunTotalNumber = gunTotalNumber + 1;
  16916. gunType[connectorIndex] = GUN_TYPE_AC;
  16917. connectorIndex = connectorIndex + 1;
  16918. }
  16919. }
  16920. }
  16921. }
  16922. //DEBUG_INFO("DC ...\n");
  16923. }
  16924. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16925. {
  16926. //check connector / socket type (index: 8, 9, 10)
  16927. for(int index=7; index <10 ; index++)
  16928. {
  16929. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16930. {
  16931. SystemInitial = SystemInitial + 1;
  16932. gunTotalNumber = gunTotalNumber + 1;
  16933. gunType[connectorIndex] = GUN_TYPE_AC;
  16934. connectorIndex = connectorIndex + 1;
  16935. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16936. }
  16937. }
  16938. }
  16939. //Status && ConnectorPlugIn Setting
  16940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16941. {
  16942. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16943. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16944. }
  16945. for (int index = 0; index < CCS_QUANTITY; index++)
  16946. {
  16947. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16948. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16949. }
  16950. for (int index = 0; index < GB_QUANTITY; index++)
  16951. {
  16952. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16953. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16954. }
  16955. for (int index = 0; index < AC_QUANTITY; index++)
  16956. {
  16957. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16958. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16959. }
  16960. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16961. {
  16962. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16963. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16964. }
  16965. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16966. {
  16967. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16968. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16969. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16970. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16971. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16972. }
  16973. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16974. clientTime.Heartbeat=time((time_t*)NULL);
  16975. sleep(1);
  16976. }
  16977. void LWS_Send(char *str)
  16978. {
  16979. //=====================================================
  16980. // Check InternetConn 0: disconnected, 1: connected
  16981. //====================================================
  16982. if(GetOcppConnStatus() == 0)
  16983. {
  16984. DEBUG_INFO("offline now !!!\n");
  16985. return;
  16986. }
  16987. // Only disable isWebsocketSendable operation initiated by charger
  16988. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16989. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16990. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16991. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16992. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16993. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16994. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16995. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16996. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16997. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16998. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16999. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17000. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17001. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17002. {
  17003. isWebsocketSendable = 0;
  17004. }
  17005. pthread_mutex_lock(&lock_send);
  17006. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17007. sprintf((char *)SendBuffer, "%s", str);
  17008. SendBufLen = strlen(str);
  17009. pthread_mutex_unlock(&lock_send);
  17010. lws_callback_on_writable(wsi_client);
  17011. //lws_service(context, 0);
  17012. //sleep(1);
  17013. }
  17014. void LWS_SendNow(char *str)
  17015. {
  17016. //=====================================================
  17017. // Check InternetConn 0: disconnected, 1: connected
  17018. //====================================================
  17019. if(GetOcppConnStatus() == 0)
  17020. {
  17021. DEBUG_INFO("offline now !!!\n");
  17022. return;
  17023. }
  17024. // Only disable isWebsocketSendable operation initiated by charger
  17025. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17026. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17027. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17028. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17029. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17030. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17031. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17032. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17033. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17034. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17035. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17036. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17037. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17038. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17039. {
  17040. isWebsocketSendable = 0;
  17041. }
  17042. pthread_mutex_lock(&lock_send);
  17043. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17044. sprintf((char *)SendBuffer, "%s", str);
  17045. SendBufLen = strlen(str);
  17046. pthread_mutex_unlock(&lock_send);
  17047. lws_callback_on_writable(wsi_client);
  17048. lws_service(context, 0);
  17049. //sleep(1);
  17050. }