MessageHandler.c 850 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551
  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. while(getline(&line, &len, fp) != -1)
  1274. {
  1275. json_object *obj = NULL;
  1276. obj = json_tokener_parse(line);
  1277. if(is_error(obj))
  1278. {
  1279. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1280. }
  1281. else
  1282. {
  1283. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1284. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1285. )
  1286. {
  1287. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1288. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1289. )
  1290. {
  1291. struct tm tmFrom, tmTo;
  1292. struct timeb tbFrom, tbTo;
  1293. 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) &&
  1294. (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))
  1295. {
  1296. tmFrom.tm_year -= 1900;
  1297. tmFrom.tm_mon -= 1;
  1298. tbFrom.time = mktime(&tmFrom);
  1299. tmTo.tm_year -= 1900;
  1300. tmTo.tm_mon -= 1;
  1301. tbTo.time = mktime(&tmTo);
  1302. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1303. {
  1304. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1305. {
  1306. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1307. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1308. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1309. }
  1310. maxProfile.ChargingProfileId = -1;
  1311. maxProfile.StackLevel = -1;
  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. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1407. {
  1408. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1409. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1410. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1411. }
  1412. maxProfile.ChargingProfileId = -1;
  1413. maxProfile.StackLevel = -1;
  1414. if(maxProfile.ChargingProfileId == -1)
  1415. DEBUG_INFO("MaxProfile found.\n");
  1416. else
  1417. DEBUG_INFO("MaxProfile updated.\n");
  1418. // Required item
  1419. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1420. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1421. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1422. if(isUnitA)
  1423. {
  1424. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1425. 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++)
  1426. {
  1427. 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"));
  1428. 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?
  1429. 3:
  1430. 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")));
  1431. 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")));
  1432. }
  1433. }
  1434. else
  1435. {
  1436. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1437. 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++)
  1438. {
  1439. 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"));
  1440. 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?
  1441. 3:
  1442. 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")));
  1443. 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));
  1444. }
  1445. }
  1446. // Optional item
  1447. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1448. {
  1449. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1450. }
  1451. else
  1452. {
  1453. sprintf((char*)maxProfile.ValidFrom, " ");
  1454. }
  1455. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1456. {
  1457. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.ValidTo, " ");
  1462. }
  1463. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1464. {
  1465. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1466. }
  1467. else
  1468. {
  1469. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1470. }
  1471. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1472. {
  1473. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1474. }
  1475. else
  1476. {
  1477. maxProfile.TransactionId = -1;
  1478. }
  1479. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1480. {
  1481. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1482. }
  1483. else
  1484. {
  1485. maxProfile.ChargingSchedule.Duration = 86400;
  1486. }
  1487. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1488. {
  1489. 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")));
  1490. }
  1491. else
  1492. {
  1493. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1494. }
  1495. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1496. {
  1497. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1498. }
  1499. else
  1500. {
  1501. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1502. }
  1503. }
  1504. }
  1505. }
  1506. json_object_put(obj);
  1507. }
  1508. fclose(fp);
  1509. /*
  1510. if(maxProfile.ChargingProfileId !=-1)
  1511. {
  1512. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1513. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1514. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1515. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1516. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1517. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1518. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1519. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1520. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1521. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1522. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1523. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1524. {
  1525. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1526. {
  1527. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1528. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1529. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1530. }
  1531. }
  1532. }
  1533. else
  1534. DEBUG_INFO("MaxProfile not found.\n");
  1535. DEBUG_INFO("------------------------------------\n");*/
  1536. }
  1537. if(maxProfile.ChargingProfileId != -1)
  1538. {
  1539. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1540. {
  1541. if(maxProfile.ChargingSchedule.Duration != -1)
  1542. {
  1543. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1544. 0:
  1545. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1546. }
  1547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1548. {
  1549. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1550. {
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1552. 0:
  1553. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1554. if(idxPeriod > 0)
  1555. {
  1556. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1557. {
  1558. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1559. }
  1560. }
  1561. }
  1562. }
  1563. }
  1564. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1565. {
  1566. if(maxProfile.ChargingSchedule.Duration != -1)
  1567. {
  1568. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1569. }
  1570. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1571. {
  1572. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1573. {
  1574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1575. if(idxPeriod > 0)
  1576. {
  1577. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1578. {
  1579. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. else
  1586. {
  1587. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1588. {
  1589. if(maxProfile.ChargingSchedule.Duration != -1)
  1590. {
  1591. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1592. 0:
  1593. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1594. }
  1595. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1596. {
  1597. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1598. {
  1599. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1600. 0:
  1601. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1602. if(idxPeriod > 0)
  1603. {
  1604. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1605. {
  1606. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1607. }
  1608. }
  1609. }
  1610. }
  1611. }
  1612. else
  1613. {
  1614. if(maxProfile.ChargingSchedule.Duration != -1)
  1615. {
  1616. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1617. 0:
  1618. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1619. }
  1620. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1621. {
  1622. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1623. {
  1624. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1625. 0:
  1626. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1627. if(idxPeriod > 0)
  1628. {
  1629. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1630. {
  1631. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1632. }
  1633. }
  1634. }
  1635. }
  1636. }
  1637. }
  1638. /*
  1639. DEBUG_INFO("MaxProfile after align.\n");
  1640. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1641. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1642. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1643. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1644. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1645. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1646. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1647. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1648. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1649. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1650. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1651. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1652. {
  1653. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1654. {
  1655. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1656. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1657. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1658. }
  1659. }
  1660. DEBUG_INFO("------------------------------------\n");*/
  1661. }
  1662. // Find each profile period quantity
  1663. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1664. {
  1665. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1666. limitMax = idx+1;
  1667. }
  1668. if(maxProfile.ChargingProfileId != -1)
  1669. {
  1670. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1671. {
  1672. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1673. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1674. (maxProfile.ChargingSchedule.Duration > 0))
  1675. {
  1676. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1677. {
  1678. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1679. compositePeriodIdx++;
  1680. }
  1681. else
  1682. {
  1683. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1684. }
  1685. }
  1686. }
  1687. }
  1688. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1689. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1690. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1691. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1692. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1693. {
  1694. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1695. {
  1696. compositeProfile->ChargingProfileId = 1;
  1697. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1698. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1699. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1700. }
  1701. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1702. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1703. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1704. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1705. }
  1706. if(line)
  1707. free(line);
  1708. }
  1709. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1710. {
  1711. FILE *fp;
  1712. char profileFileName[128];
  1713. char *line = NULL;
  1714. size_t len = 0;
  1715. time_t CurrentTime;
  1716. struct tm *tmComposite;
  1717. struct StructChargingProfile maxProfile;
  1718. struct StructChargingProfile defaultTxProfile;
  1719. struct StructChargingProfile txProfile;
  1720. struct StructChargingSchedulePeriod tmpPeriod;
  1721. uint8_t limitMax=0;
  1722. uint8_t limitDef=0;
  1723. uint8_t limitTx=0;
  1724. int compositePeriodIdx = 0;
  1725. CurrentTime = time(NULL);
  1726. tmComposite=localtime(&CurrentTime);
  1727. 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);
  1728. if(isUnitA)
  1729. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1730. else
  1731. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1732. compositeProfile->ChargingSchedule.Duration = durationReq;
  1733. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1734. {
  1735. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1736. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1737. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1738. }
  1739. compositeProfile->ChargingProfileId = 0;
  1740. compositeProfile->StackLevel = 99 ;
  1741. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1742. maxProfile.ChargingProfileId = -1;
  1743. defaultTxProfile.ChargingProfileId = -1;
  1744. txProfile.ChargingProfileId = -1;
  1745. maxProfile.ChargingSchedule.Duration = -1;
  1746. defaultTxProfile.ChargingSchedule.Duration = -1;
  1747. txProfile.ChargingSchedule.Duration = -1;
  1748. system("rm -f /tmp/*.json");
  1749. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1750. /*
  1751. * Search valid charging profile
  1752. */
  1753. //DEBUG_INFO("====================================\n");
  1754. // Search tx profile
  1755. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1756. if((access(profileFileName, F_OK))!=-1)
  1757. {
  1758. fp = fopen(profileFileName, "r");
  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. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1791. {
  1792. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1793. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1794. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1795. }
  1796. txProfile.ChargingProfileId = -1;
  1797. txProfile.StackLevel = -1;
  1798. if(txProfile.ChargingProfileId == -1)
  1799. DEBUG_INFO("TxProfile found.\n");
  1800. else
  1801. DEBUG_INFO("TxProfile updated.\n");
  1802. // Required item
  1803. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1804. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1805. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1806. if(isUnitA)
  1807. {
  1808. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1809. 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++)
  1810. {
  1811. 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"));
  1812. 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?
  1813. 3:
  1814. 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")));
  1815. 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")));
  1816. }
  1817. }
  1818. else
  1819. {
  1820. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1821. 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++)
  1822. {
  1823. 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"));
  1824. 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?
  1825. 3:
  1826. 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")));
  1827. 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));
  1828. }
  1829. }
  1830. // Optional item
  1831. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1832. {
  1833. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1834. }
  1835. else
  1836. {
  1837. sprintf((char*)txProfile.ValidFrom, " ");
  1838. }
  1839. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1840. {
  1841. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1842. }
  1843. else
  1844. {
  1845. sprintf((char*)txProfile.ValidTo, " ");
  1846. }
  1847. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1848. {
  1849. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1850. }
  1851. else
  1852. {
  1853. sprintf((char*)txProfile.RecurrencyKind, " ");
  1854. }
  1855. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1856. {
  1857. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1858. }
  1859. else
  1860. {
  1861. txProfile.TransactionId = -1;
  1862. }
  1863. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1864. {
  1865. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1866. }
  1867. else
  1868. {
  1869. txProfile.ChargingSchedule.Duration = 86400;
  1870. }
  1871. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1872. {
  1873. 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")));
  1874. }
  1875. else
  1876. {
  1877. 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));
  1878. }
  1879. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1880. {
  1881. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1882. }
  1883. else
  1884. {
  1885. txProfile.ChargingSchedule.MinChargingRate = -1;
  1886. }
  1887. }
  1888. }
  1889. }
  1890. else
  1891. {
  1892. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1893. {
  1894. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1895. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1896. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1897. }
  1898. txProfile.ChargingProfileId = -1;
  1899. txProfile.StackLevel = -1;
  1900. if(txProfile.ChargingProfileId == -1)
  1901. DEBUG_INFO("TxProfile found.\n");
  1902. else
  1903. DEBUG_INFO("TxProfile updated.\n");
  1904. // Required item
  1905. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1906. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1907. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1908. if(isUnitA)
  1909. {
  1910. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1911. 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++)
  1912. {
  1913. 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"));
  1914. 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?
  1915. 3:
  1916. 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")));
  1917. 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")));
  1918. }
  1919. }
  1920. else
  1921. {
  1922. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1923. 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++)
  1924. {
  1925. 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"));
  1926. 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?
  1927. 3:
  1928. 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")));
  1929. 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));
  1930. }
  1931. }
  1932. // Optional item
  1933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1934. {
  1935. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1936. }
  1937. else
  1938. {
  1939. sprintf((char*)txProfile.ValidFrom, " ");
  1940. }
  1941. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1942. {
  1943. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1944. }
  1945. else
  1946. {
  1947. sprintf((char*)txProfile.ValidTo, " ");
  1948. }
  1949. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1950. {
  1951. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1952. }
  1953. else
  1954. {
  1955. sprintf((char*)txProfile.RecurrencyKind, " ");
  1956. }
  1957. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1958. {
  1959. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1960. }
  1961. else
  1962. {
  1963. txProfile.TransactionId = -1;
  1964. }
  1965. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1966. {
  1967. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1968. }
  1969. else
  1970. {
  1971. txProfile.ChargingSchedule.Duration = 86400;
  1972. }
  1973. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1974. {
  1975. 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")));
  1976. }
  1977. else
  1978. {
  1979. 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));
  1980. }
  1981. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1982. {
  1983. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1984. }
  1985. else
  1986. {
  1987. txProfile.ChargingSchedule.MinChargingRate = -1;
  1988. }
  1989. }
  1990. }
  1991. }
  1992. json_object_put(obj);
  1993. }
  1994. fclose(fp);
  1995. /*
  1996. if(txProfile.ChargingProfileId != -1)
  1997. {
  1998. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1999. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2000. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2001. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2002. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2003. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2004. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2005. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2006. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2007. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2008. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2009. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2010. {
  2011. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2012. {
  2013. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2014. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2015. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2016. }
  2017. }
  2018. }
  2019. else
  2020. DEBUG_INFO("TxProfile not found.\n");*/
  2021. }
  2022. // Search default tx profile
  2023. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2024. if((access(profileFileName, F_OK))==-1)
  2025. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2026. if((access(profileFileName, F_OK))!=-1)
  2027. {
  2028. fp = fopen(profileFileName, "r");
  2029. while(getline(&line, &len, fp) != -1)
  2030. {
  2031. json_object *obj = NULL;
  2032. obj = json_tokener_parse(line);
  2033. if(is_error(obj))
  2034. {
  2035. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2036. }
  2037. else
  2038. {
  2039. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2040. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2041. )
  2042. {
  2043. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2044. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2045. )
  2046. {
  2047. struct tm tmFrom, tmTo;
  2048. struct timeb tbFrom, tbTo;
  2049. 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) &&
  2050. (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))
  2051. {
  2052. tmFrom.tm_year -= 1900;
  2053. tmFrom.tm_mon -= 1;
  2054. tbFrom.time = mktime(&tmFrom);
  2055. tmTo.tm_year -= 1900;
  2056. tmTo.tm_mon -= 1;
  2057. tbTo.time = mktime(&tmTo);
  2058. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2059. {
  2060. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2061. {
  2062. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2063. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2064. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2065. }
  2066. defaultTxProfile.ChargingProfileId = -1;
  2067. defaultTxProfile.StackLevel = -1;
  2068. if(defaultTxProfile.ChargingProfileId == -1)
  2069. DEBUG_INFO("TxDefaultProfile found.\n");
  2070. else
  2071. DEBUG_INFO("TxDefaultProfile updated.\n");
  2072. // Required item
  2073. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2074. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2075. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2076. if(isUnitA)
  2077. {
  2078. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2079. 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++)
  2080. {
  2081. 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"));
  2082. 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?
  2083. 3:
  2084. 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")));
  2085. 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")));
  2086. }
  2087. }
  2088. else
  2089. {
  2090. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2091. 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++)
  2092. {
  2093. 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"));
  2094. 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?
  2095. 3:
  2096. 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")));
  2097. 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));
  2098. }
  2099. }
  2100. // Optional item
  2101. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2102. {
  2103. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2104. }
  2105. else
  2106. {
  2107. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2108. }
  2109. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2110. {
  2111. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2112. }
  2113. else
  2114. {
  2115. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2116. }
  2117. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2118. {
  2119. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2120. }
  2121. else
  2122. {
  2123. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2124. }
  2125. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2126. {
  2127. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2128. }
  2129. else
  2130. {
  2131. defaultTxProfile.TransactionId = -1;
  2132. }
  2133. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2134. {
  2135. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2136. }
  2137. else
  2138. {
  2139. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2140. }
  2141. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2142. {
  2143. 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")));
  2144. }
  2145. else
  2146. {
  2147. 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));
  2148. }
  2149. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2150. {
  2151. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2152. }
  2153. else
  2154. {
  2155. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2156. }
  2157. }
  2158. }
  2159. }
  2160. else
  2161. {
  2162. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2163. {
  2164. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2165. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2166. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2167. }
  2168. defaultTxProfile.ChargingProfileId = -1;
  2169. defaultTxProfile.StackLevel = -1;
  2170. if(defaultTxProfile.ChargingProfileId == -1)
  2171. DEBUG_INFO("TxDefaultProfile found.\n");
  2172. else
  2173. DEBUG_INFO("TxDefaultProfile updated.\n");
  2174. // Required item
  2175. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2176. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2177. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2178. if(isUnitA)
  2179. {
  2180. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2181. 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++)
  2182. {
  2183. 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"));
  2184. 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?
  2185. 3:
  2186. 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")));
  2187. 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")));
  2188. }
  2189. }
  2190. else
  2191. {
  2192. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2193. 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++)
  2194. {
  2195. 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"));
  2196. 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?
  2197. 3:
  2198. 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")));
  2199. 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));
  2200. }
  2201. }
  2202. // Optional item
  2203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2204. {
  2205. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2206. }
  2207. else
  2208. {
  2209. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2210. }
  2211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2212. {
  2213. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2214. }
  2215. else
  2216. {
  2217. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2218. }
  2219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2220. {
  2221. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2226. }
  2227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2228. {
  2229. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2230. }
  2231. else
  2232. {
  2233. defaultTxProfile.TransactionId = -1;
  2234. }
  2235. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2236. {
  2237. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2238. }
  2239. else
  2240. {
  2241. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2242. }
  2243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2244. {
  2245. 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")));
  2246. }
  2247. else
  2248. {
  2249. 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));
  2250. }
  2251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2252. {
  2253. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2254. }
  2255. else
  2256. {
  2257. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2258. }
  2259. }
  2260. }
  2261. }
  2262. json_object_put(obj);
  2263. }
  2264. fclose(fp);
  2265. /*
  2266. if(defaultTxProfile.ChargingProfileId != -1)
  2267. {
  2268. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2269. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2270. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2271. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2272. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2273. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2274. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2275. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2276. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2277. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2278. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2279. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2280. {
  2281. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2282. {
  2283. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2284. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2285. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2286. }
  2287. }
  2288. }
  2289. else
  2290. DEBUG_INFO("TxDefaultProfile not found.\n");
  2291. DEBUG_INFO("------------------------------------\n");*/
  2292. }
  2293. // Search max profile
  2294. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2295. if((access(profileFileName, F_OK))!=-1)
  2296. {
  2297. fp = fopen(profileFileName, "r");
  2298. while(getline(&line, &len, fp) != -1)
  2299. {
  2300. json_object *obj = NULL;
  2301. obj = json_tokener_parse(line);
  2302. if(is_error(obj))
  2303. {
  2304. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2305. }
  2306. else
  2307. {
  2308. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2309. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2310. )
  2311. {
  2312. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2313. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2314. )
  2315. {
  2316. struct tm tmFrom, tmTo;
  2317. struct timeb tbFrom, tbTo;
  2318. 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) &&
  2319. (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))
  2320. {
  2321. tmFrom.tm_year -= 1900;
  2322. tmFrom.tm_mon -= 1;
  2323. tbFrom.time = mktime(&tmFrom);
  2324. tmTo.tm_year -= 1900;
  2325. tmTo.tm_mon -= 1;
  2326. tbTo.time = mktime(&tmTo);
  2327. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2328. {
  2329. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2330. {
  2331. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2332. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2333. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2334. }
  2335. maxProfile.ChargingProfileId = -1;
  2336. maxProfile.StackLevel = -1;
  2337. if(maxProfile.ChargingProfileId == -1)
  2338. DEBUG_INFO("MaxProfile found.\n");
  2339. else
  2340. DEBUG_INFO("MaxProfile updated.\n");
  2341. // Required item
  2342. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2343. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2344. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2345. if(isUnitA)
  2346. {
  2347. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2348. 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++)
  2349. {
  2350. 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"));
  2351. 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?
  2352. 3:
  2353. 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")));
  2354. 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")));
  2355. }
  2356. }
  2357. else
  2358. {
  2359. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2360. 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++)
  2361. {
  2362. 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"));
  2363. 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?
  2364. 3:
  2365. 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")));
  2366. 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));
  2367. }
  2368. }
  2369. // Optional item
  2370. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2371. {
  2372. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2373. }
  2374. else
  2375. {
  2376. sprintf((char*)maxProfile.ValidFrom, " ");
  2377. }
  2378. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2379. {
  2380. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2381. }
  2382. else
  2383. {
  2384. sprintf((char*)maxProfile.ValidTo, " ");
  2385. }
  2386. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2387. {
  2388. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2389. }
  2390. else
  2391. {
  2392. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2393. }
  2394. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2395. {
  2396. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2397. }
  2398. else
  2399. {
  2400. maxProfile.TransactionId = -1;
  2401. }
  2402. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2403. {
  2404. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2405. }
  2406. else
  2407. {
  2408. maxProfile.ChargingSchedule.Duration = 86400;
  2409. }
  2410. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2411. {
  2412. 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")));
  2413. }
  2414. else
  2415. {
  2416. 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));
  2417. }
  2418. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2419. {
  2420. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2421. }
  2422. else
  2423. {
  2424. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2425. }
  2426. }
  2427. }
  2428. }
  2429. else
  2430. {
  2431. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2432. {
  2433. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2434. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2435. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2436. }
  2437. maxProfile.ChargingProfileId = -1;
  2438. maxProfile.StackLevel = -1;
  2439. if(maxProfile.ChargingProfileId == -1)
  2440. DEBUG_INFO("MaxProfile found.\n");
  2441. else
  2442. DEBUG_INFO("MaxProfile updated.\n");
  2443. // Required item
  2444. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2445. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2446. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2447. if(isUnitA)
  2448. {
  2449. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2450. 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++)
  2451. {
  2452. 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"));
  2453. 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?
  2454. 3:
  2455. 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")));
  2456. 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")));
  2457. }
  2458. }
  2459. else
  2460. {
  2461. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2462. 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++)
  2463. {
  2464. 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"));
  2465. 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?
  2466. 3:
  2467. 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")));
  2468. 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));
  2469. }
  2470. }
  2471. // Optional item
  2472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2473. {
  2474. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2475. }
  2476. else
  2477. {
  2478. sprintf((char*)maxProfile.ValidFrom, " ");
  2479. }
  2480. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2481. {
  2482. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2483. }
  2484. else
  2485. {
  2486. sprintf((char*)maxProfile.ValidTo, " ");
  2487. }
  2488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2489. {
  2490. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2491. }
  2492. else
  2493. {
  2494. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2495. }
  2496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2497. {
  2498. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2499. }
  2500. else
  2501. {
  2502. maxProfile.TransactionId = -1;
  2503. }
  2504. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2505. {
  2506. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2507. }
  2508. else
  2509. {
  2510. maxProfile.ChargingSchedule.Duration = 86400;
  2511. }
  2512. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2513. {
  2514. 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")));
  2515. }
  2516. else
  2517. {
  2518. 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));
  2519. }
  2520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2521. {
  2522. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2523. }
  2524. else
  2525. {
  2526. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2527. }
  2528. }
  2529. }
  2530. }
  2531. json_object_put(obj);
  2532. }
  2533. fclose(fp);
  2534. /*
  2535. if(maxProfile.ChargingProfileId !=-1)
  2536. {
  2537. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2538. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2539. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2540. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2541. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2542. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2543. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2544. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2545. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2546. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2547. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2548. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2549. {
  2550. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2551. {
  2552. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2553. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2554. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2555. }
  2556. }
  2557. }
  2558. else
  2559. DEBUG_INFO("MaxProfile not found.\n");
  2560. DEBUG_INFO("------------------------------------\n");*/
  2561. }
  2562. /*
  2563. * Align found profile start schedule & periods
  2564. */
  2565. //DEBUG_INFO("====================================\n");
  2566. /*
  2567. // For local test usage, force modify found profile start schedule info
  2568. 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);
  2569. 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);
  2570. 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);
  2571. */
  2572. if(txProfile.ChargingProfileId != -1)
  2573. {
  2574. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2575. {
  2576. if(txProfile.ChargingSchedule.Duration != -1)
  2577. {
  2578. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2579. 0:
  2580. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2581. }
  2582. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2583. {
  2584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2585. {
  2586. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2587. 0:
  2588. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2589. if(idxPeriod > 0)
  2590. {
  2591. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2592. {
  2593. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2594. }
  2595. }
  2596. }
  2597. }
  2598. }
  2599. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2600. {
  2601. if(txProfile.ChargingSchedule.Duration != -1)
  2602. {
  2603. 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?
  2604. 0:
  2605. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2606. }
  2607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2608. {
  2609. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2610. {
  2611. 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?
  2612. 0:
  2613. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2614. if(idxPeriod > 0)
  2615. {
  2616. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2617. {
  2618. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2619. }
  2620. }
  2621. }
  2622. }
  2623. }
  2624. else
  2625. {
  2626. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2627. {
  2628. if(txProfile.ChargingSchedule.Duration != -1)
  2629. {
  2630. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2631. 0:
  2632. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2633. }
  2634. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2635. {
  2636. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2637. {
  2638. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2639. 0:
  2640. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2641. if(idxPeriod > 0)
  2642. {
  2643. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2644. {
  2645. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2646. }
  2647. }
  2648. }
  2649. }
  2650. }
  2651. else
  2652. {
  2653. if(txProfile.ChargingSchedule.Duration != -1)
  2654. {
  2655. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2656. 0:
  2657. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2658. }
  2659. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2660. {
  2661. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2662. {
  2663. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2664. 0:
  2665. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2666. if(idxPeriod > 0)
  2667. {
  2668. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2669. {
  2670. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2671. }
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. /*
  2678. DEBUG_INFO("txProfile after align.\n");
  2679. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2680. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2681. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2682. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2683. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2684. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2685. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2686. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2687. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2688. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2689. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2690. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2691. {
  2692. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2693. {
  2694. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2695. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2696. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2697. }
  2698. }*/
  2699. }
  2700. if(defaultTxProfile.ChargingProfileId != -1)
  2701. {
  2702. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2703. {
  2704. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2705. {
  2706. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2707. 0:
  2708. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2709. }
  2710. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2711. {
  2712. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2713. {
  2714. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2715. 0:
  2716. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2717. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2718. {
  2719. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2720. }
  2721. if(idxPeriod > 0)
  2722. {
  2723. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2724. {
  2725. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2726. }
  2727. }
  2728. }
  2729. }
  2730. }
  2731. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2732. {
  2733. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2734. {
  2735. 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?
  2736. 0:
  2737. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2738. }
  2739. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2740. {
  2741. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2742. {
  2743. 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?
  2744. 0:
  2745. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2746. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2747. {
  2748. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2749. }
  2750. if(idxPeriod > 0)
  2751. {
  2752. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2753. {
  2754. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2755. }
  2756. }
  2757. }
  2758. }
  2759. }
  2760. else
  2761. {
  2762. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2763. {
  2764. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2765. {
  2766. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2767. 0:
  2768. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2769. }
  2770. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2771. {
  2772. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2773. {
  2774. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2775. 0:
  2776. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2777. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2778. {
  2779. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2780. }
  2781. if(idxPeriod > 0)
  2782. {
  2783. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2784. {
  2785. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2786. }
  2787. }
  2788. }
  2789. }
  2790. }
  2791. else
  2792. {
  2793. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2794. {
  2795. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2796. 0:
  2797. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2798. }
  2799. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2800. {
  2801. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2802. {
  2803. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2804. 0:
  2805. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2806. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2807. {
  2808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2809. }
  2810. if(idxPeriod > 0)
  2811. {
  2812. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2813. {
  2814. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2815. }
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. /*
  2822. DEBUG_INFO("defaultTxProfile after align.\n");
  2823. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2824. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2825. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2826. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2827. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2828. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2829. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2830. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2831. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2832. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2833. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2834. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2835. {
  2836. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2837. {
  2838. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2839. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2840. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2841. }
  2842. }
  2843. DEBUG_INFO("------------------------------------\n");*/
  2844. }
  2845. if(maxProfile.ChargingProfileId != -1)
  2846. {
  2847. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2848. {
  2849. if(maxProfile.ChargingSchedule.Duration != -1)
  2850. {
  2851. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2852. 0:
  2853. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2854. }
  2855. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2856. {
  2857. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2858. {
  2859. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2860. 0:
  2861. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2862. if(idxPeriod > 0)
  2863. {
  2864. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2865. {
  2866. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2867. }
  2868. }
  2869. }
  2870. }
  2871. }
  2872. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2873. {
  2874. if(maxProfile.ChargingSchedule.Duration != -1)
  2875. {
  2876. 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?
  2877. 0:
  2878. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2879. }
  2880. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2881. {
  2882. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2883. {
  2884. 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?
  2885. 0:
  2886. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2887. if(idxPeriod > 0)
  2888. {
  2889. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2890. {
  2891. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2892. }
  2893. }
  2894. }
  2895. }
  2896. }
  2897. else
  2898. {
  2899. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2900. {
  2901. if(maxProfile.ChargingSchedule.Duration != -1)
  2902. {
  2903. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2904. 0:
  2905. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2906. }
  2907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2908. {
  2909. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2910. {
  2911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2912. 0:
  2913. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2914. if(idxPeriod > 0)
  2915. {
  2916. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2917. {
  2918. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2919. }
  2920. }
  2921. }
  2922. }
  2923. }
  2924. else
  2925. {
  2926. if(maxProfile.ChargingSchedule.Duration != -1)
  2927. {
  2928. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2929. 0:
  2930. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2931. }
  2932. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2933. {
  2934. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2935. {
  2936. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2937. 0:
  2938. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2939. if(idxPeriod > 0)
  2940. {
  2941. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2942. {
  2943. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2944. }
  2945. }
  2946. }
  2947. }
  2948. }
  2949. }
  2950. /*
  2951. DEBUG_INFO("MaxProfile after align.\n");
  2952. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2953. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2954. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2955. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2956. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2957. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2958. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2959. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2960. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2961. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2962. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2963. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2964. {
  2965. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2966. {
  2967. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2968. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2969. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2970. }
  2971. }
  2972. DEBUG_INFO("------------------------------------\n");*/
  2973. }
  2974. /*
  2975. * Merge to conposite schedule
  2976. */
  2977. //DEBUG_INFO("====================================\n");
  2978. // Find each profile period quantity
  2979. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2980. {
  2981. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2982. limitMax = idx+1;
  2983. }
  2984. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2985. {
  2986. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2987. limitDef = idx+1;
  2988. }
  2989. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2990. {
  2991. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2992. limitTx = idx+1;
  2993. }
  2994. // TxProfile found, composite schedule based on it
  2995. if(txProfile.ChargingProfileId != -1)
  2996. {
  2997. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2998. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2999. {
  3000. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3001. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3002. (txProfile.ChargingSchedule.Duration > 0))
  3003. {
  3004. if(maxProfile.ChargingProfileId != -1)
  3005. {
  3006. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3007. {
  3008. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3009. {
  3010. if((maxProfile.ChargingSchedule.Duration > 0))
  3011. {
  3012. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3013. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3014. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3015. }
  3016. else
  3017. {
  3018. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3019. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3020. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3021. }
  3022. }
  3023. if(idxMaxPeriod == (limitMax-1))
  3024. {
  3025. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3026. {
  3027. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3028. {
  3029. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3030. compositePeriodIdx++;
  3031. }
  3032. else
  3033. {
  3034. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3035. }
  3036. }
  3037. }
  3038. }
  3039. }
  3040. else
  3041. {
  3042. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3043. {
  3044. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3045. compositePeriodIdx++;
  3046. }
  3047. else
  3048. {
  3049. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3050. }
  3051. }
  3052. }
  3053. if(idxTxPeriod == (limitTx-1))
  3054. {
  3055. if(defaultTxProfile.ChargingProfileId != -1)
  3056. {
  3057. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3058. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3059. {
  3060. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3061. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3062. (defaultTxProfile.ChargingSchedule.Duration>0))
  3063. {
  3064. if(maxProfile.ChargingProfileId != -1)
  3065. {
  3066. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3067. {
  3068. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3069. {
  3070. if((maxProfile.ChargingSchedule.Duration > 0))
  3071. {
  3072. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3073. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3074. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3075. }
  3076. else
  3077. {
  3078. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3079. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3080. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3081. }
  3082. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3083. {
  3084. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3085. {
  3086. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3087. compositePeriodIdx++;
  3088. }
  3089. else
  3090. {
  3091. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3092. }
  3093. }
  3094. // Delete duplicate period
  3095. if(compositePeriodIdx > 1)
  3096. {
  3097. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3098. {
  3099. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3100. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3101. compositePeriodIdx -= 1;
  3102. }
  3103. }
  3104. }
  3105. else
  3106. {
  3107. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3108. {
  3109. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3110. compositePeriodIdx++;
  3111. }
  3112. else
  3113. {
  3114. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3115. }
  3116. break;
  3117. }
  3118. }
  3119. }
  3120. else
  3121. {
  3122. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3123. {
  3124. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3125. compositePeriodIdx++;
  3126. }
  3127. else
  3128. {
  3129. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3130. }
  3131. }
  3132. }
  3133. }
  3134. }
  3135. }
  3136. }
  3137. }
  3138. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3139. else if(defaultTxProfile.ChargingProfileId != -1)
  3140. {
  3141. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3142. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3143. {
  3144. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3145. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3146. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3147. {
  3148. if(maxProfile.ChargingProfileId != -1)
  3149. {
  3150. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3151. {
  3152. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3153. {
  3154. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3155. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3156. if((maxProfile.ChargingSchedule.Duration > 0))
  3157. {
  3158. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3159. }
  3160. else
  3161. {
  3162. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3163. }
  3164. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3165. {
  3166. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3167. {
  3168. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3169. compositePeriodIdx++;
  3170. }
  3171. else
  3172. {
  3173. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3174. }
  3175. }
  3176. // Delete duplicate period
  3177. if(compositePeriodIdx > 1)
  3178. {
  3179. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3180. {
  3181. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3182. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3183. compositePeriodIdx -= 1;
  3184. }
  3185. }
  3186. }
  3187. else
  3188. {
  3189. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3190. {
  3191. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3192. compositePeriodIdx++;
  3193. }
  3194. else
  3195. {
  3196. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3197. }
  3198. break;
  3199. }
  3200. }
  3201. }
  3202. else
  3203. {
  3204. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3205. {
  3206. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3207. compositePeriodIdx++;
  3208. }
  3209. else
  3210. {
  3211. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3212. }
  3213. }
  3214. }
  3215. }
  3216. }
  3217. // Fill other period by MaxProfile
  3218. if(maxProfile.ChargingProfileId != -1)
  3219. {
  3220. if(compositePeriodIdx==0)
  3221. {
  3222. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3223. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3224. {
  3225. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3226. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3227. (maxProfile.ChargingSchedule.Duration > 0))
  3228. {
  3229. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3230. {
  3231. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3232. compositePeriodIdx++;
  3233. }
  3234. else
  3235. {
  3236. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3237. }
  3238. }
  3239. }
  3240. }
  3241. else
  3242. {
  3243. int lastCompositePeriodIdx = compositePeriodIdx;
  3244. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3245. {
  3246. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3247. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3248. (maxProfile.ChargingSchedule.Duration > 0))
  3249. {
  3250. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3251. {
  3252. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3253. {
  3254. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3255. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3256. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3257. }
  3258. else
  3259. {
  3260. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3261. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3262. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3263. }
  3264. }
  3265. if(tmpPeriod.Limit != -1)
  3266. {
  3267. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3268. {
  3269. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3270. {
  3271. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3272. compositePeriodIdx++;
  3273. }
  3274. else
  3275. {
  3276. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3277. }
  3278. }
  3279. // Delete duplicate period
  3280. if(compositePeriodIdx > 1)
  3281. {
  3282. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3283. {
  3284. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3285. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3286. compositePeriodIdx -= 1;
  3287. }
  3288. }
  3289. }
  3290. }
  3291. }
  3292. }
  3293. }
  3294. compositeProfile->ChargingSchedule.Duration = durationReq;
  3295. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3296. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3297. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3298. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3299. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3300. {
  3301. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3302. {
  3303. compositeProfile->ChargingProfileId = 1;
  3304. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3305. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3306. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3307. }
  3308. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3309. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3310. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3311. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3312. }
  3313. if(line)
  3314. free(line);
  3315. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3316. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3317. }
  3318. //==========================================
  3319. // Init all share memory
  3320. //==========================================
  3321. int InitShareMemory()
  3322. {
  3323. int result = PASS;
  3324. int MeterSMId;
  3325. //creat ShmSysConfigAndInfo
  3326. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3327. {
  3328. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3329. result = FAIL;
  3330. }
  3331. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3332. {
  3333. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3334. result = FAIL;
  3335. }
  3336. else
  3337. {}
  3338. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3339. {
  3340. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3341. result = FAIL;
  3342. }
  3343. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3344. {
  3345. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3346. result = FAIL;
  3347. }
  3348. else
  3349. {}
  3350. //creat ShmPsuData
  3351. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3352. {
  3353. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3354. result = FAIL;
  3355. }
  3356. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3357. {
  3358. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3359. result = FAIL;
  3360. }
  3361. else
  3362. {}
  3363. //creat ShmOCPP16Data
  3364. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3365. {
  3366. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3367. result = FAIL;
  3368. }
  3369. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3370. {
  3371. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3372. result = FAIL;
  3373. }
  3374. else
  3375. {}
  3376. /****************************** For Initial Settings************************************************/
  3377. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3378. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3379. // allocate Configuration memory address
  3380. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3381. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3382. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3383. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3384. //offline MeterValue Interval
  3385. TempMeterValueInterval = 0;
  3386. return result;
  3387. }
  3388. int ProcessShareMemory()
  3389. {
  3390. int result = PASS;
  3391. ParsingRatedCur modelnameInfo={0};
  3392. if(InitShareMemory() == FAIL)
  3393. {
  3394. DEBUG_ERROR("InitShareMemory NG\n");
  3395. if(ShmStatusCodeData!=NULL)
  3396. {
  3397. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3398. }
  3399. result = FAIL;
  3400. }
  3401. // Model name parsing
  3402. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3403. {
  3404. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3405. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3406. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3407. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3408. ) // 'D' means DC
  3409. {
  3410. // DO series
  3411. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3412. {
  3413. SystemInitial += 1;
  3414. gunTotalNumber += 1;
  3415. gunType[gun_index] = GUN_TYPE_DO;
  3416. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3417. {
  3418. case Gun_Type_Chademo:
  3419. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3420. break;
  3421. case Gun_Type_CCS_2:
  3422. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3423. break;
  3424. case Gun_Type_GB:
  3425. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3426. break;
  3427. case Gun_Type_AC:
  3428. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3429. break;
  3430. default:
  3431. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3432. break;
  3433. }
  3434. }
  3435. }
  3436. else
  3437. {
  3438. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3439. {
  3440. SystemInitial += 1;
  3441. gunTotalNumber += 1;
  3442. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3443. {
  3444. case Gun_Type_Chademo:
  3445. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3446. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3447. break;
  3448. case Gun_Type_CCS_2:
  3449. gunType[gun_index] = GUN_TYPE_CCS;
  3450. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3451. break;
  3452. case Gun_Type_GB:
  3453. gunType[gun_index] = GUN_TYPE_GBT;
  3454. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3455. break;
  3456. case Gun_Type_AC:
  3457. gunType[gun_index] = GUN_TYPE_AC;
  3458. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3459. break;
  3460. default:
  3461. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3462. break;
  3463. }
  3464. }
  3465. }
  3466. }
  3467. else
  3468. {
  3469. DEBUG_ERROR("Model name parsing fail.\n");
  3470. result = FAIL;
  3471. }
  3472. if(result != PASS)sleep(5);
  3473. return result;
  3474. }
  3475. void CheckSystemValue(void)
  3476. {
  3477. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3478. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3479. char filenmae[100]={0};
  3480. char str[100]={0};
  3481. int tempIndex = 0;
  3482. //===============================
  3483. // send Heartbeat
  3484. //===============================
  3485. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3486. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3487. {
  3488. clientTime.Heartbeat=time((time_t*)NULL);
  3489. if(server_sign == TRUE)
  3490. {
  3491. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3492. }
  3493. else
  3494. {
  3495. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3496. }
  3497. }
  3498. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3499. {
  3500. //parameter for test
  3501. sendHeartbeatRequest(0);
  3502. //==============================================
  3503. // Reset Waiting Time
  3504. //==============================================
  3505. HeartBeatWithNOResponse += 1;
  3506. }
  3507. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3508. {
  3509. //==========================================
  3510. // csu trigger DataTransferReq
  3511. //==========================================
  3512. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3513. {
  3514. sendDataTransferRequest(gun_index);
  3515. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3516. }
  3517. //===============================
  3518. // CSU Trigger Authorize Request
  3519. //===============================
  3520. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3521. {
  3522. sendAuthorizeRequest(0);
  3523. authorizeRetryTimes = authorizeRetryTimes + 1;
  3524. if(authorizeRetryTimes < 3)
  3525. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3526. }
  3527. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3528. {
  3529. authorizeRetryTimes = 0;
  3530. SetOcppConnStatus(FALSE);
  3531. server_sign = FALSE;
  3532. }
  3533. 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))
  3534. {
  3535. sendAuthorizeRequest(0);
  3536. }
  3537. //==============================================
  3538. // Charger start transaction
  3539. //==============================================
  3540. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3541. {
  3542. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3543. sendStartTransactionRequest(gun_index);
  3544. clientTime.StartTransaction = time((time_t*)NULL);
  3545. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3546. storeTempStopTransaction(gun_index);
  3547. }
  3548. //==============================================
  3549. // Charger stop transaction
  3550. //==============================================
  3551. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3552. {
  3553. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3554. sendStopTransactionRequest(gun_index);
  3555. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3556. clientTime.StopTransaction = time((time_t*)NULL);
  3557. }
  3558. //==============================================
  3559. // Charger status report
  3560. //==============================================
  3561. //--- Check Mode Change ---//
  3562. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3563. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3564. {
  3565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3566. {
  3567. tempIndex = ((gun_index==2) ? 1: 0);
  3568. }
  3569. else
  3570. {
  3571. tempIndex = gun_index;
  3572. }
  3573. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3574. {
  3575. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3576. {
  3577. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3578. {
  3579. // Sent unplug message for California pricing logic
  3580. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3581. {
  3582. uint8_t ts[20];
  3583. getNowDatetime(ts);
  3584. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3585. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3586. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3587. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3588. }
  3589. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3590. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3591. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3592. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3593. {
  3594. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3595. if((access(filenmae,F_OK))!=-1)
  3596. {
  3597. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3598. sprintf(str,"rm -f %s",filenmae);
  3599. system(str);
  3600. }
  3601. }
  3602. }
  3603. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3604. #if 1 // for TempStopTransaction
  3605. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3606. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3607. {
  3608. checkTempStopTransaction(gun_index);
  3609. }
  3610. #endif
  3611. }
  3612. }
  3613. }
  3614. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3615. {
  3616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3617. {
  3618. tempIndex = ((gun_index==2) ? 1: 0);
  3619. }
  3620. else
  3621. {
  3622. tempIndex = gun_index;
  3623. }
  3624. for (int index = 0; index < CCS_QUANTITY; index++)
  3625. {
  3626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3627. {
  3628. 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]*/ )
  3629. {
  3630. // Sent unplug message for California pricing logic
  3631. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3632. {
  3633. uint8_t ts[20];
  3634. getNowDatetime(ts);
  3635. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3636. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3637. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3638. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3639. }
  3640. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3641. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3642. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3643. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3644. {
  3645. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3646. if((access(filenmae,F_OK))!=-1)
  3647. {
  3648. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3649. sprintf(str,"rm -f %s",filenmae);
  3650. system(str);
  3651. }
  3652. }
  3653. }
  3654. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3655. #if 1 // for TempStopTransaction
  3656. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3657. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3658. {
  3659. checkTempStopTransaction(gun_index);
  3660. }
  3661. #endif
  3662. }
  3663. }
  3664. }
  3665. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3666. {
  3667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3668. {
  3669. tempIndex = ((gun_index==2) ? 1: 0);
  3670. }
  3671. else
  3672. {
  3673. tempIndex = gun_index;
  3674. }
  3675. for (int index = 0; index < GB_QUANTITY; index++)
  3676. {
  3677. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3678. {
  3679. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3680. {
  3681. // Sent unplug message for California pricing logic
  3682. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3683. {
  3684. uint8_t ts[20];
  3685. getNowDatetime(ts);
  3686. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3687. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3688. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3689. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3690. }
  3691. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3692. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3693. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3694. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3695. {
  3696. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3697. if((access(filenmae,F_OK))!=-1)
  3698. {
  3699. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3700. sprintf(str,"rm -f %s",filenmae);
  3701. system(str);
  3702. }
  3703. }
  3704. }
  3705. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3706. #if 1 // for TempStopTransaction
  3707. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3708. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3709. {
  3710. checkTempStopTransaction(gun_index);
  3711. }
  3712. #endif
  3713. }
  3714. }
  3715. }
  3716. else if(gunType[gun_index] == GUN_TYPE_DO)
  3717. {
  3718. tempIndex = gun_index;
  3719. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3720. {
  3721. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3722. {
  3723. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3724. {
  3725. // Sent unplug message for California pricing logic
  3726. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3727. {
  3728. uint8_t ts[20];
  3729. getNowDatetime(ts);
  3730. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3731. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3732. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3733. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3734. }
  3735. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3736. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3737. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3738. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  3739. {
  3740. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3741. if((access(filenmae,F_OK))!=-1)
  3742. {
  3743. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3744. sprintf(str,"rm -f %s",filenmae);
  3745. system(str);
  3746. }
  3747. }
  3748. }
  3749. 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);
  3750. #if 1 // for TempStopTransaction
  3751. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3752. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3753. {
  3754. checkTempStopTransaction(gun_index);
  3755. }
  3756. #endif
  3757. }
  3758. }
  3759. }
  3760. else
  3761. {
  3762. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3763. {
  3764. tempIndex = 2;
  3765. }
  3766. else
  3767. {
  3768. tempIndex = gun_index;
  3769. }
  3770. for (int index = 0; index < AC_QUANTITY; index++)
  3771. {
  3772. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3773. {
  3774. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3775. {
  3776. // Sent unplug message for California pricing logic
  3777. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3778. {
  3779. uint8_t ts[20];
  3780. getNowDatetime(ts);
  3781. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3782. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3783. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3784. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3785. }
  3786. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3787. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3788. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3789. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3790. {
  3791. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3792. if((access(filenmae,F_OK))!=-1)
  3793. {
  3794. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3795. sprintf(str,"rm -f %s",filenmae);
  3796. system(str);
  3797. }
  3798. }
  3799. }
  3800. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3801. #if 1 // for TempStopTransaction
  3802. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3803. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3804. {
  3805. checkTempStopTransaction(gun_index);
  3806. }
  3807. #endif
  3808. }
  3809. }// END
  3810. }
  3811. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3812. (
  3813. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3814. )
  3815. )
  3816. {
  3817. if(SystemInitial > 0)
  3818. SystemInitial -= 1;
  3819. sendStatusNotificationRequest(gun_index);
  3820. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3821. }
  3822. //==============================================
  3823. // CSU Trigger Smart Charging Profilw
  3824. //==============================================
  3825. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3826. {
  3827. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3828. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3829. }
  3830. //==============================================
  3831. // Meter report
  3832. //==============================================
  3833. // Trigger MeterValue
  3834. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3835. {
  3836. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3837. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3838. }
  3839. // ClockAlign MeterValue
  3840. 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))
  3841. {
  3842. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3843. {
  3844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3845. {
  3846. tempIndex = ((gun_index==2) ? 1: 0);
  3847. }
  3848. else
  3849. {
  3850. tempIndex = gun_index;
  3851. }
  3852. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3853. {
  3854. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3855. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3856. {
  3857. reqClockAlignMeter[gun_index] = 1;
  3858. }
  3859. }// End for CHAdeMO
  3860. }
  3861. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3862. {
  3863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3864. {
  3865. tempIndex = ((gun_index==2) ? 1: 0);
  3866. }
  3867. else
  3868. {
  3869. tempIndex = gun_index;
  3870. }
  3871. for (int index = 0; index < CCS_QUANTITY; index++)
  3872. {
  3873. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3874. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3875. {
  3876. reqClockAlignMeter[gun_index] = 1;
  3877. }
  3878. } // End for CCS
  3879. }
  3880. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3881. {
  3882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3883. {
  3884. tempIndex = ((gun_index==2) ? 1: 0);
  3885. }
  3886. else
  3887. {
  3888. tempIndex = gun_index;
  3889. }
  3890. for (int index = 0; index < GB_QUANTITY; index++)
  3891. {
  3892. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3893. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3894. {
  3895. reqClockAlignMeter[gun_index] = 1;
  3896. }
  3897. }// End for GB
  3898. }
  3899. else if(gunType[gun_index] == GUN_TYPE_DO)
  3900. {
  3901. tempIndex = gun_index;
  3902. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3903. {
  3904. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3905. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3906. {
  3907. reqClockAlignMeter[gun_index] = 1;
  3908. }
  3909. }
  3910. }
  3911. else
  3912. {
  3913. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3914. {
  3915. tempIndex = 2;
  3916. }
  3917. else
  3918. {
  3919. tempIndex = gun_index;
  3920. }
  3921. for (int index = 0; index < AC_QUANTITY; index++)
  3922. {
  3923. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3924. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3925. {
  3926. reqClockAlignMeter[gun_index] = 1;
  3927. }
  3928. }//End for AC
  3929. }
  3930. if(reqClockAlignMeter[gun_index] == 1)
  3931. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3932. }
  3933. // Sample period MeterValue
  3934. 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))))
  3935. {
  3936. //check Transaction active
  3937. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3938. {
  3939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3940. {
  3941. tempIndex = ((gun_index==2) ? 1: 0);
  3942. }
  3943. else
  3944. {
  3945. tempIndex = gun_index;
  3946. }
  3947. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3948. {
  3949. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3950. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3951. {
  3952. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3953. {
  3954. reqSampleMeter[gun_index] = 1;
  3955. }
  3956. }
  3957. }// End for CHAdeMO
  3958. }
  3959. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3960. {
  3961. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3962. {
  3963. tempIndex = ((gun_index==2) ? 1: 0);
  3964. }
  3965. else
  3966. {
  3967. tempIndex = gun_index;
  3968. }
  3969. for (int index = 0; index < CCS_QUANTITY; index++)
  3970. {
  3971. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3972. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3973. {
  3974. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3975. {
  3976. reqSampleMeter[gun_index] = 1;
  3977. }
  3978. }
  3979. } // End for CCS
  3980. }
  3981. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3982. {
  3983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3984. {
  3985. tempIndex = ((gun_index==2) ? 1: 0);
  3986. }
  3987. else
  3988. {
  3989. tempIndex = gun_index;
  3990. }
  3991. for (int index = 0; index < GB_QUANTITY; index++)
  3992. {
  3993. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3994. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3995. {
  3996. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3997. {
  3998. reqSampleMeter[gun_index] = 1;
  3999. }
  4000. }
  4001. }// End for GB
  4002. }
  4003. else if(gunType[gun_index] == GUN_TYPE_DO)
  4004. {
  4005. tempIndex = gun_index;
  4006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4007. {
  4008. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4009. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4010. {
  4011. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4012. {
  4013. reqSampleMeter[gun_index] = 1;
  4014. }
  4015. }
  4016. }
  4017. }
  4018. else
  4019. {
  4020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4021. {
  4022. tempIndex = 2;
  4023. }
  4024. else
  4025. {
  4026. tempIndex = gun_index;
  4027. }
  4028. for (int index = 0; index < AC_QUANTITY; index++)
  4029. {
  4030. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4031. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4032. {
  4033. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4034. {
  4035. reqSampleMeter[gun_index] = 1;
  4036. }
  4037. }
  4038. }//End for AC
  4039. }
  4040. if(reqSampleMeter[gun_index] == 1)
  4041. {
  4042. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4043. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4044. storeTempStopTransaction(gun_index);
  4045. }
  4046. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4047. }
  4048. //==============================================
  4049. // Check Connector reserved
  4050. //==============================================
  4051. //===============================
  4052. // Check if Reserve is expired
  4053. //===============================
  4054. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4055. {
  4056. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4057. {
  4058. DEBUG_INFO("reserve expired.\n");
  4059. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4060. }
  4061. }//END OF Check if Reserve is expired
  4062. //==========================================
  4063. // csu trigger FirmwareStatusNotificationReq
  4064. //==========================================
  4065. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4066. {
  4067. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4068. }
  4069. //==========================================
  4070. // csu trigger DiagnosticsStatusNotificationReq
  4071. //==========================================
  4072. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4073. {
  4074. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4075. }
  4076. //==========================================
  4077. // csu trigger CancelReservationConf
  4078. //==========================================
  4079. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4080. {
  4081. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4082. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4083. }
  4084. //==========================================
  4085. // csu trigger ChangeAvailabilityConf
  4086. //==========================================
  4087. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4088. {
  4089. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4090. }
  4091. //==========================================
  4092. // csu trigger UnlockConnectorConf
  4093. //==========================================
  4094. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4095. {
  4096. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4097. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4098. }
  4099. //==========================================
  4100. // csu trigger ReserveNowConf
  4101. //==========================================
  4102. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4103. {
  4104. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4105. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4106. }
  4107. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4108. {
  4109. sendSignCertificateRequest();
  4110. }
  4111. }
  4112. }
  4113. //==========================================
  4114. // send request routine
  4115. //==========================================
  4116. int sendAuthorizeRequest(int gun_index)
  4117. {
  4118. mtrace();
  4119. int result = FAIL;
  4120. char message[100]={0};
  4121. char guid[37];
  4122. char tempdata[65]={0};
  4123. DEBUG_INFO("sendAuthorizeRequest...\n");
  4124. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4125. //Local Authorize
  4126. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4127. {
  4128. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4129. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4130. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4131. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4132. result = PASS;
  4133. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4134. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4135. authorizeRetryTimes = 0;
  4136. return result;
  4137. }
  4138. 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))||
  4139. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4140. {
  4141. // Query from cache
  4142. DEBUG_INFO("Authorize from cache.\n");
  4143. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4144. // Query from list
  4145. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4146. {
  4147. DEBUG_INFO("Authorize from list.\n");
  4148. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4149. }
  4150. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4151. {
  4152. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4153. {
  4154. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4155. }
  4156. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4157. {
  4158. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4159. }
  4160. if(!GetOcppConnStatus())
  4161. {
  4162. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4163. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4164. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4165. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4166. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4167. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4168. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4169. authorizeRetryTimes = 0;
  4170. return result;
  4171. }
  4172. }
  4173. else
  4174. {
  4175. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4176. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4177. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4178. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4179. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4180. else
  4181. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4182. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4183. result = PASS;
  4184. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4185. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4186. authorizeRetryTimes = 0;
  4187. return result;
  4188. }
  4189. }
  4190. //initialize struct Authorize
  4191. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4192. //get data from shared memory
  4193. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4194. random_uuid(guid);
  4195. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4196. LWS_Send(message);
  4197. sprintf(tempdata, "Authorize,%d", gun_index);
  4198. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4199. {
  4200. result = PASS;
  4201. DEBUG_INFO("Authorize mapItem pass\n");
  4202. }
  4203. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4204. return result;
  4205. }
  4206. int sendBootNotificationRequest(void)
  4207. {
  4208. mtrace();
  4209. int result = FAIL;
  4210. char message[500]={0}, payload[700]={0};
  4211. char guid[37]={0};
  4212. char tempdata[65]={0};
  4213. // Fill BootNotification fields
  4214. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4215. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4216. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4217. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4218. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4219. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4220. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4221. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4222. ShmOCPP16Data->ChargeBoxId
  4223. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4224. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4225. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4226. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4227. ,ShmOCPP16Data->BootNotification.CpIccid
  4228. ,ShmOCPP16Data->BootNotification.CpImsi);
  4229. random_uuid(guid);
  4230. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4231. LWS_Send(message);
  4232. sprintf(tempdata, "BootNotification,0");
  4233. 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*/)
  4234. {
  4235. result = PASS;
  4236. }
  4237. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4238. strcpy(queuedata,message);
  4239. return result;
  4240. }
  4241. int sendDataTransferRequest(int gun_index)
  4242. {
  4243. mtrace();
  4244. char message[1000]={0};
  4245. char guid[37]={0};
  4246. char tempdata[65]={0};
  4247. int result = FAIL;
  4248. random_uuid(guid);
  4249. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4250. MESSAGE_TYPE_CALL,
  4251. guid,
  4252. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4253. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4254. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4255. LWS_Send(message);
  4256. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4257. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4258. {
  4259. result = PASS;
  4260. DEBUG_INFO("DataTransfer mapItem pass\n");
  4261. }
  4262. return result;
  4263. }
  4264. int sendDiagnosticsStatusNotificationRequest(char *status)
  4265. {
  4266. mtrace();
  4267. int result = FAIL;
  4268. char message[110]={0};
  4269. char guid[37]={0};
  4270. char tempdata[65]={0};
  4271. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4272. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4273. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4274. random_uuid(guid);
  4275. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4276. LWS_SendNow(message);
  4277. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4278. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4279. {
  4280. result = PASS;
  4281. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4282. }
  4283. //#ifdef SystemLogMessage
  4284. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4285. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4286. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4287. //#endif
  4288. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4289. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4290. //record status
  4291. if(strcmp(status,"Idle")==0)
  4292. {
  4293. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4294. }
  4295. else if(strcmp(status,"Uploaded")==0)
  4296. {
  4297. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4298. }
  4299. else if(strcmp(status,"UploadFailed")==0)
  4300. {
  4301. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4302. }
  4303. else if(strcmp(status,"Uploading")==0)
  4304. {
  4305. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4306. }
  4307. return result;
  4308. }
  4309. int sendFirmwareStatusNotificationRequest(char *status)
  4310. {
  4311. mtrace();
  4312. int result = FAIL;
  4313. char message[110]={0};
  4314. char guid[37]={0};
  4315. char tempdata[65]={0};
  4316. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4317. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4318. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4319. random_uuid(guid);
  4320. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4321. LWS_SendNow(message);
  4322. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4323. 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*/)
  4324. {
  4325. result = PASS;
  4326. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4327. }
  4328. //#ifdef SystemLogMessage
  4329. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4330. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4331. //#endif
  4332. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4333. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4334. //record status
  4335. if(strcmp(status,"Downloaded")==0)
  4336. {
  4337. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4338. }
  4339. else if(strcmp(status,"DownloadFailed")==0)
  4340. {
  4341. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4342. }
  4343. else if(strcmp(status,"Downloading")==0)
  4344. {
  4345. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4346. }
  4347. else if(strcmp(status,"Idle")==0)
  4348. {
  4349. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4350. }
  4351. else if(strcmp(status,"InstallationFailed")==0)
  4352. {
  4353. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4354. }
  4355. else if(strcmp(status,"Installing")==0)
  4356. {
  4357. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4358. }
  4359. else if(strcmp(status,"Installed")==0)
  4360. {
  4361. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4362. }
  4363. return result;
  4364. }
  4365. int sendHeartbeatRequest(int gun_index)
  4366. {
  4367. mtrace();
  4368. int result = FAIL;
  4369. char message[80]={0};
  4370. char guid[37]={0};
  4371. char tempdata[65]={0};
  4372. random_uuid(guid);
  4373. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4374. , MESSAGE_TYPE_CALL
  4375. , guid );
  4376. LWS_Send(message);
  4377. sprintf(tempdata, "Heartbeat,%d", 0);
  4378. 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*/)
  4379. {
  4380. result = PASS;
  4381. }
  4382. return result;
  4383. }
  4384. int sendStartTransactionRequest(int gun_index)
  4385. {
  4386. mtrace();
  4387. int result = FAIL;
  4388. char message[250]={0};
  4389. char guid[37]={0};
  4390. struct timeval tmnow;
  4391. struct tm *tm;
  4392. char buf[28];//, usec_buf[6];
  4393. char tempdata[65]={0};
  4394. int tempIndex = 0;
  4395. DEBUG_INFO("sendStartTransactionRequest...\n");
  4396. gettimeofday(&tmnow, NULL);
  4397. time_t t;
  4398. t = time(NULL);
  4399. /*UTC time and date*/
  4400. tm = gmtime(&t);
  4401. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4402. #if 0 // remove temporally
  4403. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4404. strcat(buf,".");
  4405. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4406. strcat(buf,usec_buf);
  4407. #endif
  4408. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4409. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4410. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4411. // clear StartTransaction Response
  4412. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4413. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4414. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4415. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4416. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4417. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4418. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4419. {
  4420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4421. {
  4422. tempIndex = ((gun_index==2) ? 1: 0);
  4423. }
  4424. else
  4425. {
  4426. tempIndex = gun_index;
  4427. }
  4428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4429. {
  4430. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4431. {
  4432. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4433. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4434. }
  4435. }
  4436. }
  4437. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  4448. {
  4449. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4450. {
  4451. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4452. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4453. }
  4454. }
  4455. }
  4456. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4457. {
  4458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4459. {
  4460. tempIndex = ((gun_index==2) ? 1: 0);
  4461. }
  4462. else
  4463. {
  4464. tempIndex = gun_index;
  4465. }
  4466. for (int index = 0; index < GB_QUANTITY; index++)
  4467. {
  4468. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4469. {
  4470. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4471. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4472. }
  4473. }
  4474. }
  4475. else if(gunType[gun_index] == GUN_TYPE_DO)
  4476. {
  4477. tempIndex = gun_index;
  4478. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4479. {
  4480. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4481. {
  4482. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4483. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4484. }
  4485. }
  4486. }
  4487. else
  4488. {
  4489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4490. {
  4491. tempIndex = 2;
  4492. }
  4493. else
  4494. {
  4495. tempIndex = gun_index;
  4496. }
  4497. for (int index = 0; index < AC_QUANTITY; index++)
  4498. {
  4499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4500. {
  4501. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4502. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4503. }
  4504. }
  4505. }
  4506. random_uuid(guid);
  4507. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4508. {
  4509. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4510. , gun_index +1
  4511. , MESSAGE_TYPE_CALL
  4512. , guid
  4513. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4514. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4515. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4516. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4517. }
  4518. else
  4519. {
  4520. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4521. , gun_index +1
  4522. , MESSAGE_TYPE_CALL
  4523. , guid
  4524. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4525. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4526. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4527. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4528. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4529. }
  4530. #if 1
  4531. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4532. 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*/)
  4533. {
  4534. result = PASS;
  4535. }
  4536. #endif
  4537. strcpy(queuedata, message);
  4538. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4539. OCPP_insert_transaction_msg(YES, queuedata);
  4540. return result;
  4541. }
  4542. int sendStatusNotificationRequest(int gun_index)
  4543. {
  4544. mtrace();
  4545. int result = FAIL;
  4546. char message[600]={0};
  4547. char guid[37];
  4548. int currentStatus = 0;
  4549. struct timeval tmnow;
  4550. struct tm *tm;
  4551. char buf[28];//, usec_buf[6];
  4552. char tempdata[65]={0};
  4553. int tempIndex = 0;
  4554. uint8_t isStateChanged = TRUE;
  4555. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4556. gettimeofday(&tmnow, NULL);
  4557. time_t t;
  4558. t = time(NULL);
  4559. /*UTC time and date*/
  4560. tm = gmtime(&t);
  4561. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4562. #if 0 // remove temporally
  4563. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4564. strcat(buf,".");
  4565. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4566. strcat(buf,usec_buf);
  4567. #endif
  4568. //printf("%s",buf);
  4569. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4570. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4571. // it's option
  4572. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4573. /*
  4574. enum _SYSTEM_STATUS
  4575. {
  4576. S_BOOTING = 0,
  4577. S_IDLE, = 1
  4578. S_AUTHORIZING, =2
  4579. S_REASSIGN_CHECK, =3
  4580. S_REASSIGN, =4
  4581. S_PRECHARGE, =5
  4582. S_PREPARING_FOR_EV, =6
  4583. S_PREPARING_FOR_EVSE, =7
  4584. S_CHARGING, =8
  4585. S_TERMINATING, =9
  4586. S_COMPLETE, =10
  4587. S_ALARM, =11
  4588. S_FAULT =12
  4589. }
  4590. */
  4591. //check Transaction active
  4592. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4593. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4594. {
  4595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4596. {
  4597. tempIndex = ((gun_index==2) ? 1: 0);
  4598. }
  4599. else
  4600. {
  4601. tempIndex = gun_index;
  4602. }
  4603. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4604. {
  4605. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4606. {
  4607. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4608. {
  4609. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4610. {
  4611. currentStatus = Preparing; //OCPP Status: Preparing
  4612. }
  4613. else
  4614. {
  4615. currentStatus = Available; //OCPP Status: Available
  4616. }
  4617. }
  4618. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4619. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4620. ) //S_PRECHARGE
  4621. {
  4622. currentStatus = Preparing; //OCPP Status: Preparing
  4623. }
  4624. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4625. {
  4626. currentStatus = Charging; //OCPP Status: Charging
  4627. }
  4628. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4629. {
  4630. currentStatus = Finishing; //OCPP Status: Finishing
  4631. }
  4632. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4633. {
  4634. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4635. }
  4636. 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
  4637. {
  4638. currentStatus = Unavailable; //OCPP Status: Unavailable
  4639. }
  4640. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4641. {
  4642. currentStatus = Faulted; //OCPP Status: Faulted
  4643. }
  4644. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4645. {
  4646. currentStatus = Reserved; //OCPP Status: Reserved
  4647. }
  4648. } //end of the same index
  4649. }//end of for CHAdeMO_QUANTITY
  4650. }
  4651. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4652. {
  4653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4654. {
  4655. tempIndex = ((gun_index==2) ? 1: 0);
  4656. }
  4657. else
  4658. {
  4659. tempIndex = gun_index;
  4660. }
  4661. for (int index = 0; index < CCS_QUANTITY; index++)
  4662. {
  4663. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4664. {
  4665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4666. {
  4667. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4668. {
  4669. currentStatus = Preparing; //OCPP Status: Preparing
  4670. }
  4671. else
  4672. {
  4673. currentStatus = Available; //OCPP Status: Available
  4674. }
  4675. }
  4676. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4677. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4678. ) //S_PRECHARGE
  4679. {
  4680. currentStatus = Preparing; //OCPP Status: Preparing
  4681. }
  4682. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4683. {
  4684. currentStatus = Charging; //OCPP Status: Charging
  4685. }
  4686. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4687. {
  4688. currentStatus = Finishing; //OCPP Status: Finishing
  4689. }
  4690. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4691. {
  4692. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4693. }
  4694. 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
  4695. {
  4696. currentStatus = Unavailable; //OCPP Status : Unavailable
  4697. }
  4698. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4699. {
  4700. currentStatus = Faulted; //OCPP Status: Faulted
  4701. }
  4702. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4703. {
  4704. currentStatus = Reserved; //OCPP Status: Reserved
  4705. }
  4706. } //end of the same index
  4707. } // end of for CCS_QUANTITY
  4708. }
  4709. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4710. {
  4711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4712. {
  4713. tempIndex = ((gun_index==2) ? 1: 0);
  4714. }
  4715. else
  4716. {
  4717. tempIndex = gun_index;
  4718. }
  4719. for (int index = 0; index < GB_QUANTITY; index++)
  4720. {
  4721. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4722. {
  4723. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4724. {
  4725. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4726. {
  4727. currentStatus = Preparing; //OCPP Status: Preparing
  4728. }
  4729. else
  4730. {
  4731. currentStatus = Available; //OCPP Status: Available
  4732. }
  4733. }
  4734. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4735. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4736. ) //S_PRECHARGE
  4737. {
  4738. currentStatus = Preparing; //OCPP Status: Preparing
  4739. }
  4740. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4741. {
  4742. currentStatus = Charging; //OCPP Status: Charging
  4743. }
  4744. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4745. {
  4746. currentStatus = Finishing; //OCPP Status: Finishing
  4747. }
  4748. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4749. {
  4750. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4751. }
  4752. 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
  4753. {
  4754. currentStatus = Unavailable; //OCPP Status: Unavailable
  4755. }
  4756. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4757. {
  4758. currentStatus = Faulted; //OCPP Status: Faulted
  4759. }
  4760. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4761. {
  4762. currentStatus = Reserved; //OCPP Status: Reserved
  4763. }
  4764. } //end of the same index
  4765. } // end of for GB_QUANTITY
  4766. }
  4767. else if(gunType[gun_index] == GUN_TYPE_DO)
  4768. {
  4769. tempIndex = gun_index;
  4770. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4771. {
  4772. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4773. {
  4774. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4775. {
  4776. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4777. {
  4778. currentStatus = Preparing; //OCPP Status: Preparing
  4779. }
  4780. else
  4781. {
  4782. currentStatus = Available; //OCPP Status: Available
  4783. }
  4784. }
  4785. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4786. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4787. ) //S_PRECHARGE
  4788. {
  4789. currentStatus = Preparing; //OCPP Status: Preparing
  4790. }
  4791. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4792. {
  4793. currentStatus = Charging; //OCPP Status: Charging
  4794. }
  4795. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4796. {
  4797. currentStatus = Finishing; //OCPP Status: Finishing
  4798. }
  4799. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4800. {
  4801. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4802. }
  4803. 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
  4804. {
  4805. currentStatus = Unavailable; //OCPP Status: Unavailable
  4806. }
  4807. 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
  4808. {
  4809. currentStatus = Faulted; //OCPP Status: Faulted
  4810. }
  4811. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4812. {
  4813. currentStatus = Reserved; //OCPP Status: Reserved
  4814. }
  4815. } //end of the same index
  4816. }
  4817. }
  4818. else
  4819. {
  4820. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4821. {
  4822. tempIndex = 2;
  4823. }
  4824. else
  4825. {
  4826. tempIndex = gun_index;
  4827. }
  4828. for (int index = 0; index < AC_QUANTITY; index++)
  4829. {
  4830. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4831. {
  4832. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4833. {
  4834. 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))
  4835. {
  4836. currentStatus = Preparing; //OCPP Status: Preparing
  4837. }
  4838. else
  4839. {
  4840. currentStatus = Available; //OCPP Status: Available
  4841. }
  4842. }
  4843. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4844. {
  4845. currentStatus = Preparing; //OCPP Status: Preparing
  4846. }
  4847. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4848. {
  4849. currentStatus = Charging; //OCPP Status: Charging
  4850. }
  4851. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4852. {
  4853. currentStatus = Finishing; //OCPP Status: Finishing
  4854. }
  4855. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4856. {
  4857. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4858. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4859. else
  4860. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4861. }
  4862. 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
  4863. {
  4864. currentStatus = Unavailable; //OCPP Status: Unavailable
  4865. }
  4866. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4867. {
  4868. currentStatus = Faulted; //OCPP Status: Faulted
  4869. }
  4870. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4871. {
  4872. currentStatus = Reserved; //OCPP Status: Reserved
  4873. }
  4874. }//end of the same index
  4875. }//end of for AC_QUANTITY
  4876. }
  4877. //it's option
  4878. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4879. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4880. {
  4881. isStateChanged = FALSE;
  4882. }
  4883. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4884. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4885. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4886. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4887. random_uuid(guid);
  4888. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4889. , MESSAGE_TYPE_CALL
  4890. , guid
  4891. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4892. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4893. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4894. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4895. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4896. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4897. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4898. if((server_sign == TRUE) && isStateChanged)
  4899. {
  4900. LWS_Send(message);
  4901. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4902. 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*/)
  4903. {
  4904. //DEBUG_ERROR("statusNotification mapitem pass");
  4905. result = PASS;
  4906. }
  4907. }
  4908. else
  4909. {
  4910. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4911. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4912. result = PASS;
  4913. }
  4914. return result;
  4915. }
  4916. int sendStopTransactionRequest(int gun_index)
  4917. {
  4918. mtrace();
  4919. int result = FAIL;
  4920. //char message[1500]={0};
  4921. char guid[37]={0};
  4922. char tempdata[65]={0};
  4923. int tempIndex = 0;
  4924. char TempStopTransaction[256];
  4925. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4926. //int idx_sample=0;
  4927. DEBUG_INFO("sendStopTransactionRequest \n");
  4928. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4929. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4930. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4931. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4932. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4933. {
  4934. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4935. {
  4936. tempIndex = ((gun_index==2) ? 1: 0);
  4937. }
  4938. else
  4939. {
  4940. tempIndex = gun_index;
  4941. }
  4942. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4943. {
  4944. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4945. {
  4946. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4947. }
  4948. }// END OF CHAdeMO_QUANTITY
  4949. }
  4950. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4951. {
  4952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4953. {
  4954. tempIndex = ((gun_index==2) ? 1: 0);
  4955. }
  4956. else
  4957. {
  4958. tempIndex = gun_index;
  4959. }
  4960. for (int index = 0; index < CCS_QUANTITY; index++)
  4961. {
  4962. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4963. {
  4964. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4965. }
  4966. }// END OF CCS_QUANTITY
  4967. }
  4968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4969. {
  4970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4971. {
  4972. tempIndex = ((gun_index==2) ? 1: 0);
  4973. }
  4974. else
  4975. {
  4976. tempIndex = gun_index;
  4977. }
  4978. for (int index = 0; index < GB_QUANTITY; index++)
  4979. {
  4980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4981. {
  4982. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4983. }
  4984. }// END OF GB_QUANTITY
  4985. }
  4986. else if(gunType[gun_index] == GUN_TYPE_DO)
  4987. {
  4988. tempIndex = gun_index;
  4989. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4990. {
  4991. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4992. {
  4993. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4994. }
  4995. }// END OF GB_QUANTITY
  4996. }
  4997. else
  4998. {
  4999. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5000. {
  5001. tempIndex = 2;
  5002. }
  5003. else
  5004. {
  5005. tempIndex = gun_index;
  5006. }
  5007. for (int index = 0; index < AC_QUANTITY; index++)
  5008. {
  5009. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5010. {
  5011. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5012. }
  5013. }// END OF AC_QUANTITY
  5014. }
  5015. //====================================== Stop Transaction Time =====================================================
  5016. struct timeval tmnow;
  5017. struct tm *tm;
  5018. char buf[28];//, usec_buf[6];
  5019. gettimeofday(&tmnow, NULL);
  5020. time_t t;
  5021. t = time(NULL);
  5022. /*UTC time and date*/
  5023. tm = gmtime(&t);
  5024. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5026. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5027. random_uuid(guid);
  5028. /***********************************transactionData******************************************************/
  5029. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5031. //=================================
  5032. // Transaction_Begin
  5033. //=================================
  5034. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5035. {
  5036. //============================================ Energy.Active.Import.Interval ================================
  5037. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5040. 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*/]);
  5041. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5042. 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))
  5043. {
  5044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5045. }
  5046. else
  5047. {
  5048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5049. }
  5050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5052. }
  5053. //=================================
  5054. // Transaction_End
  5055. //=================================
  5056. // ================================= Current.Import L1 ===============================================
  5057. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5058. {
  5059. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5060. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5061. {
  5062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5063. {
  5064. tempIndex = ((gun_index==2) ? 1: 0);
  5065. }
  5066. else
  5067. {
  5068. tempIndex = gun_index;
  5069. }
  5070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5071. {
  5072. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5073. {
  5074. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5075. }
  5076. }// End of for CHAdeMO_QUANTITY
  5077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5078. }
  5079. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5080. {
  5081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5082. {
  5083. tempIndex = ((gun_index==2) ? 1: 0);
  5084. }
  5085. else
  5086. {
  5087. tempIndex = gun_index;
  5088. }
  5089. for (int index = 0; index < CCS_QUANTITY; index++)
  5090. {
  5091. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5092. {
  5093. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5094. }
  5095. }// End of for CCS_QUANTITY
  5096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5097. }
  5098. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5099. {
  5100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5101. {
  5102. tempIndex = ((gun_index==2) ? 1: 0);
  5103. }
  5104. else
  5105. {
  5106. tempIndex = gun_index;
  5107. }
  5108. for (int index = 0; index < GB_QUANTITY; index++)
  5109. {
  5110. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5111. {
  5112. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5113. }
  5114. }// End of for GB_QUANTITY
  5115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5116. }
  5117. else if(gunType[gun_index] == GUN_TYPE_DO)
  5118. {
  5119. tempIndex = gun_index;
  5120. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5121. {
  5122. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5123. {
  5124. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5125. }
  5126. }
  5127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5128. }
  5129. else
  5130. {
  5131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5132. {
  5133. tempIndex = 2;
  5134. }
  5135. else
  5136. {
  5137. tempIndex = gun_index;
  5138. }
  5139. for (int index = 0; index < AC_QUANTITY; index++)
  5140. {
  5141. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5142. {
  5143. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5144. }
  5145. }// End of for AC_QUANTITY
  5146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5147. }
  5148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5153. }
  5154. // ================================= Energy.Active.Import.Interval ==============================================
  5155. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5156. {
  5157. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5158. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5159. {
  5160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5161. {
  5162. tempIndex = ((gun_index==2) ? 1: 0);
  5163. }
  5164. else
  5165. {
  5166. tempIndex = gun_index;
  5167. }
  5168. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5171. {
  5172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5173. }
  5174. }// END OF CHAdeMO_QUANTITY
  5175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5176. }
  5177. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5180. {
  5181. tempIndex = ((gun_index==2) ? 1: 0);
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < CCS_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5190. {
  5191. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5192. }
  5193. }// END OF CCS_QUANTITY
  5194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5195. }
  5196. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5197. {
  5198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5199. {
  5200. tempIndex = ((gun_index==2) ? 1: 0);
  5201. }
  5202. else
  5203. {
  5204. tempIndex = gun_index;
  5205. }
  5206. for (int index = 0; index < GB_QUANTITY; index++)
  5207. {
  5208. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5209. {
  5210. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5211. }
  5212. }// END OF GB_QUANTITY
  5213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5214. }
  5215. else if(gunType[gun_index] == GUN_TYPE_DO)
  5216. {
  5217. tempIndex = gun_index;
  5218. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5219. {
  5220. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5221. {
  5222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5223. }
  5224. }
  5225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5226. }
  5227. else
  5228. {
  5229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5230. {
  5231. tempIndex = 2;
  5232. }
  5233. else
  5234. {
  5235. tempIndex = gun_index;
  5236. }
  5237. for (int index = 0; index < AC_QUANTITY; index++)
  5238. {
  5239. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5240. {
  5241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5242. }
  5243. }// END OF AC_QUANTITY
  5244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5245. }
  5246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5251. }
  5252. //=================================== Power.Active.Import ==================================================
  5253. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5254. {
  5255. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5256. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5257. {
  5258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5259. {
  5260. tempIndex = ((gun_index==2) ? 1: 0);
  5261. }
  5262. else
  5263. {
  5264. tempIndex = gun_index;
  5265. }
  5266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5267. {
  5268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5269. {
  5270. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5271. }
  5272. } // End for CHAdeMO_QUANTITY
  5273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5274. }
  5275. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5276. {
  5277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5278. {
  5279. tempIndex = ((gun_index==2) ? 1: 0);
  5280. }
  5281. else
  5282. {
  5283. tempIndex = gun_index;
  5284. }
  5285. for (int index = 0; index < CCS_QUANTITY; index++)
  5286. {
  5287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5288. {
  5289. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5290. }
  5291. } // END for CCS_QUANTITY
  5292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5293. }
  5294. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5295. {
  5296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5297. {
  5298. tempIndex = ((gun_index==2) ? 1: 0);
  5299. }
  5300. else
  5301. {
  5302. tempIndex = gun_index;
  5303. }
  5304. for (int index = 0; index < GB_QUANTITY; index++)
  5305. {
  5306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5307. {
  5308. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5309. }
  5310. }// END for GB_QUANTITY
  5311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5312. }
  5313. else if(gunType[gun_index] == GUN_TYPE_DO)
  5314. {
  5315. tempIndex = gun_index;
  5316. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5317. {
  5318. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5319. {
  5320. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5321. }
  5322. }
  5323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5324. }
  5325. else
  5326. {
  5327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5328. {
  5329. tempIndex = 2;
  5330. }
  5331. else
  5332. {
  5333. tempIndex = gun_index;
  5334. }
  5335. for (int index = 0; index < AC_QUANTITY; index++)
  5336. {
  5337. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5338. {
  5339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5340. }
  5341. } // END for AC_QUANTITY
  5342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5343. }
  5344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5349. }
  5350. //============================ Voltage L1 ====================================
  5351. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5352. {
  5353. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5354. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5355. {
  5356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5357. {
  5358. tempIndex = ((gun_index==2) ? 1: 0);
  5359. }
  5360. else
  5361. {
  5362. tempIndex = gun_index;
  5363. }
  5364. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5365. {
  5366. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5367. {
  5368. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5369. }
  5370. } // END OF FOR CHAdeMO_QUANTITY
  5371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5372. }
  5373. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5374. {
  5375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5376. {
  5377. tempIndex = ((gun_index==2) ? 1: 0);
  5378. }
  5379. else
  5380. {
  5381. tempIndex = gun_index;
  5382. }
  5383. for (int index = 0; index < CCS_QUANTITY; index++)
  5384. {
  5385. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5386. {
  5387. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5388. }
  5389. } // END OF FOR CCS_QUANTITY
  5390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5391. }
  5392. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5393. {
  5394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5395. {
  5396. tempIndex = ((gun_index==2) ? 1: 0);
  5397. }
  5398. else
  5399. {
  5400. tempIndex = gun_index;
  5401. }
  5402. for (int index = 0; index < GB_QUANTITY; index++)
  5403. {
  5404. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5405. {
  5406. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5407. }
  5408. } // END OF FOR GB_QUANTITY
  5409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5410. }
  5411. else if(gunType[gun_index] == GUN_TYPE_DO)
  5412. {
  5413. tempIndex = gun_index;
  5414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5415. {
  5416. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5417. {
  5418. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5419. }
  5420. }
  5421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5422. }
  5423. else
  5424. {
  5425. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5426. {
  5427. tempIndex = 2;
  5428. }
  5429. else
  5430. {
  5431. tempIndex = gun_index;
  5432. }
  5433. for (int index = 0; index < AC_QUANTITY; index++)
  5434. {
  5435. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5436. {
  5437. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5438. }
  5439. } // END OF FOR AC_QUANTITY
  5440. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5441. }
  5442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5447. }
  5448. //====================== End SoC ================================
  5449. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5450. {
  5451. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5452. 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))
  5453. {
  5454. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5455. {
  5456. tempIndex = ((gun_index==2) ? 1: 0);
  5457. }
  5458. else
  5459. {
  5460. tempIndex = gun_index;
  5461. }
  5462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5463. {
  5464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5465. {
  5466. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5467. {
  5468. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5469. }
  5470. }
  5471. }
  5472. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5473. {
  5474. for (int index = 0; index < CCS_QUANTITY; index++)
  5475. {
  5476. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5477. {
  5478. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5479. }
  5480. }
  5481. }
  5482. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5483. {
  5484. for (int index = 0; index < GB_QUANTITY; index++)
  5485. {
  5486. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5487. {
  5488. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5489. }
  5490. }
  5491. }
  5492. else if(gunType[gun_index] == GUN_TYPE_DO)
  5493. {
  5494. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5495. {
  5496. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5497. {
  5498. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5499. }
  5500. }
  5501. }
  5502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5508. } // END FOR DC CASE
  5509. }
  5510. // ================================= Current.Import L2 ===============================================
  5511. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5512. {
  5513. // AC 3 phse L2 current
  5514. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5515. {
  5516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5517. {
  5518. tempIndex = 2;
  5519. }
  5520. else
  5521. {
  5522. tempIndex = gun_index;
  5523. }
  5524. for (int index = 0; index < AC_QUANTITY; index++)
  5525. {
  5526. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5527. {
  5528. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5529. }
  5530. }// End of for AC_QUANTITY
  5531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5532. }
  5533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5538. }
  5539. // ================================= Current.Import L3 ===============================================
  5540. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5541. {
  5542. // AC 3 phse L3 current
  5543. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5544. {
  5545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5546. {
  5547. tempIndex = 2;
  5548. }
  5549. else
  5550. {
  5551. tempIndex = gun_index;
  5552. }
  5553. for (int index = 0; index < AC_QUANTITY; index++)
  5554. {
  5555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5556. {
  5557. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5558. }
  5559. }// End of for AC_QUANTITY
  5560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5561. }
  5562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5567. }
  5568. //============================ Voltage L2 ====================================
  5569. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5570. {
  5571. // AC 3 phse L2 voltage
  5572. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5573. {
  5574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5575. {
  5576. tempIndex = 2;
  5577. }
  5578. else
  5579. {
  5580. tempIndex = gun_index;
  5581. }
  5582. for (int index = 0; index < AC_QUANTITY; index++)
  5583. {
  5584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5585. {
  5586. 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
  5587. }
  5588. } // END OF FOR AC_QUANTITY
  5589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5590. }
  5591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5596. }
  5597. //============================ Voltage L3 ====================================
  5598. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5599. {
  5600. // AC 3 phse L3 voltage
  5601. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5602. {
  5603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5604. {
  5605. tempIndex = 2;
  5606. }
  5607. else
  5608. {
  5609. tempIndex = gun_index;
  5610. }
  5611. for (int index = 0; index < AC_QUANTITY; index++)
  5612. {
  5613. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5614. {
  5615. 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
  5616. }
  5617. } // END OF FOR AC_QUANTITY
  5618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5619. }
  5620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5623. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5625. }
  5626. //====================== Start SoC ================================
  5627. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5628. {
  5629. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5630. 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))
  5631. {
  5632. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5633. {
  5634. tempIndex = ((gun_index==2) ? 1: 0);
  5635. }
  5636. else
  5637. {
  5638. tempIndex = gun_index;
  5639. }
  5640. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5641. {
  5642. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5643. {
  5644. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5645. {
  5646. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5647. }
  5648. }
  5649. }
  5650. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5651. {
  5652. for (int index = 0; index < CCS_QUANTITY; index++)
  5653. {
  5654. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5655. {
  5656. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5657. }
  5658. }
  5659. }
  5660. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5661. {
  5662. for (int index = 0; index < GB_QUANTITY; index++)
  5663. {
  5664. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5665. {
  5666. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5667. }
  5668. }
  5669. }
  5670. else if(gunType[gun_index] == GUN_TYPE_DO)
  5671. {
  5672. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5673. {
  5674. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5675. {
  5676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5677. }
  5678. }
  5679. }
  5680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5686. } // END FOR DC CASE
  5687. }
  5688. //================================================ Message create ====================================================
  5689. json_object *StopTransaction = json_object_new_object();
  5690. json_object *transactionDatas = json_object_new_array();
  5691. json_object *sampledValues = json_object_new_array();
  5692. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5693. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5694. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5695. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5696. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5697. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5698. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5699. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5700. {
  5701. json_object *transactionData = json_object_new_object();
  5702. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5703. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5704. {
  5705. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5706. {
  5707. json_object *sampledValue = json_object_new_object();
  5708. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5709. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5710. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5711. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5712. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5713. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5714. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5715. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5716. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5717. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5718. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5719. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5720. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5721. json_object_array_add(sampledValues, sampledValue);
  5722. }
  5723. }
  5724. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5725. json_object_array_add(transactionDatas, transactionData);
  5726. }
  5727. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5728. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5729. ,MESSAGE_TYPE_CALL
  5730. ,guid
  5731. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5732. json_object_put(StopTransaction);
  5733. #if 1 // for TempStopTransaction
  5734. //Delete TempStopTransaction
  5735. if((access(TempStopTransaction,F_OK))!=-1)
  5736. {
  5737. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5738. }
  5739. #endif
  5740. #if 1
  5741. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5742. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5743. {
  5744. result = PASS;
  5745. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5746. }
  5747. #endif
  5748. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5749. OCPP_insert_transaction_msg(NO, queuedata);
  5750. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5751. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5752. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5753. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5754. {
  5755. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5756. }
  5757. //for test
  5758. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5759. return result;
  5760. }
  5761. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5762. {
  5763. mtrace();
  5764. int result = FAIL;
  5765. char guid[37]={0};
  5766. char tempdata[65]={0};
  5767. int tempIndex = 0;
  5768. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5769. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5770. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5771. //set value
  5772. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5773. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5774. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5775. -1);
  5776. random_uuid(guid);
  5777. //UTC Date time
  5778. struct timeval tmnow;
  5779. struct tm *tm;
  5780. char buf[28];//, usec_buf[6];
  5781. gettimeofday(&tmnow, NULL);
  5782. time_t t;
  5783. t = time(NULL);
  5784. /*UTC time and date*/
  5785. tm = gmtime(&t);
  5786. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5787. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5788. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5789. //********************************(1)Current.Import L1************************************************/
  5790. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5791. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5792. (dataType == ReadingContext_Trigger))
  5793. {
  5794. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5795. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5796. {
  5797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5798. {
  5799. tempIndex = ((gun_index==2) ? 1: 0);
  5800. }
  5801. else
  5802. {
  5803. tempIndex = gun_index;
  5804. }
  5805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5806. {
  5807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5808. {
  5809. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5810. }
  5811. }
  5812. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5813. }
  5814. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5815. {
  5816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5817. {
  5818. tempIndex = ((gun_index==2) ? 1: 0);
  5819. }
  5820. else
  5821. {
  5822. tempIndex = gun_index;
  5823. }
  5824. for (int index = 0; index < CCS_QUANTITY; index++)
  5825. {
  5826. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5827. {
  5828. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5829. }
  5830. }
  5831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5832. }
  5833. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5834. {
  5835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5836. {
  5837. tempIndex = ((gun_index==2) ? 1: 0);
  5838. }
  5839. else
  5840. {
  5841. tempIndex = gun_index;
  5842. }
  5843. for (int index = 0; index < GB_QUANTITY; index++)
  5844. {
  5845. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5846. {
  5847. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5848. }
  5849. }
  5850. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5851. }
  5852. else if(gunType[gun_index] == GUN_TYPE_DO)
  5853. {
  5854. tempIndex = gun_index;
  5855. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5856. {
  5857. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5858. {
  5859. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5860. }
  5861. }
  5862. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5863. }
  5864. else
  5865. {
  5866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5867. {
  5868. tempIndex = 2;
  5869. }
  5870. else
  5871. {
  5872. tempIndex = gun_index;
  5873. }
  5874. for (int index = 0; index < AC_QUANTITY; index++)
  5875. {
  5876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5877. {
  5878. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5879. }
  5880. }
  5881. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5882. }
  5883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5884. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5885. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5886. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5887. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5888. }
  5889. //********************************(2)Energy.Active.Import.Register ************************************************/
  5890. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5891. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5892. (dataType == ReadingContext_Trigger))
  5893. {
  5894. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5895. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5896. {
  5897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5898. {
  5899. tempIndex = ((gun_index==2) ? 1: 0);
  5900. }
  5901. else
  5902. {
  5903. tempIndex = gun_index;
  5904. }
  5905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5906. {
  5907. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5908. {
  5909. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5910. }
  5911. }
  5912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5913. }
  5914. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5915. {
  5916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5917. {
  5918. tempIndex = ((gun_index==2) ? 1: 0);
  5919. }
  5920. else
  5921. {
  5922. tempIndex = gun_index;
  5923. }
  5924. for (int index = 0; index < CCS_QUANTITY; index++)
  5925. {
  5926. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5927. {
  5928. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5929. }
  5930. }
  5931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5932. }
  5933. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5934. {
  5935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5936. {
  5937. tempIndex = ((gun_index==2) ? 1: 0);
  5938. }
  5939. else
  5940. {
  5941. tempIndex = gun_index;
  5942. }
  5943. for (int index = 0; index < GB_QUANTITY; index++)
  5944. {
  5945. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5946. {
  5947. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5948. }
  5949. }
  5950. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5951. }
  5952. else if(gunType[gun_index] == GUN_TYPE_DO)
  5953. {
  5954. tempIndex = gun_index;
  5955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5956. {
  5957. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5958. {
  5959. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5960. }
  5961. }
  5962. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5963. }
  5964. else
  5965. {
  5966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5967. {
  5968. tempIndex = 2;
  5969. }
  5970. else
  5971. {
  5972. tempIndex = gun_index;
  5973. }
  5974. for (int index = 0; index < AC_QUANTITY; index++)
  5975. {
  5976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5977. {
  5978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5979. }
  5980. }
  5981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5982. }
  5983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5986. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5988. }
  5989. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5990. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5991. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5992. (dataType == ReadingContext_Trigger))
  5993. {
  5994. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5995. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5996. {
  5997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5998. {
  5999. tempIndex = ((gun_index==2) ? 1: 0);
  6000. }
  6001. else
  6002. {
  6003. tempIndex = gun_index;
  6004. }
  6005. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6006. {
  6007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6008. {
  6009. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6010. }
  6011. } // END OF FOR CHAdeMO_QUANTITY
  6012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6013. }
  6014. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6015. {
  6016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6017. {
  6018. tempIndex = ((gun_index==2) ? 1: 0);
  6019. }
  6020. else
  6021. {
  6022. tempIndex = gun_index;
  6023. }
  6024. for (int index = 0; index < CCS_QUANTITY; index++)
  6025. {
  6026. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6027. {
  6028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6029. }
  6030. } // END OF CCS_QUANTITY
  6031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6032. }
  6033. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6034. {
  6035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6036. {
  6037. tempIndex = ((gun_index==2) ? 1: 0);
  6038. }
  6039. else
  6040. {
  6041. tempIndex = gun_index;
  6042. }
  6043. for (int index = 0; index < GB_QUANTITY; index++)
  6044. {
  6045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6046. {
  6047. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6048. }
  6049. } // END OF GB_QUANTITY
  6050. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6051. }
  6052. else if(gunType[gun_index] == GUN_TYPE_DO)
  6053. {
  6054. tempIndex = gun_index;
  6055. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6056. {
  6057. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6058. {
  6059. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6060. }
  6061. }
  6062. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6063. }
  6064. else
  6065. {
  6066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6067. {
  6068. tempIndex = 2;
  6069. }
  6070. else
  6071. {
  6072. tempIndex = gun_index;
  6073. }
  6074. for (int index = 0; index < AC_QUANTITY; index++)
  6075. {
  6076. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6077. {
  6078. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6079. }
  6080. }
  6081. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6082. }
  6083. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6084. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6085. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6086. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6087. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6088. }
  6089. //********************************(4)Power.Active.Import************************************************/
  6090. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6091. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6092. (dataType == ReadingContext_Trigger))
  6093. {
  6094. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6095. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6096. {
  6097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6098. {
  6099. tempIndex = ((gun_index==2) ? 1: 0);
  6100. }
  6101. else
  6102. {
  6103. tempIndex = gun_index;
  6104. }
  6105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6106. {
  6107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6108. {
  6109. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6110. }
  6111. } // END OF FOR
  6112. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6113. }
  6114. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6115. {
  6116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6117. {
  6118. tempIndex = ((gun_index==2) ? 1: 0);
  6119. }
  6120. else
  6121. {
  6122. tempIndex = gun_index;
  6123. }
  6124. for (int index = 0; index < CCS_QUANTITY; index++)
  6125. {
  6126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6127. {
  6128. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6129. }
  6130. }
  6131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6132. }
  6133. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6134. {
  6135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6136. {
  6137. tempIndex = ((gun_index==2) ? 1: 0);
  6138. }
  6139. else
  6140. {
  6141. tempIndex = gun_index;
  6142. }
  6143. for (int index = 0; index < GB_QUANTITY; index++)
  6144. {
  6145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6146. {
  6147. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6148. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6149. }
  6150. }
  6151. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6152. }
  6153. else if(gunType[gun_index] == GUN_TYPE_DO)
  6154. {
  6155. tempIndex = gun_index;
  6156. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6157. {
  6158. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6159. {
  6160. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6161. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6162. }
  6163. }
  6164. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6165. }
  6166. else
  6167. {
  6168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6169. {
  6170. tempIndex = 2;
  6171. }
  6172. else
  6173. {
  6174. tempIndex = gun_index;
  6175. }
  6176. for (int index = 0; index < AC_QUANTITY; index++)
  6177. {
  6178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6179. {
  6180. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6181. }
  6182. }
  6183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6184. }
  6185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6190. }
  6191. //***********************************************(5)VOLTAGE L1******************************************************/
  6192. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6193. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6194. (dataType == ReadingContext_Trigger))
  6195. {
  6196. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6197. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6198. {
  6199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6200. {
  6201. tempIndex = ((gun_index==2) ? 1: 0);
  6202. }
  6203. else
  6204. {
  6205. tempIndex = gun_index;
  6206. }
  6207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6208. {
  6209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6210. {
  6211. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6212. }
  6213. }
  6214. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6215. }
  6216. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6217. {
  6218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6219. {
  6220. tempIndex = ((gun_index==2) ? 1: 0);
  6221. }
  6222. else
  6223. {
  6224. tempIndex = gun_index;
  6225. }
  6226. for (int index = 0; index < CCS_QUANTITY; index++)
  6227. {
  6228. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6229. {
  6230. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6231. }
  6232. }
  6233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6234. }
  6235. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6236. {
  6237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6238. {
  6239. tempIndex = ((gun_index==2) ? 1: 0);
  6240. }
  6241. else
  6242. {
  6243. tempIndex = gun_index;
  6244. }
  6245. for (int index = 0; index < GB_QUANTITY; index++)
  6246. {
  6247. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6248. {
  6249. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6250. }
  6251. }
  6252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6253. }
  6254. else if(gunType[gun_index] == GUN_TYPE_DO)
  6255. {
  6256. tempIndex = gun_index;
  6257. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6258. {
  6259. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6260. {
  6261. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6262. }
  6263. }
  6264. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6265. }
  6266. else
  6267. {
  6268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6269. {
  6270. tempIndex = 2;
  6271. }
  6272. else
  6273. {
  6274. tempIndex = gun_index;
  6275. }
  6276. for (int index = 0; index < AC_QUANTITY; index++)
  6277. {
  6278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6279. {
  6280. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6281. }
  6282. }
  6283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6284. }
  6285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6286. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6288. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6289. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6290. }
  6291. //***********************************************(6)SOC******************************************************/
  6292. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6293. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6294. (dataType == ReadingContext_Trigger))
  6295. {
  6296. 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))
  6297. {
  6298. //idx_sample=5;
  6299. //sampledValue = NULL;
  6300. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6301. {
  6302. tempIndex = ((gun_index==2) ? 1: 0);
  6303. }
  6304. else
  6305. {
  6306. tempIndex = gun_index;
  6307. }
  6308. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6309. {
  6310. //tempIndex = ((gun_index==2) ? 1: 0);
  6311. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6312. {
  6313. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6314. {
  6315. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6316. }
  6317. }
  6318. }
  6319. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6320. {
  6321. //tempIndex = ((gun_index==2) ? 1: 0);
  6322. for (int index = 0; index < CCS_QUANTITY; index++)
  6323. {
  6324. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6325. {
  6326. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6327. }
  6328. }
  6329. }
  6330. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6331. {
  6332. //tempIndex = ((gun_index==2) ? 1: 0);
  6333. for (int index = 0; index < GB_QUANTITY; index++)
  6334. {
  6335. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6336. {
  6337. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6338. }
  6339. }
  6340. }
  6341. else if(gunType[gun_index] == GUN_TYPE_DO)
  6342. {
  6343. //tempIndex = ((gun_index==2) ? 1: 0);
  6344. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6345. {
  6346. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6347. {
  6348. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6349. }
  6350. }
  6351. }
  6352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6354. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6355. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6356. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6357. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6358. }
  6359. }
  6360. //********************************(7)Current.Import L2************************************************/
  6361. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6362. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6363. (dataType == ReadingContext_Trigger))
  6364. {
  6365. // Only for AC 3 phase
  6366. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6367. {
  6368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6369. {
  6370. tempIndex = 2;
  6371. }
  6372. else
  6373. {
  6374. tempIndex = gun_index;
  6375. }
  6376. for (int index = 0; index < AC_QUANTITY; index++)
  6377. {
  6378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6379. {
  6380. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6381. }
  6382. }
  6383. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6384. }
  6385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6389. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6390. }
  6391. //********************************(8)Current.Import L3************************************************/
  6392. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6393. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6394. (dataType == ReadingContext_Trigger))
  6395. {
  6396. // Only for AC 3 phase
  6397. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  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. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6412. }
  6413. }
  6414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6415. }
  6416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6421. }
  6422. //***********************************************(9)VOLTAGE L2******************************************************/
  6423. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6424. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6425. (dataType == ReadingContext_Trigger))
  6426. {
  6427. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6428. {
  6429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6430. {
  6431. tempIndex = 2;
  6432. }
  6433. else
  6434. {
  6435. tempIndex = gun_index;
  6436. }
  6437. for (int index = 0; index < AC_QUANTITY; index++)
  6438. {
  6439. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6440. {
  6441. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6442. }
  6443. }
  6444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6445. }
  6446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6451. }
  6452. //***********************************************(10)VOLTAGE L3******************************************************/
  6453. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6454. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6455. (dataType == ReadingContext_Trigger))
  6456. {
  6457. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6458. {
  6459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6460. {
  6461. tempIndex = 2;
  6462. }
  6463. else
  6464. {
  6465. tempIndex = gun_index;
  6466. }
  6467. for (int index = 0; index < AC_QUANTITY; index++)
  6468. {
  6469. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6470. {
  6471. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6472. }
  6473. }
  6474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6475. }
  6476. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6481. }
  6482. //***********************************************(11)Current.Offered******************************************************/
  6483. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6484. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6485. (dataType == ReadingContext_Trigger))
  6486. {
  6487. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6488. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6489. {
  6490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6491. {
  6492. tempIndex = ((gun_index==2) ? 1: 0);
  6493. }
  6494. else
  6495. {
  6496. tempIndex = gun_index;
  6497. }
  6498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6499. {
  6500. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6501. {
  6502. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6503. }
  6504. } // END OF FOR CHAdeMO_QUANTITY
  6505. }
  6506. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6507. {
  6508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6509. {
  6510. tempIndex = ((gun_index==2) ? 1: 0);
  6511. }
  6512. else
  6513. {
  6514. tempIndex = gun_index;
  6515. }
  6516. for (int index = 0; index < CCS_QUANTITY; index++)
  6517. {
  6518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6519. {
  6520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6521. }
  6522. } // END OF CCS_QUANTITY
  6523. }
  6524. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6525. {
  6526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6527. {
  6528. tempIndex = ((gun_index==2) ? 1: 0);
  6529. }
  6530. else
  6531. {
  6532. tempIndex = gun_index;
  6533. }
  6534. for (int index = 0; index < GB_QUANTITY; index++)
  6535. {
  6536. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6537. {
  6538. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6539. }
  6540. } // END OF GB_QUANTITY
  6541. }
  6542. else if(gunType[gun_index] == GUN_TYPE_DO)
  6543. {
  6544. tempIndex = gun_index;
  6545. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6546. {
  6547. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6548. {
  6549. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6550. }
  6551. }
  6552. }
  6553. else
  6554. {
  6555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6556. {
  6557. tempIndex = 2;
  6558. }
  6559. else
  6560. {
  6561. tempIndex = gun_index;
  6562. }
  6563. for (int index = 0; index < AC_QUANTITY; index++)
  6564. {
  6565. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6566. {
  6567. uint16_t currentOffer;
  6568. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6569. {
  6570. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6571. }
  6572. else
  6573. {
  6574. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6575. }
  6576. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6577. }
  6578. }
  6579. }
  6580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6585. }
  6586. //***********************************************(12)Power.Offered******************************************************/
  6587. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6588. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6589. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6590. {
  6591. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6592. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6593. {
  6594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6595. {
  6596. tempIndex = ((gun_index==2) ? 1: 0);
  6597. }
  6598. else
  6599. {
  6600. tempIndex = gun_index;
  6601. }
  6602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6603. {
  6604. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6605. {
  6606. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  6607. }
  6608. } // END OF FOR CHAdeMO_QUANTITY
  6609. }
  6610. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6611. {
  6612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6613. {
  6614. tempIndex = ((gun_index==2) ? 1: 0);
  6615. }
  6616. else
  6617. {
  6618. tempIndex = gun_index;
  6619. }
  6620. for (int index = 0; index < CCS_QUANTITY; index++)
  6621. {
  6622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6623. {
  6624. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  6625. }
  6626. } // END OF CCS_QUANTITY
  6627. }
  6628. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6629. {
  6630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6631. {
  6632. tempIndex = ((gun_index==2) ? 1: 0);
  6633. }
  6634. else
  6635. {
  6636. tempIndex = gun_index;
  6637. }
  6638. for (int index = 0; index < GB_QUANTITY; index++)
  6639. {
  6640. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6641. {
  6642. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  6643. }
  6644. } // END OF GB_QUANTITY
  6645. }
  6646. else if(gunType[gun_index] == GUN_TYPE_DO)
  6647. {
  6648. tempIndex = gun_index;
  6649. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6650. {
  6651. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6652. {
  6653. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  6654. }
  6655. }
  6656. }
  6657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6658. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6659. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6662. }
  6663. // Message create ====================================================================================================
  6664. if(TRUE)
  6665. {
  6666. json_object *MeterValueReq = json_object_new_object();
  6667. json_object *MeterValues = json_object_new_array();
  6668. json_object *sampledValues = json_object_new_array();
  6669. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6670. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6671. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6672. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6673. {
  6674. json_object *MeterValue = json_object_new_object();
  6675. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6676. {
  6677. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6678. {
  6679. json_object *sampledValue = json_object_new_object();
  6680. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6681. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6682. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6683. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6684. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6685. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6686. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6687. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6688. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6689. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6690. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6691. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6692. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6693. json_object_array_add(sampledValues, sampledValue);
  6694. }
  6695. }
  6696. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6697. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6698. json_object_array_add(MeterValues, MeterValue);
  6699. }
  6700. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6701. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6702. ,gun_index + 1
  6703. ,MESSAGE_TYPE_CALL
  6704. ,guid
  6705. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6706. json_object_put(MeterValueReq);
  6707. }
  6708. // Put request guid to hash map
  6709. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6710. 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*/)
  6711. {
  6712. result = PASS;
  6713. //DEBUG_INFO("MeterValues mapitem pass\n");
  6714. }
  6715. if((dataType != ReadingContext_Trigger) &&
  6716. (dataType != ReadingContext_Sample_Clock) &&
  6717. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6718. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6719. else
  6720. {
  6721. if(FirstHeartBeat)
  6722. LWS_Send(queuedata +2);
  6723. }
  6724. return result;
  6725. }
  6726. int sendLogStatusNotificationRequest(char *status)
  6727. {
  6728. mtrace();
  6729. int result = PASS;
  6730. char message[4096]={0};
  6731. char guid[37]={0};
  6732. char tempdata[128]={0};
  6733. json_object *LogStatusNotification = json_object_new_object();
  6734. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6735. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6736. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6737. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6738. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6739. random_uuid(guid);
  6740. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6741. json_object_put(LogStatusNotification);
  6742. LWS_Send(message);
  6743. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6744. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6745. {
  6746. result = PASS;
  6747. }
  6748. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6749. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6750. return result;
  6751. }
  6752. int sendSecurityEventNotificationRequest()
  6753. {
  6754. mtrace();
  6755. int result = PASS;
  6756. char message[4096]={0};
  6757. char guid[37]={0};
  6758. char tempdata[128]={0};
  6759. json_object *SecurityEventNotification = json_object_new_object();
  6760. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6761. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6762. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6763. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6764. random_uuid(guid);
  6765. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6766. json_object_put(SecurityEventNotification);
  6767. LWS_Send(message);
  6768. sprintf(tempdata, "SecurityEventNotification,0");
  6769. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6770. {
  6771. result = PASS;
  6772. }
  6773. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6774. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6775. return result;
  6776. }
  6777. int sendSignCertificateRequest()
  6778. {
  6779. mtrace();
  6780. int result = PASS;
  6781. char message[4096]={0};
  6782. char guid[37]={0};
  6783. char tempdata[128]={0};
  6784. json_object *SignCertificate = json_object_new_object();
  6785. DEBUG_INFO("sendSignCertificateRequest...\n");
  6786. // Read csr file content
  6787. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6788. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6789. char *line = NULL;
  6790. size_t len = 0;
  6791. while(getline(&line, &len, fp) != -1)
  6792. {
  6793. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6794. {
  6795. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6796. }
  6797. }
  6798. fclose(fp);
  6799. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6800. random_uuid(guid);
  6801. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6802. json_object_put(SignCertificate);
  6803. LWS_Send(message);
  6804. sprintf(tempdata, "SignCertificate,0");
  6805. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6806. {
  6807. result = PASS;
  6808. }
  6809. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6810. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6811. return result;
  6812. }
  6813. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6814. {
  6815. mtrace();
  6816. int result = PASS;
  6817. char message[110]={0};
  6818. char guid[37]={0};
  6819. char tempdata[65]={0};
  6820. json_object *FirmwareStatusNotification = json_object_new_object();
  6821. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6822. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6823. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6824. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6825. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6826. random_uuid(guid);
  6827. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6828. json_object_put(FirmwareStatusNotification);
  6829. LWS_Send(message);
  6830. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6831. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6832. {
  6833. result = PASS;
  6834. }
  6835. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6836. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6837. return result;
  6838. }
  6839. //==========================================
  6840. // send confirm routine
  6841. //==========================================
  6842. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6843. {
  6844. mtrace();
  6845. int result = FAIL;
  6846. char message[100]={0};
  6847. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6848. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6849. LWS_Send(message);
  6850. result = TRUE;
  6851. return result;
  6852. }
  6853. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6854. {
  6855. mtrace();
  6856. int result = FAIL;
  6857. char message[100]={0};
  6858. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6859. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6860. LWS_Send(message);
  6861. result = TRUE;
  6862. return result;
  6863. }
  6864. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6865. {
  6866. mtrace();
  6867. int result = FAIL;
  6868. char message[100]={0};
  6869. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6870. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6871. LWS_Send(message);
  6872. result = TRUE;
  6873. return result;
  6874. }
  6875. int sendClearCacheConfirmation(char *uuid,char *payload)
  6876. {
  6877. mtrace();
  6878. int result = FAIL;
  6879. char message[500]={0};
  6880. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6881. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6882. LWS_Send(message);
  6883. return result;
  6884. }
  6885. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6886. {
  6887. mtrace();
  6888. int result = FAIL;
  6889. char message[500]={0};
  6890. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6891. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6892. LWS_Send(message);
  6893. return result;
  6894. }
  6895. int sendDataTransferConfirmation(char *uuid,char *payload)
  6896. {
  6897. mtrace();
  6898. char statusStr[20]={0};
  6899. char dataStr[10]={0};
  6900. char sstr[20]={0};
  6901. int c = 0;
  6902. char *loc;
  6903. int result = FAIL;
  6904. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6905. /**********************status**************************/
  6906. loc = strstr(payload, "status");
  6907. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6908. c = 0;
  6909. while (loc[3+strlen("status")+c] != '\"')
  6910. {
  6911. sstr[c] = loc[3+strlen("status")+c];
  6912. c++;
  6913. }
  6914. sstr[c] = '\0';
  6915. strcpy(statusStr, sstr);
  6916. /**********************data**************************/
  6917. loc = strstr(payload, "data");
  6918. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6919. c = 0;
  6920. while (loc[3+strlen("data")+c] != '\"')
  6921. {
  6922. sstr[c] = loc[3+strlen("data")+c];
  6923. c++;
  6924. }
  6925. sstr[c] = '\0';
  6926. strcpy(dataStr, sstr);
  6927. return result;
  6928. }
  6929. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6930. {
  6931. mtrace();
  6932. int result = FAIL;
  6933. char message[1000]={0};
  6934. int CompositeScheduleIndex = 0;
  6935. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6936. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6937. if(nPeriod == 0)
  6938. {
  6939. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6940. {
  6941. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6942. ,MESSAGE_TYPE_CALLRESULT
  6943. ,uuid
  6944. ,payload
  6945. ,connectorIdInt);
  6946. }
  6947. else
  6948. {
  6949. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6950. ,MESSAGE_TYPE_CALLRESULT
  6951. ,uuid
  6952. ,payload
  6953. ,connectorIdInt
  6954. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6955. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6956. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6957. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6958. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6959. }
  6960. }
  6961. else
  6962. {
  6963. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6964. ,MESSAGE_TYPE_CALLRESULT
  6965. ,uuid
  6966. ,payload
  6967. ,connectorIdInt
  6968. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6969. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6970. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6971. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6972. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6973. {
  6974. if (idx_sample == 0)
  6975. {
  6976. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6977. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6978. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6979. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6980. }
  6981. else
  6982. {
  6983. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6984. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6985. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6986. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6987. }
  6988. }
  6989. sprintf(message + strlen(message), "]}}]");
  6990. }
  6991. LWS_Send(message);
  6992. result = TRUE;
  6993. return result;
  6994. }
  6995. int sendGetConfigurationConfirmation(char *uuid)
  6996. {
  6997. mtrace();
  6998. int result = FAIL;
  6999. int MaxKeySupported = 0;
  7000. int sentConfigurationNumber= 0;
  7001. int sentunConfigurationNumber= 0;
  7002. char message[1024*10]={0};
  7003. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7004. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7005. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7006. ,MESSAGE_TYPE_CALLRESULT
  7007. ,uuid );
  7008. //configuration key
  7009. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7010. {
  7011. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7012. {
  7013. if (sentConfigurationNumber == 0)
  7014. {
  7015. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7016. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7017. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7018. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7019. }
  7020. else
  7021. {
  7022. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7023. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7024. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7025. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7026. }
  7027. sentConfigurationNumber = sentConfigurationNumber + 1;
  7028. }
  7029. }
  7030. sprintf(message + strlen(message), "]");
  7031. if(UnknownKeynum != 0)
  7032. {
  7033. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7034. //unkown key
  7035. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7036. {
  7037. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7038. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7039. if(sentunConfigurationNumber == 0)
  7040. {
  7041. sprintf(message + strlen(message), "\"%s\""
  7042. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7043. }
  7044. else
  7045. {
  7046. sprintf(message + strlen(message), ",\"%s\""
  7047. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7048. }
  7049. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7050. }
  7051. sprintf(message + strlen(message), "]");
  7052. }
  7053. sprintf(message + strlen(message), "}]");
  7054. LWS_Send(message);
  7055. return result;
  7056. }
  7057. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7058. {
  7059. mtrace();
  7060. int result = FAIL;
  7061. char message[400]={0};
  7062. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7063. if(strcmp(payload,"")==0)
  7064. {
  7065. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7066. }
  7067. else
  7068. {
  7069. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7070. }
  7071. LWS_Send(message);
  7072. result = TRUE;
  7073. return result;
  7074. }
  7075. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7076. {
  7077. mtrace();
  7078. int result = FAIL;
  7079. char message[80]={0};
  7080. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7081. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7082. LWS_Send(message);
  7083. result = TRUE;
  7084. return result;
  7085. }
  7086. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7087. {
  7088. mtrace();
  7089. int result = FAIL;
  7090. char message[80]={0};
  7091. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7092. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7093. LWS_Send(message);
  7094. result = TRUE;
  7095. return result;
  7096. }
  7097. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7098. {
  7099. mtrace();
  7100. int result = FAIL;
  7101. char message[80]={0};
  7102. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7103. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7104. LWS_Send(message);
  7105. result = TRUE;
  7106. return result;
  7107. }
  7108. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7109. {
  7110. mtrace();
  7111. int result = FAIL;
  7112. char message[80]={0};
  7113. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7114. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7115. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7116. LWS_Send(message);
  7117. result = TRUE;
  7118. return result;
  7119. }
  7120. int sendResetConfirmation(char *uuid,char *payload)
  7121. {
  7122. mtrace();
  7123. int result = FAIL;
  7124. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7125. char message[80]={0};
  7126. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7127. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7128. LWS_Send(message);
  7129. result = TRUE;
  7130. return result;
  7131. }
  7132. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7133. {
  7134. mtrace();
  7135. int result = FAIL;
  7136. char message[500]={0};
  7137. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7138. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7139. LWS_Send(message);
  7140. result = TRUE;
  7141. return result;
  7142. }
  7143. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7144. {
  7145. mtrace();
  7146. int result = FAIL;
  7147. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7148. char message[80]={0};
  7149. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7150. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7151. LWS_Send(message);
  7152. result = TRUE;
  7153. return result;
  7154. }
  7155. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7156. {
  7157. mtrace();
  7158. int result = FAIL;
  7159. char message[80]={0};
  7160. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7161. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7162. LWS_Send(message);
  7163. result = TRUE;
  7164. return result;
  7165. }
  7166. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7167. {
  7168. mtrace();
  7169. int result = FAIL;
  7170. char message[80]={0};
  7171. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7172. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7173. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7174. LWS_Send(message);
  7175. result = TRUE;
  7176. return result;
  7177. }
  7178. int sendUpdateFirmwareConfirmation(char *uuid)
  7179. {
  7180. mtrace();
  7181. int result = FAIL;
  7182. char message[60]={0};
  7183. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7184. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7185. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7186. LWS_Send(message);
  7187. result = TRUE;
  7188. return result;
  7189. }
  7190. int sendCertificateSignedConfirmation(char *uuid)
  7191. {
  7192. mtrace();
  7193. int result = PASS;
  7194. char message[4096]={0};
  7195. json_object *CertificateSigned = json_object_new_object();
  7196. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7197. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7198. sprintf(message,"[%d,\"%s\",%s]"
  7199. ,MESSAGE_TYPE_CALLRESULT
  7200. ,uuid
  7201. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7202. json_object_put(CertificateSigned);
  7203. LWS_Send(message);
  7204. return result;
  7205. }
  7206. int sendDeleteCertificateConfirmation(char *uuid)
  7207. {
  7208. mtrace();
  7209. int result = PASS;
  7210. char message[4096]={0};
  7211. json_object *DeleteCertificate = json_object_new_object();
  7212. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7213. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7214. sprintf(message,"[%d,\"%s\",%s]"
  7215. ,MESSAGE_TYPE_CALLRESULT
  7216. ,uuid
  7217. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7218. json_object_put(DeleteCertificate);
  7219. LWS_Send(message);
  7220. return result;
  7221. }
  7222. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7223. {
  7224. mtrace();
  7225. int result = PASS;
  7226. char message[4096]={0};
  7227. json_object *ExtendedTriggerMessage = json_object_new_object();
  7228. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7229. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7230. sprintf(message,"[%d,\"%s\",%s]"
  7231. ,MESSAGE_TYPE_CALLRESULT
  7232. ,uuid
  7233. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7234. json_object_put(ExtendedTriggerMessage);
  7235. LWS_Send(message);
  7236. return result;
  7237. }
  7238. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7239. {
  7240. mtrace();
  7241. int result = PASS;
  7242. char message[4096]={0};
  7243. json_object *GetInstalledCertificateIds = json_object_new_object();
  7244. json_object *certificateHashDataDatas = json_object_new_array();
  7245. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7246. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7247. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7248. {
  7249. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7250. {
  7251. json_object *certificateHashData = json_object_new_object();
  7252. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7253. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7254. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7255. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7256. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7257. }
  7258. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7259. }
  7260. else
  7261. {
  7262. json_object_put(certificateHashDataDatas);
  7263. }
  7264. sprintf(message,"[%d,\"%s\",%s]"
  7265. ,MESSAGE_TYPE_CALLRESULT
  7266. ,uuid
  7267. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7268. json_object_put(GetInstalledCertificateIds);
  7269. LWS_Send(message);
  7270. return result;
  7271. }
  7272. int sendGetLogConfirmation(char *uuid)
  7273. {
  7274. mtrace();
  7275. int result = PASS;
  7276. char message[4096]={0};
  7277. json_object *GetLog = json_object_new_object();
  7278. DEBUG_INFO("sendGetLogConfirmation...\n");
  7279. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7280. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7281. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7282. sprintf(message,"[%d,\"%s\",%s]"
  7283. ,MESSAGE_TYPE_CALLRESULT
  7284. ,uuid
  7285. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7286. json_object_put(GetLog);
  7287. LWS_Send(message);
  7288. return result;
  7289. }
  7290. int sendInstallCertificateConfirmation(char *uuid)
  7291. {
  7292. mtrace();
  7293. int result = PASS;
  7294. char message[4096]={0};
  7295. json_object *InstallCertificate = json_object_new_object();
  7296. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7297. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7298. sprintf(message,"[%d,\"%s\",%s]"
  7299. ,MESSAGE_TYPE_CALLRESULT
  7300. ,uuid
  7301. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7302. json_object_put(InstallCertificate);
  7303. LWS_Send(message);
  7304. return result;
  7305. }
  7306. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7307. {
  7308. mtrace();
  7309. int result = PASS;
  7310. char message[4096]={0};
  7311. json_object *SignedUpdateFirmware = json_object_new_object();
  7312. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7313. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7314. sprintf(message,"[%d,\"%s\",%s]"
  7315. ,MESSAGE_TYPE_CALLRESULT
  7316. ,uuid
  7317. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7318. json_object_put(SignedUpdateFirmware);
  7319. LWS_Send(message);
  7320. return result;
  7321. }
  7322. int sendUnknownConfirmation(char *uuid)
  7323. {
  7324. mtrace();
  7325. int result = PASS;
  7326. char message[256]={0};
  7327. DEBUG_INFO("sendUnknownConfirmation...\n");
  7328. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7329. LWS_Send(message);
  7330. return result;
  7331. }
  7332. //==========================================
  7333. // Handle server request routine Start
  7334. //==========================================
  7335. int handleCancelReservationRequest(char *uuid, char *payload)
  7336. {
  7337. mtrace();
  7338. int result = FAIL;
  7339. int gunNO = 0;
  7340. int reservationIdInt = -1;
  7341. char comfirmstr[20];
  7342. DEBUG_INFO("handleCancelReservationRequest...\n");
  7343. json_object *CancelReservation;
  7344. CancelReservation = json_tokener_parse(payload);
  7345. if(!is_error(CancelReservation))
  7346. {
  7347. // Required data
  7348. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7349. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7350. }
  7351. json_object_put(CancelReservation);
  7352. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7353. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7354. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7355. if(reservationIdInt != -1)
  7356. {
  7357. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7358. //check Transaction active
  7359. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7360. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7361. {
  7362. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7363. {
  7364. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7365. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7366. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7367. {
  7368. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7369. }
  7370. else
  7371. {
  7372. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7373. }
  7374. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7375. goto end;
  7376. }
  7377. }
  7378. for (int index = 0; index < CCS_QUANTITY; index++)
  7379. {
  7380. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7381. {
  7382. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7383. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7384. if(gunType[2] == GUN_TYPE_CCS)
  7385. {
  7386. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7387. }
  7388. else
  7389. {
  7390. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7391. }
  7392. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7393. goto end;
  7394. }
  7395. }
  7396. for (int index = 0; index < GB_QUANTITY; index++)
  7397. {
  7398. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7399. {
  7400. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7401. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7402. if(gunType[2] == GUN_TYPE_GBT)
  7403. {
  7404. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7405. }
  7406. else
  7407. {
  7408. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7409. }
  7410. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7411. goto end;
  7412. }
  7413. }
  7414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7415. {
  7416. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7417. {
  7418. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7419. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7420. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7421. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7422. goto end;
  7423. }
  7424. }
  7425. for (int index = 0; index < AC_QUANTITY; index++)
  7426. {
  7427. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7428. {
  7429. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7430. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7432. {
  7433. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7434. }
  7435. else
  7436. {
  7437. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7438. }
  7439. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7440. goto end;
  7441. }
  7442. }
  7443. }
  7444. //The reservationId does NOT match the reservationId
  7445. sendCancelReservationConfirmation(uuid, comfirmstr);
  7446. end:
  7447. // Fill in ocpp packet uuid
  7448. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7449. return result;
  7450. }
  7451. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7452. {
  7453. mtrace();
  7454. int result = FAIL;
  7455. int gunIndex = 0;
  7456. char typeStr[16]={0};
  7457. char comfirmstr[20];
  7458. int specificId = FALSE;
  7459. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7460. json_object *ChangeAvailability;
  7461. ChangeAvailability = json_tokener_parse(payload);
  7462. if(!is_error(ChangeAvailability))
  7463. {
  7464. // Required data
  7465. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7466. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7467. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7468. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7469. }
  7470. json_object_put(ChangeAvailability);
  7471. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7472. {
  7473. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7474. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7475. }
  7476. else if(gunIndex == 0)
  7477. {
  7478. for(int i=0; i < gunTotalNumber; i++)
  7479. {
  7480. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7481. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7482. }
  7483. }
  7484. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7486. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7487. {
  7488. specificId = TRUE;
  7489. }
  7490. if(specificId == FALSE)
  7491. goto end;
  7492. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7493. {
  7494. //----------------------gunIndex is 0 ------------------------------------------------//
  7495. if(gunIndex == 0)
  7496. {
  7497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7498. {
  7499. for(int i=0; i < gunTotalNumber; i++)
  7500. {
  7501. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7502. {
  7503. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7504. {
  7505. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7506. {
  7507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7508. goto end;
  7509. }
  7510. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7511. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7512. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7513. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7514. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7515. {
  7516. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7517. goto end;
  7518. }
  7519. }
  7520. }//END FOR CHAdeMO_QUANTITY
  7521. for (int index = 0; index < CCS_QUANTITY; index++)
  7522. {
  7523. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7524. {
  7525. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7526. {
  7527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7528. goto end;
  7529. }
  7530. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7531. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7532. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7533. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7534. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7535. {
  7536. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7537. goto end;
  7538. }
  7539. }
  7540. }//END FOR CCS_QUANTITY
  7541. for (int index = 0; index < GB_QUANTITY; index++)
  7542. {
  7543. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7544. {
  7545. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7546. {
  7547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7548. goto end;
  7549. }
  7550. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7551. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7552. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7553. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7554. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7555. {
  7556. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7557. goto end;
  7558. }
  7559. }
  7560. }// END FOR GB_QUANTITY
  7561. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7562. {
  7563. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7564. {
  7565. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7566. {
  7567. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7568. goto end;
  7569. }
  7570. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7571. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7572. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7573. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7574. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7575. {
  7576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7577. goto end;
  7578. }
  7579. }
  7580. }// END FOR GENERAL_GUN_QUANTITY
  7581. for (int index = 0; index < AC_QUANTITY; index++)
  7582. {
  7583. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7584. {
  7585. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7586. {
  7587. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7588. goto end;
  7589. }
  7590. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7591. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7592. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7593. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7594. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7595. {
  7596. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7597. goto end;
  7598. }
  7599. }
  7600. }//END FOR AC_QUANTITY
  7601. }// END FOR gunTotalNumber
  7602. }
  7603. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7604. {
  7605. for(int i=0; i < gunTotalNumber; i++)
  7606. {
  7607. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7608. {
  7609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7610. goto end;
  7611. }
  7612. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7613. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7614. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7615. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7616. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7617. {
  7618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7619. goto end;
  7620. }
  7621. }
  7622. }
  7623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7624. goto end;
  7625. }
  7626. //----------------------gunIndex is not 0 ------------------------------------------------//
  7627. //check Transaction active
  7628. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7629. {
  7630. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7631. {
  7632. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7633. {
  7634. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7635. goto end;
  7636. }
  7637. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7638. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7639. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7640. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7641. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7642. {
  7643. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7644. goto end;
  7645. }
  7646. else
  7647. {
  7648. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7650. goto end;
  7651. }
  7652. }
  7653. }//END FOR CHAdeMO_QUANTITY
  7654. for (int index = 0; index < CCS_QUANTITY; index++)
  7655. {
  7656. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7657. {
  7658. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7659. {
  7660. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7661. goto end;
  7662. }
  7663. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7664. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7665. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7666. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7667. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7668. {
  7669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7670. goto end;
  7671. }
  7672. else
  7673. {
  7674. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7675. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7676. goto end;
  7677. }
  7678. }
  7679. }//END FOR CCS_QUANTITY
  7680. for (int index = 0; index < GB_QUANTITY; index++)
  7681. {
  7682. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7683. {
  7684. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7685. {
  7686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7687. goto end;
  7688. }
  7689. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7690. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7691. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7692. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7693. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7694. {
  7695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7696. goto end;
  7697. }
  7698. else
  7699. {
  7700. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7701. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7702. goto end;
  7703. }
  7704. }
  7705. }// END FOR GB_QUANTITY
  7706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7707. {
  7708. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7709. {
  7710. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7711. {
  7712. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7713. goto end;
  7714. }
  7715. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7716. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7717. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7718. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7719. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7720. {
  7721. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7722. goto end;
  7723. }
  7724. else
  7725. {
  7726. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7727. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7728. goto end;
  7729. }
  7730. }
  7731. }// END FOR GENERAL_GUN_QUANTITY
  7732. for (int index = 0; index < AC_QUANTITY; index++)
  7733. {
  7734. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7735. {
  7736. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7737. {
  7738. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7739. goto end;
  7740. }
  7741. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7742. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7743. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7744. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7745. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7746. {
  7747. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7748. goto end;
  7749. }
  7750. else
  7751. {
  7752. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7753. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7754. goto end;
  7755. }
  7756. }
  7757. }//END FOR AC_QUANTITY
  7758. }//END FOR AvailabilityTypeStr[Inoperative]
  7759. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7760. {
  7761. //----------------------gunIndex is 0 ------------------------------------------------//
  7762. if(gunIndex == 0)
  7763. {
  7764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7765. {
  7766. for(int i=0; i < gunTotalNumber; i++)
  7767. {
  7768. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7769. {
  7770. 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
  7771. {
  7772. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7773. goto end;
  7774. }
  7775. }//END FOR CHAdeMO_QUANTITY
  7776. for (int index = 0; index < CCS_QUANTITY; index++)
  7777. {
  7778. 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
  7779. {
  7780. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7781. goto end;
  7782. }
  7783. }//END FOR CCS_QUANTITY
  7784. for (int index = 0; index < GB_QUANTITY; index++)
  7785. {
  7786. 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
  7787. {
  7788. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7789. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7790. goto end;
  7791. }
  7792. }// END FOR GB_QUANTITY
  7793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7794. {
  7795. 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
  7796. {
  7797. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7798. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7799. goto end;
  7800. }
  7801. }// END FOR GENERAL_GUN_QUANTITY
  7802. for (int index = 0; index < AC_QUANTITY; index++)
  7803. {
  7804. 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
  7805. {
  7806. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7807. goto end;
  7808. }
  7809. }//END FOR CHAdeMO_QUANTITY
  7810. }// END FOR gunTotalNumber
  7811. }
  7812. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7813. {
  7814. for(int i=0; i < gunTotalNumber; i++)
  7815. {
  7816. for (int index = 0; index < AC_QUANTITY; index++)
  7817. {
  7818. 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
  7819. {
  7820. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7821. goto end;
  7822. }
  7823. }//END FOR CHAdeMO_QUANTITY
  7824. } // END FOR gunTotalNumber
  7825. }
  7826. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7827. goto end;
  7828. }
  7829. //----------------------gunIndex is not 0 ------------------------------------------------//
  7830. //check Transaction active
  7831. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7832. {
  7833. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7834. {
  7835. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7836. goto end;
  7837. }
  7838. }//END FOR CHAdeMO_QUANTITY
  7839. for (int index = 0; index < CCS_QUANTITY; index++)
  7840. {
  7841. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7842. {
  7843. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7844. goto end;
  7845. }
  7846. }//END FOR CCS_QUANTITY
  7847. for (int index = 0; index < GB_QUANTITY; index++)
  7848. {
  7849. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7850. {
  7851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7852. goto end;
  7853. }
  7854. }// END FOR GB_QUANTITY
  7855. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7856. {
  7857. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7858. {
  7859. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7860. goto end;
  7861. }
  7862. }// END FOR GENERAL_GUN_QUANTITY
  7863. for (int index = 0; index < AC_QUANTITY; index++)
  7864. {
  7865. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7866. {
  7867. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7868. goto end;
  7869. }
  7870. }//END FOR AC_QUANTITY
  7871. }//END FOR AvailabilityTypeStr[Operative]
  7872. end:
  7873. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7874. {
  7875. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7876. }
  7877. else
  7878. {
  7879. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7880. }
  7881. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7882. {
  7883. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7884. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7885. }
  7886. else if(gunIndex == 0)
  7887. {
  7888. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7889. {
  7890. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7891. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7892. }
  7893. }
  7894. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7895. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7896. return result;
  7897. }
  7898. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7899. {
  7900. mtrace();
  7901. int result = FAIL;
  7902. char keystr[40]={0};
  7903. char valuestr[256]={0};
  7904. char comfirmstr[20]={0};
  7905. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7906. json_object *ChangeConfiguration;
  7907. ChangeConfiguration = json_tokener_parse(payload);
  7908. if(!is_error(ChangeConfiguration))
  7909. {
  7910. // Required data
  7911. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7912. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7913. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7914. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7915. }
  7916. json_object_put(ChangeConfiguration);
  7917. if((uuid==NULL) || (payload ==NULL) )
  7918. {
  7919. DEBUG_ERROR("Payload is null\n");
  7920. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7921. }
  7922. else
  7923. {
  7924. int status = setKeyValue(keystr, valuestr);
  7925. switch(status)
  7926. {
  7927. case ConfigurationStatus_Accepted:
  7928. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7929. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7930. StoreConfigurationTable();
  7931. break;
  7932. case RebootRequired:
  7933. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7934. StoreConfigurationTable();
  7935. break;
  7936. case NotSupported:
  7937. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7938. break;
  7939. case ConfigurationStatus_Rejected:
  7940. default:
  7941. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7942. break;
  7943. }
  7944. }
  7945. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7946. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7947. if((strcmp(keystr,"WebSocketPingInterval")==0) && (strcmp(comfirmstr,"Accepted")==0))
  7948. {
  7949. ChageWebSocketPingInterval(atoi(valuestr));
  7950. }
  7951. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7952. {
  7953. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7954. SetOcppConnStatus(FALSE);
  7955. }
  7956. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7957. {
  7958. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7959. }
  7960. return result;
  7961. }
  7962. int handleClearCacheRequest(char *uuid, char *payload)
  7963. {
  7964. mtrace();
  7965. int result = FAIL;
  7966. char comfirmstr[20];
  7967. char rmFileCmd[100]={0};
  7968. struct stat stats;
  7969. DEBUG_INFO("handleClearCacheRequest...\n");
  7970. stat("/Storage/OCPP", &stats);
  7971. // Check for directory existence
  7972. if (S_ISDIR(stats.st_mode) == 1)
  7973. {}
  7974. else
  7975. {
  7976. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7977. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7978. system(rmFileCmd);
  7979. }
  7980. if(OCPP_cleanLocalCache())
  7981. {
  7982. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7983. }
  7984. else
  7985. {
  7986. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7987. }
  7988. sendClearCacheConfirmation(uuid, comfirmstr);
  7989. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7990. return result;
  7991. }
  7992. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7993. {
  7994. mtrace();
  7995. int result = FAIL;
  7996. int resultRename;
  7997. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7998. char chargingProfilePurposeStr[26]={0};
  7999. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8000. char tempchargingProfilePurposeStr[26]={0};
  8001. char str[100]={0};
  8002. char fname[200]={0};
  8003. char comfirmstr[20]={0};
  8004. char word[1600]={0};
  8005. int clearflag = FALSE;
  8006. int chargingProfileIdIsNULL = FALSE;
  8007. int connectorIsNULL = FALSE;
  8008. int chargingProfilePurposeIsNULL = FALSE;
  8009. int stackLevelIsNULL = FALSE;
  8010. //int GotoEnd = FALSE;
  8011. FILE *fptr1, *fptr2;
  8012. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8013. int n_chargingProfile=0;
  8014. int isEmptyFile = FALSE;
  8015. char sLineWord[1600]={0};
  8016. char chargingProfiles[10][100]={0};
  8017. int ChargeProfileCount = 0;
  8018. int ch;
  8019. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8020. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8021. json_object *ClearChargingProfile;
  8022. ClearChargingProfile = json_tokener_parse(payload);
  8023. if(!is_error(ClearChargingProfile))
  8024. {
  8025. // Optional data
  8026. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8027. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8028. else
  8029. chargingProfileIdIsNULL = TRUE;
  8030. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8031. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8032. else
  8033. connectorIsNULL = TRUE;
  8034. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8035. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8036. else
  8037. chargingProfilePurposeIsNULL = TRUE;
  8038. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8039. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8040. else
  8041. stackLevelIsNULL = TRUE;
  8042. }
  8043. json_object_put(ClearChargingProfile);
  8044. if(connectorIsNULL == FALSE)
  8045. {
  8046. switch(connectorIdInt)
  8047. {
  8048. case 0:
  8049. if(chargingProfilePurposeIsNULL == TRUE)
  8050. {
  8051. int l = 0;
  8052. strcpy(fname, ChargePointMaxProfile_JSON);
  8053. if((access(fname,F_OK))!=-1)
  8054. {
  8055. strcpy(chargingProfiles[l], fname);
  8056. l = l + 1;
  8057. }
  8058. strcpy(fname, TxDefaultProfile_0_JSON);
  8059. if((access(fname,F_OK))!=-1)
  8060. {
  8061. strcpy(chargingProfiles[l], fname);
  8062. l = l + 1;
  8063. }
  8064. ChargeProfileCount = l;
  8065. }
  8066. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8067. {
  8068. strcpy(fname, ChargePointMaxProfile_JSON);
  8069. if((access(fname,F_OK))!=-1)
  8070. {
  8071. strcpy(chargingProfiles[0], fname);
  8072. ChargeProfileCount = 1;
  8073. }
  8074. }
  8075. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8076. {
  8077. strcpy(fname, TxDefaultProfile_0_JSON);
  8078. if((access(fname,F_OK))!=-1)
  8079. {
  8080. strcpy(chargingProfiles[0], fname);
  8081. ChargeProfileCount = 1;
  8082. }
  8083. }
  8084. break;
  8085. default:
  8086. if(chargingProfilePurposeIsNULL == TRUE)
  8087. {
  8088. int m = 0;
  8089. memset(fname, 0, ARRAY_SIZE(fname));
  8090. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8091. if((access(fname,F_OK))!=-1)
  8092. {
  8093. strcpy(chargingProfiles[m], fname);
  8094. m = m + 1;
  8095. }
  8096. memset(fname, 0, ARRAY_SIZE(fname));
  8097. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8098. if((access(fname,F_OK))!=-1)
  8099. {
  8100. strcpy(chargingProfiles[m], fname);
  8101. m = m + 1;
  8102. }
  8103. ChargeProfileCount = m;
  8104. }
  8105. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8106. {
  8107. //strcpy(fname, TxDefaultProfile_1_JSON);
  8108. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8109. if((access(fname,F_OK))!=-1)
  8110. {
  8111. strcpy(chargingProfiles[0], fname);
  8112. ChargeProfileCount = 1;
  8113. }
  8114. }
  8115. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8116. {
  8117. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8118. if((access(fname,F_OK))!=-1)
  8119. {
  8120. strcpy(chargingProfiles[0], fname);
  8121. ChargeProfileCount = 1;
  8122. }
  8123. //strcpy(fname, TxProfile_1_JSON);
  8124. }
  8125. //strcpy(fname, ChargePointMaxProfile_JSON );
  8126. break;
  8127. }
  8128. }
  8129. else // Check all Charging Profiles
  8130. {
  8131. int i = 0;
  8132. char fnametemp[200]={0};
  8133. ChargeProfileCount = 0;
  8134. //Check ChargePointMaxProfile.json exit
  8135. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8136. {
  8137. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8138. i = i + 1;
  8139. }
  8140. //Check TxDefaultProfile_0.json exit
  8141. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8142. {
  8143. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8144. i = i + 1;
  8145. }
  8146. //Check TxDefaultProfile_%d.json
  8147. for(int j=1; j <= gunTotalNumber; j++)
  8148. {
  8149. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8150. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8151. if((access(fnametemp,F_OK))!=-1)
  8152. {
  8153. strcpy(chargingProfiles[i], fnametemp);
  8154. i = i + 1;
  8155. }
  8156. }
  8157. //Check TxProfile_%d.json
  8158. for(int j=1; j <= gunTotalNumber; j++)
  8159. {
  8160. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8161. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8162. if((access(fnametemp,F_OK))!=-1)
  8163. {
  8164. strcpy(chargingProfiles[i], fnametemp);
  8165. i = i + 1;
  8166. }
  8167. }
  8168. ChargeProfileCount = i;
  8169. }// End connectorIsNULL is TRUE
  8170. if(ChargeProfileCount == 0)
  8171. {
  8172. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8173. goto end;
  8174. }
  8175. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8176. {
  8177. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8178. goto end;
  8179. }
  8180. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8181. {
  8182. memset(str, 0, ARRAY_SIZE(str));
  8183. // clear temp file
  8184. sprintf(str,"rm -f %s",temp);
  8185. system(str);
  8186. for(int k=0; k < ChargeProfileCount; k++)
  8187. {
  8188. memset(str, 0, ARRAY_SIZE(str));
  8189. //clear file in C
  8190. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8191. system(str);
  8192. }
  8193. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8194. goto end;
  8195. }
  8196. else if(connectorIsNULL == TRUE)
  8197. {
  8198. for(int k=0; k < ChargeProfileCount; k++)
  8199. {
  8200. fptr1 = fopen(chargingProfiles[k], "r");
  8201. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8202. //Check Charging Profile Count
  8203. while(fscanf(fptr1, "%s", word) != EOF)
  8204. {
  8205. //DEBUG_INFO("word=%s\n",word);
  8206. if(strstr(word, "chargingProfileId")!= NULL)
  8207. {
  8208. //DEBUG_INFO("test chargingProfileId \n");
  8209. n_chargingProfile = n_chargingProfile + 1;
  8210. //DEBUG_INFO("chargingProfileId Found\n");
  8211. }
  8212. }
  8213. rewind(fptr1);
  8214. //search Charging Profile Element
  8215. //int i= 0;
  8216. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8217. {
  8218. json_object *tmpProfilee;
  8219. tmpProfilee = json_tokener_parse(sLineWord);
  8220. if(!is_error(tmpProfilee))
  8221. {
  8222. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8223. {
  8224. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8225. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8226. }
  8227. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8228. {
  8229. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8230. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8231. }
  8232. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8233. {
  8234. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8235. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8236. }
  8237. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8238. {
  8239. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8240. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8241. }
  8242. }
  8243. json_object_put(tmpProfilee);
  8244. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8245. {
  8246. //------- not write to fptr2-------//
  8247. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8248. //clearflag = TRUE;
  8249. }
  8250. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8251. {
  8252. //------- not write to fptr2-------//
  8253. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8254. }
  8255. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8256. {
  8257. //------- not write to fptr2-------//
  8258. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8259. }
  8260. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8261. {
  8262. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8263. }
  8264. else
  8265. {
  8266. fprintf(fptr2, sLineWord);//writing data into file
  8267. }
  8268. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8269. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8270. if(clearflag == TRUE)
  8271. {
  8272. fclose(fptr1);
  8273. fclose(fptr2);
  8274. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8275. system(str);
  8276. // clear temp file
  8277. sprintf(str,"rm -f %s",temp);
  8278. system(str);
  8279. }
  8280. else
  8281. {
  8282. fclose(fptr1);
  8283. fclose(fptr2);
  8284. memset(str, 0, ARRAY_SIZE(str));
  8285. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8286. system(str);
  8287. resultRename = rename(temp, chargingProfiles[k]);
  8288. if(resultRename == 0)
  8289. {
  8290. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8291. }
  8292. else
  8293. {
  8294. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8295. }
  8296. if(comfirmstr[0]== 0)
  8297. {
  8298. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8299. }
  8300. //Check chargingProfile is empty file
  8301. /*------ Read the file ----------------*/
  8302. fptr1=fopen(chargingProfiles[k],"r");
  8303. ch=fgetc(fptr1);
  8304. rewind(fptr1);
  8305. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8306. if(ch!=EOF)
  8307. {
  8308. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8309. {
  8310. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8311. if(sLineWord[0]=='\0')
  8312. {
  8313. isEmptyFile = TRUE;
  8314. break;
  8315. }
  8316. else
  8317. {
  8318. isEmptyFile = FALSE;
  8319. break;
  8320. }
  8321. }
  8322. }
  8323. else
  8324. isEmptyFile = TRUE;
  8325. fclose(fptr1);
  8326. if(isEmptyFile == TRUE)
  8327. {
  8328. memset(str, 0, ARRAY_SIZE(str));
  8329. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8330. system(str);
  8331. }
  8332. }
  8333. }// End of while(int k=0; k < ChargePointCount; k++)
  8334. }
  8335. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8336. {
  8337. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8338. for(int k=0; k < ChargeProfileCount; k++)
  8339. {
  8340. fptr1 = fopen(chargingProfiles[k], "r");
  8341. fptr2 = fopen(temp, "w+");
  8342. //Check Charging Profile Count
  8343. while(fscanf(fptr1, "%s", word) != EOF)
  8344. {
  8345. //DEBUG_INFO("word=%s\n",word);
  8346. if(strstr(word, "chargingProfileId")!= NULL)
  8347. {
  8348. n_chargingProfile = n_chargingProfile + 1;
  8349. }
  8350. }
  8351. rewind(fptr1);
  8352. //search Charging Profile Element
  8353. //int i= 0;
  8354. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8355. {
  8356. json_object *tmpProfilee;
  8357. tmpProfilee = json_tokener_parse(sLineWord);
  8358. if(!is_error(tmpProfilee))
  8359. {
  8360. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8361. {
  8362. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8363. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8364. }
  8365. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8366. {
  8367. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8368. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8369. }
  8370. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8371. {
  8372. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8373. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8374. }
  8375. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8376. {
  8377. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8378. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8379. }
  8380. }
  8381. json_object_put(tmpProfilee);
  8382. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8383. {
  8384. //------- not write to fptr2-------//
  8385. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8386. //clearflag = TRUE;
  8387. }
  8388. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8389. {
  8390. //------- not write to fptr2-------//
  8391. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8392. }
  8393. else if(stackLevelIsNULL == TRUE)
  8394. {
  8395. //Clear Whole File
  8396. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8397. clearflag = TRUE;
  8398. break;
  8399. }
  8400. else
  8401. {
  8402. fprintf(fptr2, sLineWord);//writing data into file
  8403. }
  8404. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8405. }
  8406. if(clearflag == TRUE)
  8407. {
  8408. fclose(fptr1);
  8409. fclose(fptr2);
  8410. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8411. system(str);
  8412. // clear temp file
  8413. sprintf(str,"rm -f %s",temp);
  8414. system(str);
  8415. }
  8416. else
  8417. {
  8418. fclose(fptr1);
  8419. fclose(fptr2);
  8420. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8421. system(str);
  8422. resultRename = rename(temp, chargingProfiles[k]);
  8423. if(resultRename == 0)
  8424. {
  8425. DEBUG_INFO("File ChargingProfile renamed successfully");
  8426. }
  8427. else
  8428. {
  8429. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8430. }
  8431. if(comfirmstr[0]== 0)
  8432. {
  8433. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8434. }
  8435. //Check chargingProfile is empty file
  8436. /*------ Read the file ----------------*/
  8437. fptr1=fopen(chargingProfiles[k],"r");
  8438. ch=fgetc(fptr1);
  8439. rewind(fptr1);
  8440. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8441. if(ch!=EOF)
  8442. {
  8443. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8444. {
  8445. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8446. if(sLineWord[0]=='\0')
  8447. {
  8448. isEmptyFile = TRUE;
  8449. break;
  8450. }
  8451. else
  8452. {
  8453. isEmptyFile = FALSE;
  8454. break;
  8455. }
  8456. }
  8457. }
  8458. else
  8459. isEmptyFile = TRUE;
  8460. fclose(fptr1);
  8461. if(isEmptyFile == TRUE)
  8462. {
  8463. memset(str, 0, ARRAY_SIZE(str));
  8464. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8465. system(str);
  8466. }
  8467. /*------- End of reading ---------------*/
  8468. }
  8469. } // while(int k=0; k < ChargeProfileCount; k++)
  8470. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8471. end:
  8472. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8473. {
  8474. if(connectorIdInt == 0)
  8475. {
  8476. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8477. {
  8478. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8479. }
  8480. }
  8481. else
  8482. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8483. }
  8484. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8485. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8486. return result;
  8487. }
  8488. void createFirmwareVersionByDataTransfer(void)
  8489. {
  8490. json_object *FirmwareDataTransfer = json_object_new_object();
  8491. // AC & DC model
  8492. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8493. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8494. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8495. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8496. // DC model
  8497. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8498. {
  8499. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8500. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8501. (gunType[3] != GUN_TYPE_UNKNOWN))
  8502. {
  8503. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8504. }
  8505. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8506. {
  8507. // DS DM DW
  8508. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8509. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8510. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8511. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8512. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8513. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8514. }
  8515. else
  8516. {
  8517. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8518. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8519. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8520. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8521. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8522. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8523. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8524. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8525. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8526. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8527. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8528. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8529. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8530. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8531. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8532. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8533. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8534. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8535. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8536. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8537. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8538. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8539. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8540. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8541. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8542. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8543. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8544. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8545. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8546. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8547. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8548. }
  8549. }
  8550. // 4G model
  8551. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8552. {
  8553. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8554. }
  8555. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8556. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8557. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8558. json_object_put(FirmwareDataTransfer);
  8559. }
  8560. int handleDataTransferRequest(char *uuid, char *payload)
  8561. {
  8562. mtrace();
  8563. json_object *response = json_object_new_object();
  8564. int result = FAIL;
  8565. char tempvendorId[255]={0};
  8566. char tempmessageId[50]={0};
  8567. char tempdata[512]={0};
  8568. char message[2048]={0};
  8569. DEBUG_INFO("handleDataTransferRequest...\n");
  8570. if((uuid != NULL) && (payload != NULL))
  8571. {
  8572. json_object *DataTransfer;
  8573. DataTransfer = json_tokener_parse(payload);
  8574. if(!is_error(DataTransfer))
  8575. {
  8576. // Required data
  8577. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8578. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8579. // Optional data
  8580. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8581. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8582. if(json_object_object_get(DataTransfer, "data") != NULL)
  8583. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8584. result = PASS;
  8585. }
  8586. json_object_put(DataTransfer);
  8587. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8588. {
  8589. // Send all moudle firmware version on EVSE
  8590. createFirmwareVersionByDataTransfer();
  8591. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8592. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8593. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8594. json_object_put(response);
  8595. }
  8596. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8597. {
  8598. system("/usr/bin/run_tmate_restart.sh &");
  8599. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8600. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8601. json_object_put(response);
  8602. }
  8603. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8604. {
  8605. json_object *data;
  8606. data = json_tokener_parse(tempdata);
  8607. if(!is_error(data))
  8608. {
  8609. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8610. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8611. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8612. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8613. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8614. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8615. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8616. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8617. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8618. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8619. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8620. }
  8621. else
  8622. {
  8623. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8624. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8625. }
  8626. json_object_put(data);
  8627. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8628. json_object_put(response);
  8629. }
  8630. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8631. {
  8632. json_object *data;
  8633. data = json_tokener_parse(tempdata);
  8634. if(!is_error(data))
  8635. {
  8636. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8637. if(json_object_object_get(data, "idToken") != NULL)
  8638. {
  8639. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8640. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8641. }
  8642. if(json_object_object_get(data, "price") != NULL)
  8643. {
  8644. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8645. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8646. }
  8647. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8648. }
  8649. else
  8650. {
  8651. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8652. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8653. }
  8654. json_object_put(data);
  8655. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8656. json_object_put(response);
  8657. }
  8658. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8659. {
  8660. json_object *data;
  8661. data = json_tokener_parse(tempdata);
  8662. if(!is_error(data))
  8663. {
  8664. if(json_object_object_get(data, "txId") != NULL)
  8665. {
  8666. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8667. for(int idx = 0;idx<gunTotalNumber;idx++)
  8668. {
  8669. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8670. {
  8671. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8672. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8673. if(json_object_object_get(data, "description") != NULL)
  8674. {
  8675. // California pricing V1.0
  8676. DEBUG_INFO("California pricing V1.0\n");
  8677. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8678. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8679. }
  8680. else
  8681. {
  8682. // California pricing V1.1
  8683. DEBUG_INFO("California pricing V1.1\n");
  8684. if(json_object_object_get(data, "timestamp") != NULL)
  8685. {
  8686. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8687. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8688. }
  8689. if(json_object_object_get(data, "meterValue") != NULL)
  8690. {
  8691. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8692. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8693. }
  8694. if(json_object_object_get(data, "cost") != NULL)
  8695. {
  8696. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8697. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8698. }
  8699. if(json_object_object_get(data, "state") != NULL)
  8700. {
  8701. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8702. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8703. }
  8704. if(json_object_object_get(data, "chargingPrice") != NULL)
  8705. {
  8706. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8707. {
  8708. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8709. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8710. }
  8711. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8712. {
  8713. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8714. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8715. }
  8716. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8717. {
  8718. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8719. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8720. }
  8721. }
  8722. if(json_object_object_get(data, "idlePrice") != NULL)
  8723. {
  8724. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8725. {
  8726. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8727. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8728. }
  8729. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8730. {
  8731. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8732. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8733. }
  8734. }
  8735. if(json_object_object_get(data, "nextPeriod") != NULL)
  8736. {
  8737. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8738. {
  8739. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8740. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8741. }
  8742. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8743. {
  8744. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8745. {
  8746. 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")));
  8747. 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"));
  8748. }
  8749. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8750. {
  8751. 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")));
  8752. 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"));
  8753. }
  8754. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8755. {
  8756. 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")));
  8757. 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"));
  8758. }
  8759. }
  8760. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8761. {
  8762. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8763. {
  8764. 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")));
  8765. 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"));
  8766. }
  8767. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8768. {
  8769. 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")));
  8770. 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"));
  8771. }
  8772. }
  8773. }
  8774. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8775. {
  8776. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8777. {
  8778. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8779. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8780. }
  8781. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8782. {
  8783. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8784. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8785. }
  8786. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8787. {
  8788. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8789. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8790. }
  8791. }
  8792. }
  8793. }
  8794. }
  8795. }
  8796. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8797. }
  8798. else
  8799. {
  8800. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8801. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8802. }
  8803. json_object_put(data);
  8804. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8805. json_object_put(response);
  8806. }
  8807. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8808. {
  8809. json_object *data;
  8810. data = json_tokener_parse(tempdata);
  8811. if(!is_error(data))
  8812. {
  8813. if(json_object_object_get(data, "txId") != NULL)
  8814. {
  8815. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8816. for(int idx = 0;idx<gunTotalNumber;idx++)
  8817. {
  8818. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8819. {
  8820. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8821. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8822. if(json_object_object_get(data, "description") != NULL)
  8823. {
  8824. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8825. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8826. }
  8827. }
  8828. }
  8829. }
  8830. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8831. }
  8832. else
  8833. {
  8834. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8835. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8836. }
  8837. json_object_put(data);
  8838. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8839. json_object_put(response);
  8840. }
  8841. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8842. {
  8843. json_object *data;
  8844. data = json_tokener_parse(tempdata);
  8845. if(!is_error(data))
  8846. {
  8847. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8848. if(json_object_object_get(data, "Content_Type") != NULL)
  8849. {
  8850. 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))
  8851. {
  8852. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8853. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8854. {
  8855. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8856. }
  8857. }
  8858. else
  8859. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8860. }
  8861. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8862. }
  8863. else
  8864. {
  8865. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8866. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8867. }
  8868. json_object_put(data);
  8869. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8870. json_object_put(response);
  8871. }
  8872. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8873. {
  8874. json_object *data;
  8875. data = json_tokener_parse(tempdata);
  8876. if(!is_error(data))
  8877. {
  8878. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8879. if(json_object_object_get(data, "Page_Index") != NULL)
  8880. {
  8881. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8882. }
  8883. if(json_object_object_get(data, "Duration") != NULL)
  8884. {
  8885. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8886. }
  8887. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8888. }
  8889. else
  8890. {
  8891. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8892. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8893. }
  8894. json_object_put(data);
  8895. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8896. json_object_put(response);
  8897. }
  8898. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8899. {
  8900. json_object *data;
  8901. data = json_tokener_parse(tempdata);
  8902. if(!is_error(data))
  8903. {
  8904. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8905. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8906. {
  8907. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8908. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8909. else
  8910. {
  8911. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8912. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8913. }
  8914. }
  8915. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8916. {
  8917. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8918. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8919. else
  8920. {
  8921. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8922. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8923. }
  8924. }
  8925. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8926. {
  8927. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8928. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8929. else
  8930. {
  8931. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8932. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8933. }
  8934. }
  8935. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8936. {
  8937. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8938. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8939. else
  8940. {
  8941. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8942. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8943. }
  8944. }
  8945. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8946. {
  8947. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8948. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8949. else
  8950. {
  8951. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8952. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8953. }
  8954. }
  8955. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8956. {
  8957. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8958. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8959. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8960. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8961. else
  8962. {
  8963. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8964. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8965. }
  8966. }
  8967. if(json_object_object_get(data, "isAuthentication") != NULL)
  8968. {
  8969. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  8970. {
  8971. case 0:
  8972. case 1:
  8973. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  8974. break;
  8975. default:
  8976. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8977. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8978. break;
  8979. }
  8980. }
  8981. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8982. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8983. }
  8984. else
  8985. {
  8986. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8987. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8988. }
  8989. json_object_put(data);
  8990. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8991. json_object_put(response);
  8992. }
  8993. else
  8994. {
  8995. // Can not find valid message id
  8996. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8997. }
  8998. }
  8999. else
  9000. {
  9001. // Payload is null
  9002. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9003. }
  9004. LWS_Send(message);
  9005. return result;
  9006. }
  9007. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9008. {
  9009. mtrace();
  9010. int result = FAIL;
  9011. int connectorIdInt, durationInt;
  9012. char chargingRateUnitStr[4]={0};
  9013. char comfirmstr[20];
  9014. int confirmPeriods = 0;
  9015. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9016. json_object *GetCompositeSchedule;
  9017. GetCompositeSchedule = json_tokener_parse(payload);
  9018. if(!is_error(GetCompositeSchedule))
  9019. {
  9020. // Required data
  9021. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9022. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9023. else
  9024. connectorIdInt = -1;
  9025. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9026. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9027. else
  9028. durationInt = 86400;
  9029. // Optional data
  9030. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9031. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9032. }
  9033. json_object_put(GetCompositeSchedule);
  9034. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9035. if((connectorIdInt == 0) ||
  9036. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9037. {
  9038. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9039. struct StructChargingProfile tmpProfile[1];
  9040. if(strstr(chargingRateUnitStr, "W") != NULL)
  9041. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9042. else
  9043. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9044. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9045. {
  9046. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9047. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9048. }
  9049. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9050. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9051. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9052. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9053. {
  9054. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9055. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9056. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9057. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9058. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9059. {
  9060. confirmPeriods = idx;
  9061. break;
  9062. }
  9063. }
  9064. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9065. {
  9066. confirmPeriods += 1;
  9067. }
  9068. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9069. }
  9070. else
  9071. {
  9072. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9073. }
  9074. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9075. return result;
  9076. }
  9077. int handleGetConfigurationRequest(char *uuid, char *payload)
  9078. {
  9079. mtrace();
  9080. int result = FAIL;
  9081. int MaxKeySupported = 0;
  9082. int n_keys = 0;
  9083. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9084. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9085. json_object *GetConfiguration;
  9086. GetConfiguration = json_tokener_parse(payload);
  9087. if(!is_error(GetConfiguration))
  9088. {
  9089. // Optional data
  9090. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9091. {
  9092. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9093. {
  9094. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9095. n_keys = idx + 1;
  9096. }
  9097. }
  9098. }
  9099. json_object_put(GetConfiguration);
  9100. UnknownKeynum = 0;
  9101. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9102. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9103. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9104. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9105. if(n_keys != 0)
  9106. {
  9107. for(int i=0;i<n_keys;i++)
  9108. {
  9109. getKeyValue(requestKey[i]);
  9110. }
  9111. }
  9112. else
  9113. {
  9114. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9115. getKeyValue("");
  9116. }
  9117. processUnkownKey();
  9118. sendGetConfigurationConfirmation(uuid);
  9119. return result;
  9120. }
  9121. static char fnamePlusPath[100]={0};
  9122. static char fnamePWithNoPath[60]={0};
  9123. void checkUploadLog(void)
  9124. {
  9125. FILE *fp;
  9126. /* Open the command for reading. */
  9127. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9128. if (fp == NULL) {
  9129. DEBUG_WARN("Failed to run command\n" );
  9130. exit(1);
  9131. }
  9132. int ftppathlen = 0;
  9133. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9134. int i = 0;
  9135. /* Read the output a line at a time - output it. */
  9136. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9137. if(i==0)
  9138. {
  9139. ftppathlen = strlen(fnamePlusPath);
  9140. DEBUG_INFO("%s\n", fnamePlusPath);
  9141. fnamePlusPath[ftppathlen]='\0';
  9142. break;
  9143. }
  9144. i= i+1;
  9145. }
  9146. /* close */
  9147. pclose(fp);
  9148. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9149. {
  9150. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9151. {
  9152. fnamePlusPath[k]='\0';
  9153. }
  9154. }
  9155. i=1;
  9156. //char fname[60]={0};
  9157. while(i < ftppathlen)
  9158. {
  9159. int len=ftppathlen-i;
  9160. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9161. {
  9162. DEBUG_INFO("compare '/' all right\n");
  9163. break;
  9164. }
  9165. i=i+1;
  9166. }
  9167. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9168. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9169. fnamePWithNoPath[i+1] = '\0';
  9170. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9171. {
  9172. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9173. {
  9174. fnamePWithNoPath[j]='\0';
  9175. }
  9176. }
  9177. FILE* fp1 = fopen(fnamePlusPath, "r");
  9178. if (fp1)
  9179. {
  9180. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9181. // file exists
  9182. fclose(fp1);
  9183. }
  9184. else
  9185. {
  9186. // file doesn't exist
  9187. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9188. }
  9189. }
  9190. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9191. {
  9192. mtrace();
  9193. int result = FAIL;
  9194. time_t CurrentTime;
  9195. struct tm *tm;
  9196. pthread_t th_Status;
  9197. CurrentTime = time(NULL);
  9198. tm = localtime(&CurrentTime);
  9199. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9200. 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);
  9201. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9202. if(!interLock.isGetDiagnosticGoing)
  9203. {
  9204. interLock.isGetDiagnosticGoing = 1;
  9205. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9206. sleep(1);
  9207. }
  9208. else
  9209. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9210. return result;
  9211. }
  9212. void* GetDiagnosticsProcess(void* data)
  9213. {
  9214. pthread_detach(pthread_self());
  9215. mtrace();
  9216. int retriesInt=0, retryIntervalInt=0;
  9217. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9218. 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};
  9219. int port=0;
  9220. int isSuccess = FALSE;
  9221. char cmdBuf[2048];
  9222. struct tm *tmNow;
  9223. time_t CurrentTime;
  9224. struct tm tmStart;
  9225. struct tm tmStop;
  9226. CurrentTime = time(NULL);
  9227. tmNow=localtime(&CurrentTime);
  9228. uint16_t targetYear, targetMonth;
  9229. json_object *GetDiagnostics;
  9230. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9231. GetDiagnostics = json_tokener_parse(data);
  9232. if(!is_error(GetDiagnostics))
  9233. {
  9234. // Required data
  9235. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9236. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9237. // Optional data
  9238. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9239. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9240. else
  9241. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9242. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9243. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9244. else
  9245. retryIntervalInt = 30;
  9246. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9247. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9248. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9249. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9250. }
  9251. json_object_put(GetDiagnostics);
  9252. // Pack log to compress file
  9253. 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) &&
  9254. (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))
  9255. {
  9256. // Pack system log
  9257. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9258. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9259. targetYear = tmStart.tm_year;
  9260. targetMonth = tmStart.tm_mon;
  9261. do
  9262. {
  9263. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9264. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9265. if(targetMonth+1>=13)
  9266. {
  9267. targetYear += 1;
  9268. targetMonth = 1;
  9269. }
  9270. else
  9271. {
  9272. targetMonth += 1;
  9273. }
  9274. }while((targetYear < (tmNow->tm_year+1900)) ||
  9275. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9276. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9277. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9278. system(cmdBuf);
  9279. // Pack charging & event log
  9280. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9281. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9282. targetYear = tmStart.tm_year;
  9283. targetMonth = tmStart.tm_mon;
  9284. do
  9285. {
  9286. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9287. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9288. if(targetMonth+1>=13)
  9289. {
  9290. targetYear += 1;
  9291. targetMonth = 1;
  9292. }
  9293. else
  9294. {
  9295. targetMonth += 1;
  9296. }
  9297. }while((targetYear < (tmNow->tm_year+1900)) ||
  9298. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9299. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9300. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9301. system(cmdBuf);
  9302. // Combine log file
  9303. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9304. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9305. }
  9306. else
  9307. {
  9308. system("exec /root/logPackTools 'log' 6");
  9309. }
  9310. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9311. system(cmdBuf);
  9312. checkUploadLog();
  9313. //****************location*******************/
  9314. if(strcmp(locationstr,"")==0)
  9315. {
  9316. DEBUG_INFO("location is <Empty>!\n");
  9317. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9318. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9319. goto end;
  9320. }
  9321. memset(protocol, 0, ARRAY_SIZE(protocol));
  9322. memset(user, 0, ARRAY_SIZE(user) );
  9323. memset(password, 0, ARRAY_SIZE(password));
  9324. memset(host, 0, ARRAY_SIZE(host));
  9325. memset(path, 0, ARRAY_SIZE(path));
  9326. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9327. memset(host1, 0, ARRAY_SIZE(host1));
  9328. memset(path1, 0, ARRAY_SIZE(path1));
  9329. /*location: ftp://user:password@host:port/path*/
  9330. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9331. if((access(fnamePlusPath,F_OK))!=-1)
  9332. {
  9333. DEBUG_INFO("fnamePlusPath exist.\n");
  9334. }
  9335. else
  9336. {
  9337. DEBUG_INFO("fnamePlusPath not exist!\n");
  9338. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9339. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9340. goto end;
  9341. }
  9342. if(strchr(locationstr,'@')==NULL)
  9343. {
  9344. sscanf(locationstr,
  9345. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9346. protocol, host, &port, path);
  9347. strcpy(user,"anonymous");
  9348. strcpy(password,"");
  9349. }
  9350. else
  9351. {
  9352. //DEBUG_INFO("pch=%s\n", pch);
  9353. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9354. protocol, user, password, host, &port, path);
  9355. }
  9356. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9357. {
  9358. DEBUG_INFO("protocol is not ftp/http ! \n");
  9359. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9360. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9361. goto end;
  9362. }
  9363. if(strncmp(locationstr,"http", 4) == 0)
  9364. {
  9365. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9366. sprintf(ftppath,"/%s", path);
  9367. do
  9368. {
  9369. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9370. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9371. sleep(3);
  9372. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9373. if(!isSuccess)
  9374. {
  9375. DEBUG_INFO("Diagnostics fail.\n");
  9376. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9377. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9378. sleep(retryIntervalInt);
  9379. }
  9380. else
  9381. {
  9382. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9383. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9384. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9385. }
  9386. retriesInt--;
  9387. }while((isSuccess == 0)&&(retriesInt >= 0));
  9388. }
  9389. else
  9390. {
  9391. sscanf(host,"%[^/]%s",host1, path1);
  9392. if(strlen(path) > 0)
  9393. sprintf(ftppath,"/%s", path);
  9394. else
  9395. sprintf(ftppath,"/%s", path1);
  9396. int ftppathlen=strlen(ftppath);
  9397. int i=1;
  9398. char filenametemp[50];
  9399. while(i < ftppathlen)
  9400. {
  9401. int len=ftppathlen-i;
  9402. if(ftppath[len]== 47) // '/' ascll code: 47
  9403. {
  9404. DEBUG_INFO("find '/' all right\n");
  9405. break;
  9406. }
  9407. i=i+1;
  9408. }
  9409. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9410. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9411. filenametemp[i+1] = 0;
  9412. if(port == 0)
  9413. port = 21;
  9414. do
  9415. {
  9416. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9417. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9418. sleep(3);
  9419. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9420. if(!isSuccess)
  9421. {
  9422. DEBUG_INFO("Diagnostics fail.\n");
  9423. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9424. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9425. sleep(retryIntervalInt);
  9426. }
  9427. else
  9428. {
  9429. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9430. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9431. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9432. }
  9433. retriesInt--;
  9434. }while((!isSuccess)&&(retriesInt >= 0));
  9435. }
  9436. end:
  9437. system("rm -f /mnt/*");
  9438. sleep(5);
  9439. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9440. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9441. interLock.isGetDiagnosticGoing = 0;
  9442. pthread_exit(NULL);
  9443. }
  9444. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9445. {
  9446. mtrace();
  9447. int result = FAIL;
  9448. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9449. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9450. {
  9451. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9452. locallistVersion = -1;
  9453. }
  9454. else
  9455. {
  9456. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9457. OCPP_getListVerion();
  9458. }
  9459. //from db.OCPP_getListVerion
  9460. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9461. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9462. sendGetLocalListVersionConfirmation(uuid,"");
  9463. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9464. return result;
  9465. }
  9466. int handleRemoteStartRequest(char *uuid, char *payload)
  9467. {
  9468. mtrace();
  9469. int result = FAIL;
  9470. int connectorIdInt=-1;
  9471. int tempIndex = 0;
  9472. int connectorIdIsNULL, chargingProfileIsNULL;
  9473. char comfirmstr[20]={0};
  9474. char cmdBuf[512];
  9475. json_object *RemoteStartTransaction;
  9476. FILE *fp;
  9477. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9478. if(server_pending == TRUE)
  9479. {
  9480. return 0;
  9481. }
  9482. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9483. RemoteStartTransaction = json_tokener_parse(payload);
  9484. if(!is_error(RemoteStartTransaction))
  9485. {
  9486. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9487. {
  9488. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9489. }
  9490. else
  9491. {
  9492. connectorIdIsNULL = TRUE;
  9493. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9494. {
  9495. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9496. {
  9497. connectorIdIsNULL = FALSE;
  9498. connectorIdInt = (gun_index+1);
  9499. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9500. break;
  9501. }
  9502. }
  9503. }
  9504. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9505. {
  9506. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9507. // Required data
  9508. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9509. // Optional data
  9510. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9511. {
  9512. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9513. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9514. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9515. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9516. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9517. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9518. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9519. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9520. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9521. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9522. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9523. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9524. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9525. {
  9526. 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")));
  9527. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9528. 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"));
  9529. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9530. 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"));
  9531. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9532. 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")));
  9533. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9534. {
  9535. 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++)
  9536. {
  9537. 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"));
  9538. 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"));
  9539. 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)
  9540. 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"));
  9541. }
  9542. }
  9543. }
  9544. }
  9545. else
  9546. {
  9547. chargingProfileIsNULL = TRUE;
  9548. }
  9549. }
  9550. }
  9551. else
  9552. {
  9553. connectorIdIsNULL = TRUE;
  9554. }
  9555. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9556. {
  9557. DEBUG_WARN("Connector id is NULL\n.");
  9558. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9559. goto end;
  9560. }
  9561. /*
  9562. enum _SYSTEM_STATUS
  9563. {
  9564. S_BOOTING = 0,
  9565. S_IDLE, = 1
  9566. S_AUTHORIZING, = 2
  9567. S_REASSIGN_CHECK, = 3
  9568. S_REASSIGN, = 4
  9569. S_PRECHARGE, = 5
  9570. S_PREPARING_FOR_EV, = 6
  9571. S_PREPARING_FOR_EVSE, = 7
  9572. S_CHARGING, = 8
  9573. S_TERMINATING, = 9
  9574. S_COMPLETE, = 10
  9575. S_ALARM, = 11
  9576. S_FAULT = 12
  9577. }
  9578. */
  9579. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9580. {
  9581. //check Transaction active
  9582. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9583. {
  9584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9585. {
  9586. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9587. }
  9588. else
  9589. {
  9590. tempIndex = connectorIdInt -1;
  9591. }
  9592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9593. {
  9594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9595. {
  9596. 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))
  9597. {
  9598. //Reserved
  9599. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9600. }
  9601. 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))
  9602. {
  9603. //Reserved
  9604. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9605. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9606. goto end;
  9607. }
  9608. else
  9609. {
  9610. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9611. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9612. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9613. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9614. {
  9615. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9616. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9617. goto end;
  9618. }
  9619. }//END FOR ELSE
  9620. }
  9621. }// END FOR CHAdeMO_QUANTITY
  9622. }
  9623. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9624. {
  9625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9626. {
  9627. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9628. }
  9629. else
  9630. {
  9631. tempIndex = connectorIdInt -1;
  9632. }
  9633. for (int index = 0; index < CCS_QUANTITY; index++)
  9634. {
  9635. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9636. {
  9637. 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))
  9638. {
  9639. //Reserved
  9640. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9641. }
  9642. 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))
  9643. {
  9644. //Reserved
  9645. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9646. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9647. goto end;
  9648. }
  9649. else
  9650. {
  9651. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9652. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9653. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9654. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9655. {
  9656. DEBUG_WARN("CCS connector not allow start\n.");
  9657. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9658. goto end;
  9659. }
  9660. }// END FOR ELSE
  9661. }
  9662. }// END FOR CCS_QUANTITY
  9663. }
  9664. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9665. {
  9666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9667. {
  9668. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9669. }
  9670. else
  9671. {
  9672. tempIndex = connectorIdInt -1;
  9673. }
  9674. for (int index = 0; index < GB_QUANTITY; index++)
  9675. {
  9676. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9677. {
  9678. 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))
  9679. {
  9680. //Reserved
  9681. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9682. }
  9683. 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))
  9684. {
  9685. //Reserved
  9686. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9687. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9688. goto end;
  9689. }
  9690. else
  9691. {
  9692. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9693. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9694. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9695. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9696. {
  9697. DEBUG_WARN("GB connector not allow start\n.");
  9698. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9699. goto end;
  9700. }
  9701. }// END FOR ELSE
  9702. }
  9703. } // END FOR GB_QUANTITY
  9704. }
  9705. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9706. {
  9707. tempIndex = connectorIdInt -1;
  9708. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9709. {
  9710. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9711. {
  9712. 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))
  9713. {
  9714. //Reserved
  9715. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9716. }
  9717. 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))
  9718. {
  9719. //Reserved
  9720. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9721. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9722. goto end;
  9723. }
  9724. else
  9725. {
  9726. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9727. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9728. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9729. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9730. {
  9731. DEBUG_WARN("GB connector not allow start\n.");
  9732. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9733. goto end;
  9734. }
  9735. }// END FOR ELSE
  9736. }
  9737. } // END FOR GB_QUANTITY
  9738. }
  9739. else
  9740. {
  9741. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9742. {
  9743. tempIndex = 2;
  9744. }
  9745. else
  9746. {
  9747. tempIndex = connectorIdInt -1;
  9748. }
  9749. for (int index = 0; index < AC_QUANTITY; index++)
  9750. {
  9751. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9752. {
  9753. 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))
  9754. {
  9755. //Reserved
  9756. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9757. }
  9758. 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))
  9759. {
  9760. //Reserved
  9761. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9762. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9763. goto end;
  9764. }
  9765. else
  9766. {
  9767. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9768. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9769. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9770. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9771. {
  9772. DEBUG_WARN("AC connector not allow start\n.");
  9773. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9774. goto end;
  9775. }
  9776. }//END FOR ELSE
  9777. }
  9778. }// END FOR AC_QUANTITY
  9779. }
  9780. if(chargingProfileIsNULL == FALSE)
  9781. {
  9782. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9783. {
  9784. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9785. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9786. //memset idTag
  9787. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9788. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9789. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9790. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9791. // Save profile to file
  9792. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9793. system(cmdBuf);
  9794. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9795. fp = fopen(cmdBuf, "w");
  9796. 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));
  9797. fclose(fp);
  9798. }
  9799. else
  9800. {
  9801. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9802. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9803. }
  9804. }
  9805. else
  9806. {
  9807. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9808. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9809. //memset idTag
  9810. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9811. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9812. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9813. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9814. }
  9815. }
  9816. else
  9817. {
  9818. DEBUG_WARN("Connector id over\n.");
  9819. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9820. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9821. }
  9822. end:
  9823. json_object_put(RemoteStartTransaction);
  9824. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9825. {
  9826. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9827. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9828. }
  9829. //OCPP send RemoteStartConfirmation by first.
  9830. sendRemoteStartConfirmation(uuid, comfirmstr);
  9831. return result;
  9832. }
  9833. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9834. {
  9835. mtrace();
  9836. int result = FAIL;
  9837. int match = FALSE;
  9838. int GunNO = 0;
  9839. int tempIndex = 0;
  9840. int transactionIdInt=0;
  9841. int transactionIdIsNULL= TRUE;
  9842. char comfirmstr[20];
  9843. json_object *RemoteStopTransaction;
  9844. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9845. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9846. if(server_pending == TRUE)
  9847. {
  9848. return 0;
  9849. }
  9850. RemoteStopTransaction = json_tokener_parse(payload);
  9851. if(!is_error(RemoteStopTransaction))
  9852. {
  9853. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9854. {
  9855. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9856. transactionIdIsNULL = FALSE;
  9857. }
  9858. }
  9859. json_object_put(RemoteStopTransaction);
  9860. if(transactionIdIsNULL == FALSE)
  9861. {
  9862. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9863. {
  9864. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9865. {
  9866. //check Transaction active
  9867. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9868. {
  9869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9870. {
  9871. tempIndex = ((gun_index==2) ? 1: 0);
  9872. }
  9873. else
  9874. {
  9875. tempIndex = gun_index;
  9876. }
  9877. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9878. {
  9879. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9880. {
  9881. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9882. {
  9883. match = TRUE;
  9884. GunNO = gun_index;
  9885. }
  9886. }
  9887. }// END FOR CHAdeMO_QUANTITY
  9888. }
  9889. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9890. {
  9891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9892. {
  9893. tempIndex = ((gun_index==2) ? 1: 0);
  9894. }
  9895. else
  9896. {
  9897. tempIndex = gun_index;
  9898. }
  9899. for (int index = 0; index < CCS_QUANTITY; index++)
  9900. {
  9901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9902. {
  9903. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9904. {
  9905. match = TRUE;
  9906. GunNO = gun_index;
  9907. }
  9908. }
  9909. }// END FOR CCS_QUANTITY
  9910. }
  9911. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9912. {
  9913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9914. {
  9915. tempIndex = ((gun_index==2) ? 1: 0);
  9916. }
  9917. else
  9918. {
  9919. tempIndex = gun_index;
  9920. }
  9921. for (int index = 0; index < GB_QUANTITY; index++)
  9922. {
  9923. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9924. {
  9925. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9926. {
  9927. match = TRUE;
  9928. GunNO = gun_index;
  9929. }
  9930. }
  9931. }// END FOR GB_QUANTITY
  9932. }
  9933. else if(gunType[gun_index] == GUN_TYPE_DO)
  9934. {
  9935. tempIndex = gun_index;
  9936. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9937. {
  9938. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9939. {
  9940. 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
  9941. {
  9942. match = TRUE;
  9943. GunNO = gun_index;
  9944. }
  9945. }
  9946. }// END FOR GB_QUANTITY
  9947. }
  9948. else
  9949. {
  9950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9951. {
  9952. tempIndex = 2;
  9953. }
  9954. else
  9955. {
  9956. tempIndex = gun_index;
  9957. }
  9958. for (int index = 0; index < AC_QUANTITY; index++)
  9959. {
  9960. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9961. {
  9962. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9963. {
  9964. match = TRUE;
  9965. GunNO = gun_index;
  9966. }
  9967. }
  9968. }// END FOR CHAdeMO_QUANTITY
  9969. } // END FOR AC ELSE
  9970. }// CHECK IF ResponseTransactionId == transactionIdInt
  9971. }//END FOR
  9972. if( match == TRUE)
  9973. {
  9974. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9975. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9976. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9977. }
  9978. else
  9979. {
  9980. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9981. }
  9982. }
  9983. else
  9984. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9985. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9986. return result;
  9987. }
  9988. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9989. {
  9990. mtrace();
  9991. int result = FAIL;
  9992. int connectorIdInt=0, reservationIdInt=0;
  9993. int tempIndex = 0;
  9994. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9995. char comfirmstr[20]={0};
  9996. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9997. int c = 0;
  9998. char *loc;
  9999. //char *ptr;
  10000. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10001. strcpy(sstrtemp, stringtrimspace(payload));
  10002. //***(1)connectorId ****/
  10003. c=0;
  10004. loc = strstr(sstrtemp, "connectorId");
  10005. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10006. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10007. {
  10008. sstr[c] = loc[strlen("connectorId")+2+c];
  10009. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10010. c++;
  10011. }
  10012. sstr[c] = '\0';
  10013. connectorIdInt = atoi(sstr);
  10014. //***(2)expiryDate ****/
  10015. loc = strstr(sstrtemp, "expiryDate");
  10016. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10017. c = 0;
  10018. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10019. {
  10020. sstr[c] = loc[3+strlen("expiryDate")+c];
  10021. c++;
  10022. }
  10023. sstr[c] = '\0';
  10024. strcpy(expiryDatestr, sstr);
  10025. //***(3)idTag ****/
  10026. loc = strstr(sstrtemp, "idTag");
  10027. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10028. c = 0;
  10029. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10030. {
  10031. sstr[c] = loc[3+strlen("idTag")+c];
  10032. c++;
  10033. }
  10034. sstr[c] = '\0';
  10035. strcpy(idTagstr, sstr);
  10036. //***(4)parentIdTag ****/
  10037. loc = strstr(sstrtemp, "parentIdTag");
  10038. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10039. c = 0;
  10040. if(loc == NULL)
  10041. {
  10042. strcpy(parentIdTagstr, "");
  10043. }
  10044. else
  10045. {
  10046. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10047. {
  10048. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10049. c++;
  10050. }
  10051. sstr[c] = '\0';
  10052. strcpy(parentIdTagstr, sstr);
  10053. }
  10054. //***(5)reservationId ****/
  10055. c=0;
  10056. loc = strstr(sstrtemp, "reservationId");
  10057. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10058. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10059. {
  10060. sstr[c] = loc[strlen("reservationId")+2+c];
  10061. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10062. c++;
  10063. }
  10064. sstr[c] = '\0';
  10065. reservationIdInt = atoi(sstr);
  10066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10067. /*
  10068. enum SYSTEM_STATUS
  10069. {
  10070. SYS_MODE_BOOTING = 0,
  10071. SYS_MODE_IDLE = 1,
  10072. SYS_MODE_AUTHORIZING = 2,
  10073. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10074. SYS_MODE_REASSIGN = 4,
  10075. SYS_MODE_PREPARING = 5,
  10076. SYS_MODE_PREPARE_FOR_EV = 6,
  10077. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10078. SYS_MODE_CHARGING = 8,
  10079. SYS_MODE_TERMINATING = 9,
  10080. SYS_MODE_COMPLETE = 10,
  10081. SYS_MODE_ALARM = 11,
  10082. SYS_MODE_FAULT = 12,
  10083. SYS_MODE_RESERVATION = 13,
  10084. SYS_MODE_BOOKING = 14,
  10085. SYS_MODE_MAINTAIN = 15,
  10086. SYS_MODE_DEBUG = 16,
  10087. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10088. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10089. SYS_MODE_UPDATE = 19
  10090. };
  10091. */
  10092. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10093. {
  10094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10095. goto end;
  10096. }
  10097. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10098. {
  10099. //check Transaction active
  10100. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10101. {
  10102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10103. {
  10104. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10105. }
  10106. else
  10107. {
  10108. tempIndex = connectorIdInt -1;
  10109. }
  10110. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10111. {
  10112. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10113. {
  10114. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10115. {
  10116. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10117. {
  10118. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10119. {
  10120. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10121. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10122. }
  10123. 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'))
  10124. {
  10125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10126. }
  10127. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10128. {
  10129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10130. }
  10131. else
  10132. {
  10133. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10134. }
  10135. }
  10136. 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
  10137. {
  10138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10139. }
  10140. }
  10141. else
  10142. {
  10143. //replace reservation
  10144. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10146. }
  10147. }
  10148. } // END FOR CHAdeMO_QUANTITY
  10149. }
  10150. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10151. {
  10152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10153. {
  10154. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10155. }
  10156. else
  10157. {
  10158. tempIndex = connectorIdInt -1;
  10159. }
  10160. for (int index = 0; index < CCS_QUANTITY; index++)
  10161. {
  10162. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10163. {
  10164. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10165. {
  10166. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10167. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10168. {
  10169. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10170. {
  10171. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10172. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10173. }
  10174. 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'))
  10175. {
  10176. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10177. }
  10178. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10179. {
  10180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10181. }
  10182. else
  10183. {
  10184. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10185. }
  10186. }
  10187. 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
  10188. {
  10189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10190. }
  10191. }
  10192. else
  10193. {
  10194. //replace reservation
  10195. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10196. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10197. }
  10198. }
  10199. } // END FOR CCS_QUANTITY
  10200. }
  10201. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10202. {
  10203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10204. {
  10205. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10206. }
  10207. else
  10208. {
  10209. tempIndex = connectorIdInt -1;
  10210. }
  10211. for (int index = 0; index < GB_QUANTITY; index++)
  10212. {
  10213. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10214. {
  10215. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10216. {
  10217. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10218. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10219. {
  10220. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10221. {
  10222. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10224. }
  10225. 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'))
  10226. {
  10227. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10228. }
  10229. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10230. {
  10231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10232. }
  10233. else
  10234. {
  10235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10236. }
  10237. }
  10238. 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
  10239. {
  10240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10241. }
  10242. }
  10243. else
  10244. {
  10245. //replace reservation
  10246. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10247. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10248. }
  10249. }
  10250. }// END FOR GB_QUANTITY
  10251. }
  10252. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10253. {
  10254. tempIndex = connectorIdInt -1;
  10255. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10256. {
  10257. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10258. {
  10259. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10260. {
  10261. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10262. 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
  10263. {
  10264. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10265. {
  10266. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10268. }
  10269. 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'))
  10270. {
  10271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10272. }
  10273. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10274. {
  10275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10276. }
  10277. else
  10278. {
  10279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10280. }
  10281. }
  10282. 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
  10283. {
  10284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10285. }
  10286. }
  10287. else
  10288. {
  10289. //replace reservation
  10290. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10291. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10292. }
  10293. }
  10294. }// END FOR GB_QUANTITY
  10295. }
  10296. else
  10297. {
  10298. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10299. {
  10300. tempIndex = 2;
  10301. }
  10302. else
  10303. {
  10304. tempIndex = (connectorIdInt -1);
  10305. }
  10306. for (int index = 0; index < AC_QUANTITY; index++)
  10307. {
  10308. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10309. {
  10310. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10311. {
  10312. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10313. {
  10314. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10315. {
  10316. 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))
  10317. {
  10318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10319. }
  10320. else
  10321. {
  10322. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10324. }
  10325. }
  10326. 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'))
  10327. {
  10328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10329. }
  10330. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10331. {
  10332. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10333. }
  10334. else
  10335. {
  10336. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10337. }
  10338. }
  10339. 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
  10340. {
  10341. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10342. }
  10343. }
  10344. else
  10345. {
  10346. //replace reservation
  10347. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10348. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10349. }
  10350. }
  10351. } // END FOR AC_QUANTITY
  10352. }
  10353. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10354. }
  10355. else if(connectorIdInt == 0)
  10356. {
  10357. //check Transaction active
  10358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10359. {
  10360. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10361. {
  10362. 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'))
  10363. {
  10364. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10365. goto end;
  10366. }
  10367. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10368. {
  10369. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10370. goto end;
  10371. }
  10372. 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
  10373. {
  10374. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10375. goto end;
  10376. }
  10377. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10378. {
  10379. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10380. goto end;
  10381. }
  10382. }
  10383. }// END FOR CHAdeMO_QUANTITY
  10384. for (int index = 0; index < CCS_QUANTITY; index++)
  10385. {
  10386. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10387. {
  10388. 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'))
  10389. {
  10390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10391. goto end;
  10392. }
  10393. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10394. {
  10395. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10396. goto end;
  10397. }
  10398. 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
  10399. {
  10400. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10401. goto end;
  10402. }
  10403. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10404. {
  10405. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10406. goto end;
  10407. }
  10408. }
  10409. } // END FOR CCS_QUANTITY
  10410. for (int index = 0; index < GB_QUANTITY; index++)
  10411. {
  10412. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10413. {
  10414. 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'))
  10415. {
  10416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10417. goto end;
  10418. }
  10419. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10420. {
  10421. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10422. goto end;
  10423. }
  10424. 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
  10425. {
  10426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10427. goto end;
  10428. }
  10429. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10430. {
  10431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10432. goto end;
  10433. }
  10434. }
  10435. } // END FOR GB_QUANTITY
  10436. for (int index = 0; index < AC_QUANTITY; index++)
  10437. {
  10438. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10439. {
  10440. 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'))
  10441. {
  10442. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10443. goto end;
  10444. }
  10445. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10446. {
  10447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10448. goto end;
  10449. }
  10450. 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
  10451. {
  10452. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10453. goto end;
  10454. }
  10455. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10456. {
  10457. 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))
  10458. {
  10459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10460. goto end;
  10461. }
  10462. }
  10463. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10464. {
  10465. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10466. goto end;
  10467. }
  10468. }
  10469. }// END FOR AC_QUANTITY
  10470. //The connectorId is 0
  10471. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10472. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10473. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10474. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10475. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10476. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10477. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10478. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10479. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10480. result = TRUE;
  10481. return result;
  10482. }
  10483. else
  10484. {
  10485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10486. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10487. }
  10488. if(strcmp(comfirmstr,"Accepted") == 0)
  10489. {
  10490. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10491. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10492. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10493. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10494. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10495. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10496. result = TRUE;
  10497. return result;
  10498. }
  10499. end:
  10500. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10501. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10502. return result;
  10503. }
  10504. int handleResetRequest(char *uuid, char *payload)
  10505. {
  10506. mtrace();
  10507. int result = FAIL;
  10508. char sstr[10]={0},sstrtemp[30]={ 0 };
  10509. char typestr[10]={0};
  10510. char comfirmstr[20]={0};
  10511. int c = 0;
  10512. char *loc;
  10513. DEBUG_INFO("handleResetRequest...\n");
  10514. strcpy(sstrtemp, stringtrimspace(payload));
  10515. loc = strstr(sstrtemp, "type");
  10516. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10517. c = 0;
  10518. while (loc[3+strlen("type")+c] != '\"')
  10519. {
  10520. sstr[c] = loc[3+strlen("type")+c];
  10521. c++;
  10522. }
  10523. sstr[c] = '\0';
  10524. strcpy(typestr,sstr);
  10525. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10526. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10527. {
  10528. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10529. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10530. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10531. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10532. }
  10533. else
  10534. {
  10535. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10536. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10537. result = PASS;
  10538. }
  10539. sendResetConfirmation(uuid, comfirmstr);
  10540. return result;
  10541. }
  10542. int handleSendLocalListRequest(char *uuid, char *payload)
  10543. {
  10544. mtrace();
  10545. int result = FAIL;
  10546. char comfirmstr[20];
  10547. int checkState_Faulted = FALSE;
  10548. json_object *SendLocalList;
  10549. DEBUG_INFO("handleSendLocalListRequest...\n");
  10550. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10551. {
  10552. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10553. goto end;
  10554. }
  10555. //check Charge Point state
  10556. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10557. {
  10558. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10559. {
  10560. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10561. }
  10562. }
  10563. for (int index = 0; index < CCS_QUANTITY; index++)
  10564. {
  10565. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10566. {
  10567. checkState_Faulted = TRUE; //OCPP Status
  10568. }
  10569. }
  10570. for (int index = 0; index < GB_QUANTITY; index++)
  10571. {
  10572. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10573. {
  10574. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10575. }
  10576. }
  10577. //check Charge Point state
  10578. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10579. {
  10580. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10581. {
  10582. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10583. }
  10584. }
  10585. //check Charge Point state
  10586. for (int index = 0; index < AC_QUANTITY; index++)
  10587. {
  10588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10589. {
  10590. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10591. }
  10592. }
  10593. if(checkState_Faulted == TRUE)
  10594. {
  10595. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10596. goto end;
  10597. }
  10598. // Parsing payload
  10599. SendLocalList = json_tokener_parse(payload);
  10600. if(!is_error(SendLocalList))
  10601. {
  10602. // Required data
  10603. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10604. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10605. // Optional data
  10606. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10607. {
  10608. //Check UpdateType
  10609. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10610. {
  10611. //Local list full update
  10612. DEBUG_INFO("Local list full update.\n");
  10613. OCPP_getListVerion();
  10614. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10615. {
  10616. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10617. goto end;
  10618. }
  10619. OCPP_cleanLocalList();
  10620. }
  10621. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10622. {
  10623. //Local list different update
  10624. DEBUG_INFO("Local list different update.\n");
  10625. OCPP_getListVerion();
  10626. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10627. {
  10628. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10629. goto end;
  10630. }
  10631. }
  10632. else
  10633. {
  10634. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10635. goto end;
  10636. }
  10637. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10638. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10639. {
  10640. 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")));
  10641. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10642. {
  10643. 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")));
  10644. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10645. 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")));
  10646. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10647. 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")));
  10648. }
  10649. // Add to db
  10650. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10651. {
  10652. //Local list full update
  10653. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10654. idx,
  10655. ShmOCPP16Data->SendLocalList.ListVersion,
  10656. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10657. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10658. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10659. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10660. // update list
  10661. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10662. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10663. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10664. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10665. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10666. }
  10667. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10668. {
  10669. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10670. idx,
  10671. ShmOCPP16Data->SendLocalList.ListVersion,
  10672. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10673. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10674. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10675. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10676. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10677. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10678. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10679. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10680. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10681. }
  10682. }
  10683. }
  10684. else
  10685. {
  10686. //Check UpdateType
  10687. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10688. {
  10689. //Local list full update
  10690. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10691. OCPP_cleanLocalList();
  10692. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10693. goto end;
  10694. }
  10695. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10696. {
  10697. //Local list different update
  10698. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10699. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10700. goto end;
  10701. }
  10702. }
  10703. result = PASS;
  10704. }
  10705. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10706. end:
  10707. json_object_put(SendLocalList);
  10708. sendSendLocalListConfirmation(uuid, comfirmstr);
  10709. return result;
  10710. }
  10711. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10712. {
  10713. mtrace();
  10714. int result = FAIL;
  10715. struct StructSetChargingProfile SetProfileReq = {0};
  10716. int tempchargingProfileIdInt;
  10717. int chargingSchedulePeriodCount = 0;
  10718. char comfirmstr[20]={0};
  10719. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10720. char rmFileCmd[128]={0};
  10721. int profileQuantity = 0;
  10722. json_object *SetChargingProfile;
  10723. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10724. SetChargingProfile = json_tokener_parse(payload);
  10725. if(!is_error(SetChargingProfile))
  10726. {
  10727. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10728. {
  10729. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10730. }
  10731. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10732. {
  10733. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10734. {
  10735. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10736. }
  10737. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10738. {
  10739. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10740. }
  10741. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10742. {
  10743. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10744. }
  10745. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10746. {
  10747. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10748. }
  10749. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10750. {
  10751. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10752. }
  10753. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10754. {
  10755. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10756. }
  10757. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10758. {
  10759. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10760. }
  10761. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10762. {
  10763. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10764. }
  10765. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10766. {
  10767. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10768. {
  10769. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10770. }
  10771. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10772. {
  10773. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10774. }
  10775. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10776. {
  10777. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10778. }
  10779. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10780. {
  10781. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10782. }
  10783. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10784. {
  10785. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10786. if(chargingSchedulePeriodCount <= 10)
  10787. {
  10788. 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++)
  10789. {
  10790. 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)
  10791. {
  10792. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10793. }
  10794. 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)
  10795. {
  10796. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10797. }
  10798. 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)
  10799. {
  10800. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10801. }
  10802. }
  10803. }
  10804. }
  10805. }
  10806. }
  10807. }
  10808. // Profile periods quantity check
  10809. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10810. {
  10811. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10812. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10813. goto end;
  10814. }
  10815. // Profile purpose info check
  10816. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10817. {
  10818. FILE *fp;
  10819. char dataLine[4096]={0};
  10820. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  10821. if(SetProfileReq.ConnectorId != 0)
  10822. {
  10823. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10824. DEBUG_WARN("Profile connector id is not 0.\n");
  10825. goto end;
  10826. }
  10827. fp = fopen(ChargePointMaxProfile_JSON, "r");
  10828. if (!fp)
  10829. {
  10830. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  10831. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  10832. }
  10833. else
  10834. {
  10835. while(fscanf(fp, "%s", dataLine) != EOF)
  10836. {
  10837. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10838. {
  10839. profileQuantity += 1;
  10840. }
  10841. }
  10842. }
  10843. fclose(fp);
  10844. }
  10845. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10846. {
  10847. FILE *fp;
  10848. char dataLine[4096]={0};
  10849. char filename[128]={0};
  10850. int tmpProfileQuantity;
  10851. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  10852. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10853. {
  10854. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10855. DEBUG_WARN("Profile connector id is over max gun number.\n");
  10856. goto end;
  10857. }
  10858. if(SetProfileReq.ConnectorId == 0)
  10859. {
  10860. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  10861. {
  10862. tmpProfileQuantity = 0;
  10863. memset(filename, 0, ARRAY_SIZE(filename));
  10864. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10865. fp = fopen(filename, "r");
  10866. if (!fp)
  10867. {
  10868. DEBUG_INFO("%s does not create.\n", filename);
  10869. fp = fopen(filename, "w+");
  10870. }
  10871. else
  10872. {
  10873. while(fscanf(fp, "%s", dataLine) != EOF)
  10874. {
  10875. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10876. {
  10877. tmpProfileQuantity += 1;
  10878. }
  10879. }
  10880. }
  10881. fclose(fp);
  10882. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  10883. }
  10884. }
  10885. else
  10886. {
  10887. memset(filename, 0, ARRAY_SIZE(filename));
  10888. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10889. fp = fopen(filename, "r");
  10890. if (!fp)
  10891. {
  10892. DEBUG_INFO("%s does not create.\n", filename);
  10893. fp = fopen(filename, "w+");
  10894. }
  10895. else
  10896. {
  10897. while(fscanf(fp, "%s", dataLine) != EOF)
  10898. {
  10899. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10900. {
  10901. profileQuantity += 1;
  10902. }
  10903. }
  10904. }
  10905. fclose(fp);
  10906. }
  10907. }
  10908. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10909. {
  10910. int isMatchTransactiodId= FALSE;
  10911. FILE *fp;
  10912. char dataLine[4096]={0};
  10913. char filename[128]={0};
  10914. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  10915. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10916. if(SetProfileReq.ConnectorId == 0)
  10917. {
  10918. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10919. DEBUG_WARN("Profile connector id is 0.\n");
  10920. goto end;
  10921. }
  10922. int tempIndex = 0;
  10923. //check Transaction active
  10924. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  10925. {
  10926. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10927. {
  10928. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10929. }
  10930. else
  10931. {
  10932. tempIndex = SetProfileReq.ConnectorId -1;
  10933. }
  10934. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10935. {
  10936. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10937. {
  10938. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10939. {
  10940. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10941. {
  10942. isMatchTransactiodId = TRUE;
  10943. break;
  10944. }
  10945. }
  10946. }
  10947. }
  10948. }
  10949. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  10950. {
  10951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10952. {
  10953. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10954. }
  10955. else
  10956. {
  10957. tempIndex = SetProfileReq.ConnectorId -1;
  10958. }
  10959. for (int index = 0; index < CCS_QUANTITY; index++)
  10960. {
  10961. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10962. {
  10963. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  10964. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  10965. {
  10966. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10967. {
  10968. isMatchTransactiodId = TRUE;
  10969. break;
  10970. }
  10971. }
  10972. }
  10973. }
  10974. }
  10975. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  10976. {
  10977. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10978. {
  10979. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10980. }
  10981. else
  10982. {
  10983. tempIndex = SetProfileReq.ConnectorId -1;
  10984. }
  10985. for (int index = 0; index < GB_QUANTITY; index++)
  10986. {
  10987. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10988. {
  10989. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10990. {
  10991. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10992. {
  10993. isMatchTransactiodId = TRUE;
  10994. break;
  10995. }
  10996. }
  10997. }
  10998. }
  10999. }
  11000. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11001. {
  11002. tempIndex = SetProfileReq.ConnectorId -1;
  11003. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11004. {
  11005. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11006. {
  11007. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11008. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11009. {
  11010. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11011. {
  11012. isMatchTransactiodId = TRUE;
  11013. break;
  11014. }
  11015. }
  11016. }
  11017. }
  11018. }
  11019. else
  11020. {
  11021. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11022. {
  11023. tempIndex = 2;
  11024. }
  11025. else
  11026. {
  11027. tempIndex = (SetProfileReq.ConnectorId -1);
  11028. }
  11029. for (int index = 0; index < AC_QUANTITY; index++)
  11030. {
  11031. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11032. {
  11033. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11034. {
  11035. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11036. {
  11037. isMatchTransactiodId = TRUE;
  11038. break;
  11039. }
  11040. }
  11041. }
  11042. }
  11043. }
  11044. //check Transaction active
  11045. if(isMatchTransactiodId == FALSE)
  11046. {
  11047. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11048. DEBUG_WARN("Tx profile transaction id is not match.\n");
  11049. goto end;
  11050. }
  11051. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11052. {
  11053. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11054. DEBUG_WARN("Connector id is over max gun number.\n");
  11055. goto end;
  11056. }
  11057. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11058. fp = fopen(filename, "r");
  11059. if (!fp)
  11060. {
  11061. DEBUG_INFO("%s does not create.\n", filename);
  11062. fp = fopen(filename, "w+");
  11063. }
  11064. else
  11065. {
  11066. //Check Charging Profile Count
  11067. while(fscanf(fp, "%s", dataLine) != EOF)
  11068. {
  11069. //DEBUG_INFO("word=%s\n",word);
  11070. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11071. {
  11072. profileQuantity += 1;
  11073. }
  11074. }
  11075. }
  11076. fclose(fp);
  11077. }
  11078. // Check ChargeProfileMaxStackLevel
  11079. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11080. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11081. {
  11082. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11083. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11084. goto end;
  11085. }
  11086. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11087. {
  11088. FILE *fp;
  11089. char dataLine[4096]={0};
  11090. char fnametemp[128]={0};
  11091. int tmpProfileQuantity;
  11092. //Check ChargePointMaxProfile.json exit
  11093. profileQuantity = 0;
  11094. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11095. {
  11096. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11097. //Check Charging Profile Count
  11098. tmpProfileQuantity = 0;
  11099. while(fscanf(fp, "%s", dataLine) != EOF)
  11100. {
  11101. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11102. {
  11103. profileQuantity += 1;
  11104. tmpProfileQuantity += 1;
  11105. }
  11106. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11107. }
  11108. fclose(fp);
  11109. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11110. }
  11111. //Check TxDefaultProfile_%d.json
  11112. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11113. {
  11114. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11115. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11116. if((access(fnametemp,F_OK))!=-1)
  11117. {
  11118. fp = fopen(fnametemp, "r");
  11119. //Check Charging Profile Count
  11120. tmpProfileQuantity = 0;
  11121. while(fscanf(fp, "%s", dataLine) != EOF)
  11122. {
  11123. //DEBUG_INFO("word=%s\n",word);
  11124. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11125. {
  11126. profileQuantity += 1;
  11127. tmpProfileQuantity += 1;
  11128. }
  11129. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11130. }
  11131. fclose(fp);
  11132. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11133. }
  11134. }
  11135. //Check TxProfile_%d.json
  11136. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11137. {
  11138. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11139. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  11140. if((access(fnametemp,F_OK))!=-1)
  11141. {
  11142. fp = fopen(fnametemp, "r");
  11143. //Check Charging Profile Count
  11144. tmpProfileQuantity = 0;
  11145. while(fscanf(fp, "%s", dataLine) != EOF)
  11146. {
  11147. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11148. {
  11149. profileQuantity += 1;
  11150. tmpProfileQuantity += 1;
  11151. }
  11152. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11153. }
  11154. fclose(fp);
  11155. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11156. }
  11157. }
  11158. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11159. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11160. {
  11161. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11162. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11163. goto end;
  11164. }
  11165. }
  11166. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11167. //**********************************Write to File********************************************************/
  11168. {
  11169. FILE *infile;
  11170. FILE *outfile;
  11171. char dataLine[4096]={0};
  11172. char filename[128]={0};
  11173. int chkChar=0;
  11174. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11175. {
  11176. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11177. {
  11178. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11179. }
  11180. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11181. {
  11182. if(SetProfileReq.ConnectorId==0)
  11183. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11184. else
  11185. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11186. }
  11187. else
  11188. {
  11189. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11190. }
  11191. infile = fopen (filename, "r");
  11192. outfile = fopen (tempfile, "w");
  11193. chkChar = fgetc(infile);
  11194. rewind(infile);
  11195. if(chkChar == EOF)
  11196. {
  11197. // Profile is empty
  11198. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11199. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11200. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11201. fclose(infile);
  11202. fclose(outfile);
  11203. sprintf(rmFileCmd,"rm -f %s",filename);
  11204. system(rmFileCmd);
  11205. rename(tempfile, filename);
  11206. }
  11207. else
  11208. {
  11209. // Profile is not empty
  11210. int ChargingProfileAdded = FALSE;
  11211. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11212. {
  11213. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11214. json_object *tmpChargingProfile;
  11215. tmpChargingProfile = json_tokener_parse(dataLine);
  11216. if(!is_error(SetChargingProfile))
  11217. {
  11218. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11219. {
  11220. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11221. {
  11222. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11223. }
  11224. }
  11225. }
  11226. json_object_put(tmpChargingProfile);
  11227. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11228. {
  11229. if(ChargingProfileAdded == FALSE)
  11230. {
  11231. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11232. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11233. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11234. ChargingProfileAdded = TRUE;
  11235. }
  11236. }
  11237. else
  11238. {
  11239. fprintf(outfile,"%s\n",dataLine);
  11240. if(ChargingProfileAdded == FALSE)
  11241. {
  11242. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11243. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11244. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11245. ChargingProfileAdded = TRUE;
  11246. }
  11247. }
  11248. } // end of while loop
  11249. fclose(infile);
  11250. fclose(outfile);
  11251. sprintf(rmFileCmd,"rm -f %s",filename);
  11252. system(rmFileCmd);
  11253. rename(tempfile, filename);
  11254. }
  11255. }
  11256. sleep(1);
  11257. result = TRUE;
  11258. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11259. }
  11260. end:
  11261. json_object_put(SetChargingProfile);
  11262. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11263. {
  11264. if(SetProfileReq.ConnectorId == 0)
  11265. {
  11266. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11267. {
  11268. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11269. }
  11270. }
  11271. else
  11272. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11273. }
  11274. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11275. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11276. return result;
  11277. }
  11278. int handleTriggerMessageRequest(char *uuid, char *payload)
  11279. {
  11280. mtrace();
  11281. int result = FAIL;
  11282. int connectorIdIsNULL = FALSE;
  11283. int connectorIdInt =0;
  11284. char sstr[40]={0},sstrtemp[100]={ 0 };
  11285. char requestedMessagestr[40]={0};
  11286. char comfirmstr[20]={0};
  11287. int c = 0;
  11288. char *loc;
  11289. DEBUG_INFO("handleTriggerMessageRequest\n");
  11290. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11291. strcpy(sstrtemp, stringtrimspace(payload));
  11292. c = 0;
  11293. loc = strstr(sstrtemp, "requestedMessage");
  11294. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11295. {
  11296. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11297. c++;
  11298. }
  11299. sstr[c] = '\0';
  11300. strcpy(requestedMessagestr, sstr);
  11301. c = 0;
  11302. loc = strstr(sstrtemp, "connectorId");
  11303. if(loc == NULL)
  11304. {
  11305. connectorIdIsNULL = TRUE;
  11306. }
  11307. else
  11308. {
  11309. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11310. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11311. {
  11312. sstr[c] = loc[strlen("connectorId")+2+c];
  11313. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11314. c++;
  11315. }
  11316. sstr[c] = '\0';
  11317. connectorIdInt = atoi(sstr);
  11318. }
  11319. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11320. {
  11321. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11322. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11323. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11324. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11325. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11326. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11327. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11328. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11329. {
  11330. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11331. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11332. return TRUE;
  11333. }
  11334. else
  11335. {
  11336. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11337. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11338. }
  11339. }
  11340. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11341. {
  11342. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11343. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11344. return TRUE;
  11345. }
  11346. //==========================
  11347. // Trigger message
  11348. //==========================
  11349. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11350. {
  11351. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11352. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11353. {
  11354. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11355. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11356. }
  11357. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11358. }
  11359. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11360. {
  11361. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11362. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11363. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11364. }
  11365. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11366. {
  11367. //sendBootNotificationRequest();
  11368. server_sign = FALSE;
  11369. }
  11370. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11371. {
  11372. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11373. }
  11374. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11375. {
  11376. if(connectorIdIsNULL == FALSE)
  11377. {
  11378. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11379. {
  11380. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11381. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11382. }
  11383. }
  11384. else
  11385. {
  11386. for(int idx=0;idx< gunTotalNumber;idx++)
  11387. {
  11388. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11389. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11390. }
  11391. }
  11392. }
  11393. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11394. {
  11395. if(connectorIdIsNULL == FALSE)
  11396. {
  11397. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11398. {
  11399. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11400. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11401. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11402. }
  11403. }
  11404. else
  11405. {
  11406. for(int idx=0;idx< gunTotalNumber;idx++)
  11407. {
  11408. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11409. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11410. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11411. }
  11412. }
  11413. }
  11414. return result;
  11415. }
  11416. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11417. {
  11418. mtrace();
  11419. int result = FAIL;
  11420. int connectorIdInt =0;
  11421. char comfirmstr[20]={0};
  11422. int tempIndex = 0;
  11423. json_object *UnlockConnector;
  11424. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11425. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11426. UnlockConnector = json_tokener_parse(payload);
  11427. if(!is_error(UnlockConnector))
  11428. {
  11429. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11430. {
  11431. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11432. }
  11433. }
  11434. json_object_put(UnlockConnector);
  11435. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11436. if(gunTotalNumber == 0)
  11437. {
  11438. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11439. goto end;
  11440. }
  11441. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11442. {
  11443. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11444. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11445. goto end;
  11446. }
  11447. else
  11448. {
  11449. //check Transaction active
  11450. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11451. {
  11452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11453. {
  11454. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11455. }
  11456. else
  11457. {
  11458. tempIndex = connectorIdInt -1;
  11459. }
  11460. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11461. {
  11462. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  11463. {
  11464. //stop Transaction
  11465. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11466. }
  11467. }
  11468. }
  11469. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11470. {
  11471. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11472. {
  11473. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11474. }
  11475. else
  11476. {
  11477. tempIndex = connectorIdInt -1;
  11478. }
  11479. for (int index = 0; index < CCS_QUANTITY; index++)
  11480. {
  11481. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  11482. {
  11483. //stop Transaction
  11484. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11485. }
  11486. }
  11487. }
  11488. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11489. {
  11490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11491. {
  11492. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11493. }
  11494. else
  11495. {
  11496. tempIndex = connectorIdInt -1;
  11497. }
  11498. for (int index = 0; index < GB_QUANTITY; index++)
  11499. {
  11500. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  11501. {
  11502. //stop Transaction
  11503. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11504. }
  11505. }
  11506. }
  11507. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11508. {
  11509. tempIndex = connectorIdInt -1;
  11510. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11511. {
  11512. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  11513. {
  11514. //stop Transaction
  11515. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11516. }
  11517. }
  11518. }
  11519. else
  11520. {
  11521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11522. {
  11523. tempIndex = 2;
  11524. }
  11525. else
  11526. {
  11527. tempIndex = connectorIdInt-1;
  11528. }
  11529. for (int index = 0; index < AC_QUANTITY; index++)
  11530. {
  11531. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  11532. {
  11533. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11534. }
  11535. }
  11536. }
  11537. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11538. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11539. result = TRUE;
  11540. return result;
  11541. }
  11542. end:
  11543. //json_object_put(obj); --- remove temporally
  11544. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11545. return result;
  11546. }
  11547. static char UpdateFirmwarepayloadData[300]={0};
  11548. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11549. {
  11550. mtrace();
  11551. int result = FAIL;
  11552. pthread_t t;
  11553. sendUpdateFirmwareConfirmation(uuid);
  11554. memset(UpdateFirmwarepayloadData, 0, 300);
  11555. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11556. if(!interLock.isUpdateFirmwareGoing)
  11557. {
  11558. interLock.isUpdateFirmwareGoing = 1;
  11559. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11560. sleep(1);
  11561. }
  11562. else
  11563. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11564. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11565. return result;
  11566. }
  11567. void *UpdateFirmwareProcess(void *data)
  11568. {
  11569. pthread_detach(pthread_self());
  11570. mtrace();
  11571. int retriesInt =0, retryIntervalInt=0;
  11572. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11573. int port=0;
  11574. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11575. int isSuccess = 0;
  11576. char ftpbuf[1024];
  11577. char temp[1024];
  11578. char * pch;
  11579. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11580. json_object *UpdateFirmware;
  11581. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11582. if(!is_error(UpdateFirmware))
  11583. {
  11584. // Required data
  11585. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11586. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11587. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11588. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11589. // Optional data
  11590. if(json_object_object_get(UpdateFirmware, "retries"))
  11591. {
  11592. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11593. }
  11594. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11595. {
  11596. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11597. }
  11598. }
  11599. json_object_put(UpdateFirmware);
  11600. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11601. memset(path, 0, ARRAY_SIZE(path));
  11602. // Wait retrieveData
  11603. if(strlen(retrieveDatestr) > 10)
  11604. {
  11605. do
  11606. {
  11607. sleep(1);
  11608. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11609. }
  11610. // Ready to download
  11611. system("rm -f /mnt/*");
  11612. if(strncmp(locationstr,"http", 4) == 0)
  11613. {
  11614. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11615. sprintf(ftppath,"/%s", path);
  11616. DEBUG_INFO("locationstr: %s\n", locationstr);
  11617. DEBUG_INFO("protocol: %s\n",protocol);
  11618. DEBUG_INFO("host: %s\n",host);
  11619. DEBUG_INFO("path: %s\n",path);
  11620. DEBUG_INFO("ftppath: %s\n",ftppath);
  11621. int ftppathlen=strlen(ftppath);
  11622. int i=1;
  11623. char filenametemp[50];
  11624. while(i < ftppathlen)
  11625. {
  11626. int len=ftppathlen-i;
  11627. if(ftppath[len]== 47) // '/' ascll code: 47
  11628. {
  11629. DEBUG_INFO("compare '/' all right\n");
  11630. break;
  11631. }
  11632. i=i+1;
  11633. }
  11634. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11635. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11636. filenametemp[i+1] = 0;
  11637. do
  11638. {
  11639. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11640. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11641. sleep(1);
  11642. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11643. if(!isSuccess)
  11644. {
  11645. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11646. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11647. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11648. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11649. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11650. }
  11651. else
  11652. {
  11653. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11654. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11655. }
  11656. retriesInt--;
  11657. }while((isSuccess == 0)&&(retriesInt >= 0));
  11658. }
  11659. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11660. {
  11661. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11662. memset(temp, 0, ARRAY_SIZE(temp));
  11663. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11664. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11665. int ftppathlen=strlen(ftpbuf);
  11666. int i=1;
  11667. char filenametemp[50];
  11668. while(i < ftppathlen)
  11669. {
  11670. int len=ftppathlen-i;
  11671. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11672. {
  11673. DEBUG_INFO(" compare '/' all right\n");
  11674. break;
  11675. }
  11676. i=i+1;
  11677. }
  11678. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11679. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11680. filenametemp[i+1] = 0;
  11681. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11682. pch=strchr(temp,'@');
  11683. if(pch==NULL)
  11684. {
  11685. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11686. protocol, host, &port, path);
  11687. strcpy(user,"anonymous");
  11688. strcpy(password,"");
  11689. }
  11690. else
  11691. {
  11692. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11693. protocol, user, password, host, &port, path);
  11694. }
  11695. sscanf(host,"%[^/]%s",host1, path1);
  11696. sprintf(ftppath,"%s", path1);
  11697. //DEBUG_INFO("protocol =%s\n",protocol);
  11698. //DEBUG_INFO("user =%s\n",user);
  11699. //DEBUG_INFO("password =%s\n",password);
  11700. //DEBUG_INFO("host1 =%s\n",host1);
  11701. //DEBUG_INFO("port =%d\n",port);
  11702. //DEBUG_INFO("path1 =%s\n",path1);
  11703. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11704. //ftpFile(host, user, password, port, ftppath, fname);
  11705. //download firmware pthred
  11706. if(port == 0)
  11707. {
  11708. port = 21;
  11709. }
  11710. do
  11711. {
  11712. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11713. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11714. sleep(1);
  11715. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11716. if(!isSuccess)
  11717. {
  11718. //BulldogUtil.sleepMs(interval*1000);
  11719. DEBUG_INFO("Update firmware request and download file fail.\n");
  11720. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11721. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11722. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11723. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11724. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11725. }
  11726. else
  11727. {
  11728. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11729. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11730. }
  11731. retriesInt--;
  11732. }while((!isSuccess)&&(retriesInt >= 0));
  11733. }
  11734. else
  11735. {
  11736. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11737. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11738. sleep(1);
  11739. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11740. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11741. }
  11742. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11743. interLock.isUpdateFirmwareGoing = 0;
  11744. pthread_exit(NULL);
  11745. }
  11746. int handleCertificateSignedRequest(char *uuid, char *payload)
  11747. {
  11748. mtrace();
  11749. int result = PASS;
  11750. json_object *CertificateSigned;
  11751. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11752. CertificateSigned = json_tokener_parse(payload);
  11753. if(!is_error(CertificateSigned))
  11754. {
  11755. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11756. }
  11757. json_object_put(CertificateSigned);
  11758. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11759. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11760. fclose(fp);
  11761. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11762. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11763. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11764. sendCertificateSignedConfirmation(uuid);
  11765. return result;
  11766. }
  11767. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11768. {
  11769. mtrace();
  11770. int result = PASS;
  11771. json_object *DeleteCertificate;
  11772. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11773. DeleteCertificate = json_tokener_parse(payload);
  11774. if(!is_error(DeleteCertificate))
  11775. {
  11776. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11777. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11778. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11779. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11780. }
  11781. json_object_put(DeleteCertificate);
  11782. /*
  11783. * TODO: Delete certificateSigned process
  11784. */
  11785. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11786. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11787. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11788. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11789. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11790. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11791. sendDeleteCertificateConfirmation(uuid);
  11792. return result;
  11793. }
  11794. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11795. {
  11796. mtrace();
  11797. int result = PASS;
  11798. json_object *ExtendedTriggerMessage;
  11799. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11800. ExtendedTriggerMessage = json_tokener_parse(payload);
  11801. if(!is_error(ExtendedTriggerMessage))
  11802. {
  11803. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11804. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11805. {
  11806. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11807. }
  11808. else
  11809. {
  11810. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11811. }
  11812. }
  11813. json_object_put(ExtendedTriggerMessage);
  11814. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11815. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11816. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11817. {
  11818. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11819. }
  11820. else
  11821. {
  11822. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11823. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11824. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11825. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11826. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11827. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11828. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11829. {
  11830. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11831. }
  11832. else
  11833. {
  11834. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11835. }
  11836. }
  11837. sendExtendedTriggerMessageConfirmation(uuid);
  11838. //==========================
  11839. // Trigger message
  11840. //==========================
  11841. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11842. {
  11843. //sendBootNotificationRequest();
  11844. server_sign = FALSE;
  11845. }
  11846. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11847. {
  11848. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11849. }
  11850. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11851. {
  11852. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11853. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11854. {
  11855. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11856. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11857. }
  11858. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11859. }
  11860. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11861. {
  11862. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11863. }
  11864. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11865. {
  11866. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11867. {
  11868. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11869. }
  11870. else
  11871. {
  11872. for(int idx=0;idx< gunTotalNumber;idx++)
  11873. {
  11874. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11875. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11876. }
  11877. }
  11878. }
  11879. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11880. {
  11881. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11882. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11883. {
  11884. 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\" &");
  11885. }
  11886. }
  11887. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11888. {
  11889. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11890. {
  11891. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11892. }
  11893. else
  11894. {
  11895. for(int idx=0;idx< gunTotalNumber;idx++)
  11896. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11897. }
  11898. }
  11899. return result;
  11900. }
  11901. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11902. {
  11903. mtrace();
  11904. int result = PASS;
  11905. json_object *GetInstalledCertificateIds;
  11906. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11907. GetInstalledCertificateIds = json_tokener_parse(payload);
  11908. if(!is_error(GetInstalledCertificateIds))
  11909. {
  11910. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11911. }
  11912. json_object_put(GetInstalledCertificateIds);
  11913. /*
  11914. * TODO: Return installed certificate process
  11915. */
  11916. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11917. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11918. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11919. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11920. sendGetInstalledCertificateIdsConfirmation(uuid);
  11921. return result;
  11922. }
  11923. int handleGetLogRequest(char *uuid, char *payload)
  11924. {
  11925. mtrace();
  11926. int result = PASS;
  11927. json_object *GetLog;
  11928. DEBUG_INFO("handleGetLogRequest...\n");
  11929. GetLog = json_tokener_parse(payload);
  11930. if(!is_error(GetLog))
  11931. {
  11932. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11933. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11934. if(json_object_object_get(GetLog, "retries") != NULL)
  11935. {
  11936. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11937. }
  11938. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11939. {
  11940. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11941. }
  11942. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11943. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11944. {
  11945. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11946. }
  11947. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11948. {
  11949. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11950. }
  11951. }
  11952. json_object_put(GetLog);
  11953. /*
  11954. * TODO: Upload log process
  11955. */
  11956. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11957. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11958. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11959. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11960. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11961. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11962. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11963. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11964. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11965. sendGetLogConfirmation(uuid);
  11966. return result;
  11967. }
  11968. int handleInstallCertificateRequest(char *uuid, char *payload)
  11969. {
  11970. mtrace();
  11971. int result = PASS;
  11972. json_object *InstallCertificate;
  11973. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11974. InstallCertificate = json_tokener_parse(payload);
  11975. if(!is_error(InstallCertificate))
  11976. {
  11977. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11978. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11979. /*
  11980. * TODO: Install certificate process
  11981. */
  11982. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11983. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11984. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11985. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11986. sendInstallCertificateConfirmation(uuid);
  11987. }
  11988. json_object_put(InstallCertificate);
  11989. return result;
  11990. }
  11991. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11992. {
  11993. mtrace();
  11994. int result = PASS;
  11995. json_object *SignedUpdateFirmware;
  11996. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11997. SignedUpdateFirmware = json_tokener_parse(payload);
  11998. if(!is_error(SignedUpdateFirmware))
  11999. {
  12000. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12001. {
  12002. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12003. }
  12004. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12005. {
  12006. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12007. }
  12008. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12009. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12010. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12011. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12012. {
  12013. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12014. }
  12015. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12016. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12017. }
  12018. json_object_put(SignedUpdateFirmware);
  12019. /*
  12020. * TODO: Upgrade firmware process
  12021. */
  12022. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12023. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  12024. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  12025. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  12026. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  12027. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  12028. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  12029. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  12030. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  12031. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  12032. sendInstallCertificateConfirmation(uuid);
  12033. return result;
  12034. }
  12035. int handleUnknownRequest(char *uuid, char *payload)
  12036. {
  12037. mtrace();
  12038. int result = PASS;
  12039. DEBUG_INFO("handleUnknownRequest...\n");
  12040. sendUnknownConfirmation(uuid);
  12041. result = PASS;
  12042. return result;
  12043. }
  12044. //==========================================
  12045. // Handle server response routine
  12046. //==========================================
  12047. void handleAuthorizeResponse(char *payload, int gun_index)
  12048. {
  12049. mtrace();
  12050. char expiryDatestr[30]={0};
  12051. char parentIdTagstr[20]={0};
  12052. char statusstr[20]={0};
  12053. int expiryDateISNULL=FALSE;
  12054. int parentIdTagISNULL=FALSE;
  12055. DEBUG_INFO("handleAuthorizeResponse...\n");
  12056. json_object *Authorize;
  12057. Authorize = json_tokener_parse(payload);
  12058. if(!is_error(Authorize))
  12059. {
  12060. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12061. {
  12062. // Required data
  12063. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12064. // Optional data
  12065. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12066. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12067. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12068. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12069. }
  12070. }
  12071. json_object_put(Authorize);
  12072. if(expiryDateISNULL == FALSE)
  12073. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12074. if(parentIdTagISNULL == FALSE)
  12075. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12076. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12077. //Update idTag information to authorization cache if supproted
  12078. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12079. {
  12080. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12081. }
  12082. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12083. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12084. authorizeRetryTimes = 0;
  12085. }
  12086. void handleBootNotificationResponse(char *payload, int gun_index)
  12087. {
  12088. mtrace();
  12089. char statusStr[12]={0};
  12090. char currentTimeStr[30]={0};
  12091. int intervalInt = 0;
  12092. DEBUG_INFO("handleBootNotificationResponse...\n");
  12093. json_object *BootNotification;
  12094. BootNotification = json_tokener_parse(payload);
  12095. if(!is_error(BootNotification))
  12096. {
  12097. // Required data
  12098. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12099. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12100. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12101. }
  12102. json_object_put(BootNotification);
  12103. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12104. BootNotificationInterval = intervalInt;
  12105. HeartBeatWaitTime = intervalInt;
  12106. //write back to ShmOCPP16Data->BootNotification
  12107. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12108. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12109. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12110. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12111. {
  12112. server_sign = TRUE;
  12113. server_pending =FALSE;
  12114. }
  12115. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12116. {
  12117. server_pending = TRUE;
  12118. }
  12119. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12120. srand(time(NULL));
  12121. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12122. SetOcppConnStatus(TRUE);
  12123. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12124. }
  12125. void handleDataTransferResponse(char *payload, int gun_index)
  12126. {
  12127. char sstr[160]={0};//sstr[200]={ 0 };
  12128. int c = 0;
  12129. char *loc;
  12130. DEBUG_INFO("handleDataTransferResponse ...\n");
  12131. loc = strstr(payload, "status");
  12132. c = 0;
  12133. while (loc[3+strlen("status")+c] != '\"')
  12134. {
  12135. sstr[c] = loc[3+strlen("status")+c];
  12136. c++;
  12137. }
  12138. sstr[c] = '\0';
  12139. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12140. }
  12141. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12142. {
  12143. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12144. //struct json_object *obj;
  12145. // obj = json_tokener_parse(payload);
  12146. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12147. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12148. //No fields are defined.
  12149. }
  12150. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12151. {
  12152. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12153. //struct json_object *obj;
  12154. // obj = json_tokener_parse(payload);
  12155. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12156. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12157. //No fields are defined.
  12158. }
  12159. void handleHeartbeatResponse(char *payload, int gun_index)
  12160. {
  12161. mtrace();
  12162. DEBUG_INFO("handleHeartbeatResponse...\n");
  12163. json_object *Heartbeat;
  12164. Heartbeat = json_tokener_parse(payload);
  12165. if(!is_error(Heartbeat))
  12166. {
  12167. // Required data
  12168. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12169. }
  12170. json_object_put(Heartbeat);
  12171. if(FirstHeartBeat == 0)
  12172. {
  12173. FirstHeartBeat = 1;
  12174. DEBUG_INFO("FirstHeartBeat \n");
  12175. }
  12176. HeartBeatWithNOResponse = 0;
  12177. clientTime.Heartbeat=time((time_t*)NULL);
  12178. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12179. }
  12180. void handleMeterValuesResponse(char *payload, int gun_index)
  12181. {
  12182. mtrace();
  12183. DEBUG_INFO("handleMeterValuesResponse...\n");
  12184. }
  12185. void handleStartTransactionResponse(char *payload, int gun_index)
  12186. {
  12187. mtrace();
  12188. //int transactionIdInt = 0;
  12189. FILE *outfile;
  12190. char data[100]={0};
  12191. DEBUG_INFO("handleStartTransactionResponse...\n");
  12192. json_object *StartTransaction;
  12193. StartTransaction = json_tokener_parse(payload);
  12194. if(!is_error(StartTransaction))
  12195. {
  12196. // Required data
  12197. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12198. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12199. // Optional data
  12200. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12201. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12202. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12203. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12204. }
  12205. json_object_put(StartTransaction);
  12206. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12207. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12208. //-----------Start : write to the Queue TransactionId file -----------------//
  12209. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12210. {}
  12211. else
  12212. {
  12213. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12214. if(log == NULL)
  12215. {
  12216. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12217. return ;
  12218. }
  12219. else
  12220. {
  12221. fclose(log);
  12222. }
  12223. }
  12224. // open file for writing
  12225. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12226. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12227. {
  12228. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12229. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12230. fputs(data, outfile);
  12231. fclose (outfile);
  12232. }
  12233. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12234. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12235. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12236. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12237. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12238. }
  12239. void handleStatusNotificationResponse(char *payload, int gun_index)
  12240. {
  12241. mtrace();
  12242. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12243. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12244. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12245. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12246. }
  12247. void handleStopTransactionnResponse(char *payload, int gun_index)
  12248. {
  12249. mtrace();
  12250. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12251. json_object *StopTransaction;
  12252. StopTransaction = json_tokener_parse(payload);
  12253. if(!is_error(StopTransaction))
  12254. {
  12255. // Optional data
  12256. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12257. {
  12258. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12259. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12261. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12263. }
  12264. }
  12265. json_object_put(StopTransaction);
  12266. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12267. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12268. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12269. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12270. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12271. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  12272. }
  12273. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12274. {
  12275. mtrace();
  12276. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12277. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12278. }
  12279. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12280. {
  12281. mtrace();
  12282. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12283. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12284. }
  12285. void handleSignCertificateResponse(char *payload, int gun_index)
  12286. {
  12287. mtrace();
  12288. DEBUG_INFO("handleSignCertificateResponse...\n");
  12289. json_object *SignCertificate;
  12290. SignCertificate = json_tokener_parse(payload);
  12291. if(!is_error(SignCertificate))
  12292. {
  12293. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12294. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12295. }
  12296. json_object_put(SignCertificate);
  12297. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12298. }
  12299. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12300. {
  12301. mtrace();
  12302. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12303. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12304. }
  12305. //==========================================
  12306. // Handle Error routine
  12307. //==========================================
  12308. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12309. {
  12310. mtrace();
  12311. #ifdef SystemLogMessage
  12312. DEBUG_INFO("errorCode: %s\n", errorCode);
  12313. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12314. DEBUG_INFO("errorDetails: %s\n", payload);
  12315. #endif
  12316. }
  12317. //===============================================
  12318. // Common routine
  12319. //===============================================
  12320. int initialConfigurationTable(void)
  12321. {
  12322. //clock_t start_t, end_t, total_t;
  12323. FILE *fp;
  12324. FILE *outfile;
  12325. char str[512]={0};
  12326. char sstr[256]={0};
  12327. int c = 0;
  12328. char *loc;
  12329. int confVersion = 10;
  12330. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12331. //start_t = clock();
  12332. //printf("Starting of the program, start_t = %ld\n", start_t);
  12333. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12334. // Check configuration file size is correct
  12335. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12336. {
  12337. struct stat st;
  12338. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12339. if(st.st_size < 3100)
  12340. {
  12341. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12342. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12343. }
  12344. }
  12345. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12346. {
  12347. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12348. if(outfile == NULL)
  12349. {
  12350. DEBUG_INFO("Error opening file\n");
  12351. return FALSE;
  12352. }
  12353. /*Core Profile*/
  12354. //AllowOfflineTxForUnknownId
  12355. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12359. //AuthorizationCacheEnabled
  12360. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12364. //AuthorizeRemoteTxRequests
  12365. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12369. //BlinkRepeat
  12370. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12374. //ClockAlignedDataInterval
  12375. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12379. //ConnectionTimeOut
  12380. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12384. //GetConfigurationMaxKeys
  12385. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12389. // HeartbeatInterval
  12390. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12394. // LightIntensity
  12395. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12399. // LocalAuthorizeOffline
  12400. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12404. // LocalPreAuthorize
  12405. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12409. // MaxEnergyOnInvalidId
  12410. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12414. // MeterValuesAlignedData
  12415. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12417. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12418. 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" );
  12419. else
  12420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12422. // MeterValuesAlignedDataMaxLength
  12423. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12425. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12427. else
  12428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12430. // MeterValuesSampledData
  12431. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12433. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12434. 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" );
  12435. else
  12436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12438. // MeterValuesSampledDataMaxLength
  12439. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12441. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12443. else
  12444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12446. // MeterValueSampleInterval
  12447. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12451. // MinimumStatusDuration
  12452. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12455. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12457. // NumberOfConnectors
  12458. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12461. {
  12462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12463. }
  12464. else
  12465. {
  12466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12467. }
  12468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12469. // ResetRetries
  12470. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12474. // ConnectorPhaseRotation
  12475. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12479. // ConnectorPhaseRotationMaxLength
  12480. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12484. // StopTransactionOnEVSideDisconnect
  12485. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12489. // StopTransactionOnInvalidId
  12490. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12494. // StopTxnAlignedData
  12495. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12499. // StopTxnAlignedDataMaxLength
  12500. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12504. // StopTxnSampledData
  12505. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12507. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12509. else
  12510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12512. // StopTxnSampledDataMaxLength
  12513. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12516. {
  12517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12518. }
  12519. else
  12520. {
  12521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12522. }
  12523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12524. // SupportedFeatureProfiles
  12525. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12529. // SupportedFeatureProfilesMaxLength
  12530. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12534. // TransactionMessageAttempts
  12535. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12538. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12540. // TransactionMessageRetryInterval
  12541. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12544. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12546. // UnlockConnectorOnEVSideDisconnect
  12547. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12551. // WebSocketPingInterval
  12552. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12556. // QueueOffLineMeterValues
  12557. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12561. // AuthorizationKey
  12562. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12566. // SecurityProfile
  12567. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12571. // DefaultPrice
  12572. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12576. // CustomDisplayCostAndPrice
  12577. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12581. // CustomIdleFeeAfterStop
  12582. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12586. // TimeOffset
  12587. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12591. // NextTimeOffsetTransitionDateTime
  12592. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12596. // TimeOffsetNextTransition
  12597. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12601. // SystemUptimeSec
  12602. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  12603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  12604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  12605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  12606. // FreeVend
  12607. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  12608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  12609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  12610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  12611. // Configuration Version
  12612. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12616. //* Local Auth List Management Profile*/
  12617. #if 0
  12618. //For OCTT Test Case
  12619. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12622. #endif
  12623. #if 1
  12624. //LocalAuthListEnabled
  12625. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12629. #endif
  12630. //LocalAuthListMaxLength
  12631. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12635. //SendLocalListMaxLength
  12636. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12640. //ReserveConnectorZeroSupported
  12641. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12645. //* Smart Charging Profile */
  12646. //ChargeProfileMaxStackLevel
  12647. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12651. // ChargingScheduleAllowedChargingRateUnit
  12652. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12656. // ChargingScheduleMaxPeriods
  12657. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12661. // ConnectorSwitch3to1PhaseSupported
  12662. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12666. // MaxChargingProfilesInstalled
  12667. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12671. fclose(outfile);
  12672. }
  12673. else
  12674. {
  12675. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12676. char keystr[60]={0};
  12677. char readonlystr[10]={0};
  12678. char valuestr[256]={0};
  12679. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12680. if(fp == NULL) {
  12681. DEBUG_INFO("Error opening file");
  12682. return FALSE;
  12683. }
  12684. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12685. {
  12686. //DEBUG_INFO("Get Configuration \n");
  12687. if(strlen(str) > 0)
  12688. {
  12689. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12690. //*************************key*********************************/
  12691. if(strstr(str, "key") != NULL)
  12692. {
  12693. loc = strstr(str, "key");
  12694. c = 0;
  12695. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12696. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12697. {
  12698. sstr[c] = loc[strlen("key")+3+c];
  12699. c++;
  12700. }
  12701. sstr[c] = '\0';
  12702. strcpy(keystr,sstr);
  12703. }
  12704. //*************************readonly*********************************/
  12705. if(strstr(str, "readonly") != NULL)
  12706. {
  12707. loc = strstr(str, "readonly");
  12708. c = 0;
  12709. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12710. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12711. {
  12712. sstr[c] = loc[strlen("readonly")+2+c];
  12713. c++;
  12714. }
  12715. sstr[c] = '\0';
  12716. strcpy(readonlystr,sstr);
  12717. }
  12718. //*************************value*********************************/
  12719. if(strstr(str, "value") != NULL)
  12720. {
  12721. loc = strstr(str, "value");
  12722. c = 0;
  12723. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12724. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12725. {
  12726. sstr[c] = loc[strlen("value")+3+c];
  12727. c++;
  12728. }
  12729. sstr[c] = '\0';
  12730. strcpy(valuestr,sstr);
  12731. }
  12732. // DEBUG_INFO("keystr=%s\n",keystr);
  12733. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12734. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12735. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12736. {
  12737. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12738. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12740. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12741. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12742. }
  12743. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12744. {
  12745. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12746. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12748. }
  12749. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12750. {
  12751. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12753. }
  12754. if(strcmp(keystr, "BlinkRepeat") == 0)
  12755. {
  12756. //Charger.BlinkRepeat = Integer.parseInt(value);
  12757. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12759. }
  12760. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12761. {
  12762. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12764. }
  12765. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12766. {
  12767. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12769. }
  12770. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12771. {
  12772. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12774. }
  12775. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12776. {
  12777. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12779. HeartBeatWaitTime = atoi(valuestr);
  12780. }
  12781. if(strcmp(keystr, "LightIntensity") == 0)
  12782. {
  12783. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12785. }
  12786. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12787. {
  12788. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12790. }
  12791. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12792. {
  12793. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12795. }
  12796. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12797. {
  12798. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12800. }
  12801. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12802. {
  12803. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12805. }
  12806. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12807. {
  12808. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12810. }
  12811. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12812. {
  12813. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12815. }
  12816. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12817. {
  12818. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12820. }
  12821. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12822. {
  12823. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12825. }
  12826. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12827. {
  12828. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12830. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12831. }
  12832. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12833. {
  12834. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12836. }
  12837. if(strcmp(keystr, "ResetRetries") == 0)
  12838. {
  12839. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12841. }
  12842. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12843. {
  12844. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12846. }
  12847. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12848. {
  12849. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12851. }
  12852. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12853. {
  12854. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12856. }
  12857. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12858. {
  12859. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12861. }
  12862. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12863. {
  12864. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12866. }
  12867. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12868. {
  12869. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12871. }
  12872. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12873. {
  12874. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12876. }
  12877. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12878. {
  12879. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12881. }
  12882. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12883. {
  12884. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12886. }
  12887. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12888. {
  12889. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12891. }
  12892. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12893. {
  12894. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12896. TransactionMessageAttemptsValue = atoi(valuestr);
  12897. }
  12898. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12899. {
  12900. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12902. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12903. }
  12904. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12905. {
  12906. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12908. }
  12909. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12910. {
  12911. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12913. }
  12914. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12915. {
  12916. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12918. }
  12919. if(strcmp(keystr, "AuthorizationKey") == 0)
  12920. {
  12921. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12922. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12924. }
  12925. if(strcmp(keystr, "SecurityProfile") == 0)
  12926. {
  12927. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12929. }
  12930. if(strcmp(keystr, "DefaultPrice") == 0)
  12931. {
  12932. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12934. }
  12935. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12936. {
  12937. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12939. }
  12940. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12941. {
  12942. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12944. }
  12945. if(strcmp(keystr, "TimeOffset") == 0)
  12946. {
  12947. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12949. }
  12950. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12951. {
  12952. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12954. }
  12955. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12956. {
  12957. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12959. }
  12960. if(strcmp(keystr, "SystemUptimeSec") == 0)
  12961. {
  12962. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  12964. }
  12965. if(strcmp(keystr, "FreeVend") == 0)
  12966. {
  12967. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  12969. }
  12970. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12971. {
  12972. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12974. }
  12975. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12976. {
  12977. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12979. }
  12980. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12981. {
  12982. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12984. }
  12985. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12986. {
  12987. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12989. }
  12990. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12991. {
  12992. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12994. }
  12995. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12996. {
  12997. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12999. }
  13000. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13001. {
  13002. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13004. }
  13005. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13006. {
  13007. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13009. }
  13010. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13011. {
  13012. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13014. }
  13015. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13016. {
  13017. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13019. }
  13020. }
  13021. }
  13022. fclose(fp);
  13023. }
  13024. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13025. {
  13026. return PASS;
  13027. }
  13028. else
  13029. {
  13030. return FAIL;
  13031. }
  13032. }
  13033. void StoreConfigurationTable(void)
  13034. {
  13035. FILE *outfile;
  13036. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13037. if(outfile == NULL)
  13038. {
  13039. DEBUG_INFO("Error opening file");
  13040. return ;
  13041. }
  13042. /*Core Profile*/
  13043. //AllowOfflineTxForUnknownId
  13044. /*
  13045. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13046. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13049. */
  13050. //DEBUG_INFO("data=%s\n",data);
  13051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13052. //AuthorizationCacheEnabled
  13053. /*
  13054. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13057. */
  13058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13059. //AuthorizeRemoteTxRequests
  13060. /*
  13061. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13064. */
  13065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13066. //BlinkRepeat
  13067. /*
  13068. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13071. */
  13072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13073. //ClockAlignedDataInterval
  13074. /*
  13075. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13078. */
  13079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13080. //ConnectionTimeOut
  13081. /*
  13082. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13085. */
  13086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13087. //GetConfigurationMaxKeys
  13088. /*
  13089. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13092. */
  13093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13094. // HeartbeatInterval
  13095. /*
  13096. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13099. */
  13100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13101. // LightIntensity
  13102. /*
  13103. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13106. */
  13107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13108. // LocalAuthorizeOffline
  13109. /*
  13110. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13113. */
  13114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13115. // LocalPreAuthorize
  13116. /*
  13117. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13120. */
  13121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13122. // MaxEnergyOnInvalidId
  13123. /*
  13124. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13127. */
  13128. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13130. // MeterValuesAlignedData
  13131. /*
  13132. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13135. */
  13136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13137. // MeterValuesAlignedDataMaxLength
  13138. /*
  13139. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13142. */
  13143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13144. // MeterValuesSampledData
  13145. /*
  13146. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13149. */
  13150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13151. // MeterValuesSampledDataMaxLength
  13152. /*
  13153. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13156. */
  13157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13158. // MeterValueSampleInterval
  13159. /*
  13160. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13163. */
  13164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13165. // MinimumStatusDuration
  13166. /*
  13167. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13170. */
  13171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13172. // NumberOfConnectors
  13173. /*
  13174. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13177. {
  13178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13179. }
  13180. else
  13181. {
  13182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13183. }
  13184. */
  13185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13186. // ResetRetries
  13187. /*
  13188. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13191. */
  13192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13193. // ConnectorPhaseRotation
  13194. /*
  13195. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13198. */
  13199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13200. // ConnectorPhaseRotationMaxLength
  13201. /*
  13202. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13205. */
  13206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13207. // StopTransactionOnEVSideDisconnect
  13208. /*
  13209. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13212. */
  13213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13214. // StopTransactionOnInvalidId
  13215. /*
  13216. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13219. */
  13220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13221. // StopTxnAlignedData
  13222. /*
  13223. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13226. */
  13227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13228. // StopTxnAlignedDataMaxLength
  13229. /*
  13230. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13233. */
  13234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13235. // StopTxnSampledData
  13236. /*
  13237. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13240. */
  13241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13242. // StopTxnSampledDataMaxLength
  13243. /*
  13244. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13247. */
  13248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13249. // SupportedFeatureProfiles
  13250. /*
  13251. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13254. */
  13255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13256. // SupportedFeatureProfilesMaxLength
  13257. /*
  13258. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13261. */
  13262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13263. // TransactionMessageAttempts
  13264. /*
  13265. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13268. */
  13269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13270. // TransactionMessageRetryInterval
  13271. /*
  13272. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13275. */
  13276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13277. // UnlockConnectorOnEVSideDisconnect
  13278. /*
  13279. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13282. */
  13283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13284. // WebSocketPingInterval
  13285. /*
  13286. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13289. */
  13290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13291. // QueueOffLineMeterValues
  13292. /*
  13293. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13296. */
  13297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13298. // AuthorizationKey
  13299. /*
  13300. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13303. */
  13304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13305. // SecurityProfile
  13306. /*
  13307. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13310. */
  13311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13312. // DefaultPrice
  13313. /*
  13314. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13317. */
  13318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13319. // CustomDisplayCostAndPrice
  13320. /*
  13321. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13324. */
  13325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13326. // CustomIdleFeeAfterStop
  13327. /*
  13328. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13331. */
  13332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13333. // TimeOffset
  13334. /*
  13335. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13338. */
  13339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13340. // NextTimeOffsetTransitionDateTime
  13341. /*
  13342. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13345. */
  13346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13347. // TimeOffsetNextTransition
  13348. /*
  13349. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13352. */
  13353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13354. // SystemUptimeSec
  13355. /*
  13356. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13359. */
  13360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13361. // FreeVend
  13362. /*
  13363. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  13366. */
  13367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13368. // ConfigurationVersion
  13369. /*
  13370. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13373. */
  13374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13375. //* Local Auth List Management Profile*/
  13376. //LocalAuthListEnabled
  13377. /*
  13378. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13381. */
  13382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13383. //LocalAuthListMaxLength
  13384. /*
  13385. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13388. */
  13389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13390. //SendLocalListMaxLength
  13391. /*
  13392. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13395. */
  13396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13397. //ReserveConnectorZeroSupported
  13398. /*
  13399. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13402. */
  13403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13404. //* Smart Charging Profile */
  13405. //ChargeProfileMaxStackLevel
  13406. /*
  13407. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13410. */
  13411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13412. // ChargingScheduleAllowedChargingRateUnit
  13413. /*
  13414. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13417. */
  13418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13419. // ChargingScheduleMaxPeriods
  13420. /*
  13421. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13424. */
  13425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13426. // ConnectorSwitch3to1PhaseSupported
  13427. /*
  13428. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13431. */
  13432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13433. // MaxChargingProfilesInstalled
  13434. /*
  13435. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13438. */
  13439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13440. fclose(outfile);
  13441. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13442. }
  13443. void getKeyValue(char *keyReq)
  13444. {
  13445. int isEmpty = FALSE;
  13446. int isKnowKey = FALSE;
  13447. DEBUG_INFO("keyReq = %s\n", keyReq);
  13448. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13449. isEmpty = TRUE;
  13450. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13451. {
  13452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13455. {
  13456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13457. }
  13458. else
  13459. {
  13460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13461. }
  13462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13463. isKnowKey = TRUE;
  13464. }
  13465. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13466. {
  13467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13470. {
  13471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13472. }
  13473. else
  13474. {
  13475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13476. }
  13477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13478. isKnowKey = TRUE;
  13479. }
  13480. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13481. {
  13482. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13485. {
  13486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13487. }
  13488. else
  13489. {
  13490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13491. }
  13492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13493. isKnowKey = TRUE;
  13494. }
  13495. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13496. {
  13497. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13500. {
  13501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13502. }
  13503. else
  13504. {
  13505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13506. }
  13507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13508. isKnowKey = TRUE;
  13509. }
  13510. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13511. {
  13512. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13515. {
  13516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13517. }
  13518. else
  13519. {
  13520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13521. }
  13522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13523. isKnowKey = TRUE;
  13524. }
  13525. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13526. {
  13527. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13530. {
  13531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13532. }
  13533. else
  13534. {
  13535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13536. }
  13537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13538. isKnowKey = TRUE;
  13539. }
  13540. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13541. {
  13542. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13544. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13545. {
  13546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13547. }
  13548. else
  13549. {
  13550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13551. }
  13552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13553. isKnowKey = TRUE;
  13554. }
  13555. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13556. {
  13557. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13560. {
  13561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13562. }
  13563. else
  13564. {
  13565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13566. }
  13567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13568. isKnowKey = TRUE;
  13569. }
  13570. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13571. {
  13572. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13574. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13575. {
  13576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13577. }
  13578. else
  13579. {
  13580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13581. }
  13582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13583. isKnowKey = TRUE;
  13584. }
  13585. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13586. {
  13587. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13590. {
  13591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13592. }
  13593. else
  13594. {
  13595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13596. }
  13597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13598. isKnowKey = TRUE;
  13599. }
  13600. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13601. {
  13602. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13604. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13605. {
  13606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13607. }
  13608. else
  13609. {
  13610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13611. }
  13612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13613. isKnowKey = TRUE;
  13614. }
  13615. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13616. {
  13617. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13620. {
  13621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13622. }
  13623. else
  13624. {
  13625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13626. }
  13627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13628. isKnowKey = TRUE;
  13629. }
  13630. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13631. {
  13632. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13634. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13635. {
  13636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13637. }
  13638. else
  13639. {
  13640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13641. }
  13642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13643. isKnowKey = TRUE;
  13644. }
  13645. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13646. {
  13647. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13649. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13650. {
  13651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13652. }
  13653. else
  13654. {
  13655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13656. }
  13657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13658. isKnowKey = TRUE;
  13659. }
  13660. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13661. {
  13662. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13664. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13665. {
  13666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13667. }
  13668. else
  13669. {
  13670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13671. }
  13672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13673. isKnowKey = TRUE;
  13674. }
  13675. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13676. {
  13677. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13680. {
  13681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13682. }
  13683. else
  13684. {
  13685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13686. }
  13687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13688. isKnowKey = TRUE;
  13689. }
  13690. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13691. {
  13692. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13695. {
  13696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13697. }
  13698. else
  13699. {
  13700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13701. }
  13702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13703. isKnowKey = TRUE;
  13704. }
  13705. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13706. {
  13707. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13709. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13710. {
  13711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13712. }
  13713. else
  13714. {
  13715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13716. }
  13717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13718. isKnowKey = TRUE;
  13719. }
  13720. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13721. {
  13722. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13725. {
  13726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13727. }
  13728. else
  13729. {
  13730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13731. }
  13732. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13734. isKnowKey = TRUE;
  13735. }
  13736. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13737. {
  13738. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13740. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13741. {
  13742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13743. }
  13744. else
  13745. {
  13746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13747. }
  13748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13749. isKnowKey = TRUE;
  13750. }
  13751. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13752. {
  13753. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13756. {
  13757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13758. }
  13759. else
  13760. {
  13761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13762. }
  13763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13764. isKnowKey = TRUE;
  13765. }
  13766. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13767. {
  13768. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13771. {
  13772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13773. }
  13774. else
  13775. {
  13776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13777. }
  13778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13779. isKnowKey = TRUE;
  13780. }
  13781. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13782. {
  13783. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13786. {
  13787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13788. }
  13789. else
  13790. {
  13791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13792. }
  13793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13794. isKnowKey = TRUE;
  13795. }
  13796. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13797. {
  13798. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13801. {
  13802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13803. }
  13804. else
  13805. {
  13806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13807. }
  13808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13809. isKnowKey = TRUE;
  13810. }
  13811. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13812. {
  13813. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13816. {
  13817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13818. }
  13819. else
  13820. {
  13821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13822. }
  13823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13824. isKnowKey = TRUE;
  13825. }
  13826. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13827. {
  13828. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13830. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13831. {
  13832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13833. }
  13834. else
  13835. {
  13836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13837. }
  13838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13839. isKnowKey = TRUE;
  13840. }
  13841. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13842. {
  13843. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13846. {
  13847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13848. }
  13849. else
  13850. {
  13851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13852. }
  13853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13854. isKnowKey = TRUE;
  13855. }
  13856. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13857. {
  13858. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13861. {
  13862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13863. }
  13864. else
  13865. {
  13866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13867. }
  13868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13869. isKnowKey = TRUE;
  13870. }
  13871. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13872. {
  13873. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13876. {
  13877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13878. }
  13879. else
  13880. {
  13881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13882. }
  13883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13884. isKnowKey = TRUE;
  13885. }
  13886. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13887. {
  13888. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13891. {
  13892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13893. }
  13894. else
  13895. {
  13896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13897. }
  13898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13899. isKnowKey = TRUE;
  13900. }
  13901. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13902. {
  13903. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13906. {
  13907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13908. }
  13909. else
  13910. {
  13911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13912. }
  13913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13914. isKnowKey = TRUE;
  13915. }
  13916. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13917. {
  13918. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13921. {
  13922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13923. }
  13924. else
  13925. {
  13926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13927. }
  13928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13929. isKnowKey = TRUE;
  13930. }
  13931. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13932. {
  13933. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13936. {
  13937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13938. }
  13939. else
  13940. {
  13941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13942. }
  13943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13944. isKnowKey = TRUE;
  13945. }
  13946. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13947. {
  13948. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13951. {
  13952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13953. }
  13954. else
  13955. {
  13956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13957. }
  13958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13959. isKnowKey = TRUE;
  13960. }
  13961. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13962. {
  13963. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13966. {
  13967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13968. }
  13969. else
  13970. {
  13971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13972. }
  13973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13974. isKnowKey = TRUE;
  13975. }
  13976. /*
  13977. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13978. {
  13979. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13982. {
  13983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13984. }
  13985. else
  13986. {
  13987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13988. }
  13989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13990. isKnowKey = TRUE;
  13991. }*/
  13992. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13993. {
  13994. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13997. {
  13998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13999. }
  14000. else
  14001. {
  14002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14003. }
  14004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14005. isKnowKey = TRUE;
  14006. }
  14007. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14008. {
  14009. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14012. {
  14013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14014. }
  14015. else
  14016. {
  14017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14018. }
  14019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14020. isKnowKey = TRUE;
  14021. }
  14022. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14023. {
  14024. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14027. {
  14028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14029. }
  14030. else
  14031. {
  14032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14033. }
  14034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14035. isKnowKey = TRUE;
  14036. }
  14037. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14038. {
  14039. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14042. {
  14043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14044. }
  14045. else
  14046. {
  14047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14048. }
  14049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14050. isKnowKey = TRUE;
  14051. }
  14052. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14053. {
  14054. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14057. {
  14058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14059. }
  14060. else
  14061. {
  14062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14063. }
  14064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14065. isKnowKey = TRUE;
  14066. }
  14067. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14068. {
  14069. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14072. {
  14073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14074. }
  14075. else
  14076. {
  14077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14078. }
  14079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14080. isKnowKey = TRUE;
  14081. }
  14082. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14083. {
  14084. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14087. {
  14088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14089. }
  14090. else
  14091. {
  14092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14093. }
  14094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14095. isKnowKey = TRUE;
  14096. }
  14097. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14098. {
  14099. struct sysinfo s_info;
  14100. int error = sysinfo(&s_info);
  14101. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14104. {
  14105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14106. }
  14107. else
  14108. {
  14109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14110. }
  14111. if(error != 0)
  14112. {
  14113. DEBUG_WARN("System uptime get error: %d\n", error);
  14114. }
  14115. else
  14116. {
  14117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14118. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14119. }
  14120. isKnowKey = TRUE;
  14121. }
  14122. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14123. {
  14124. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14127. {
  14128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14129. }
  14130. else
  14131. {
  14132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14133. }
  14134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  14135. isKnowKey = TRUE;
  14136. }
  14137. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14138. {
  14139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14142. {
  14143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14144. }
  14145. else
  14146. {
  14147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14148. }
  14149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14150. isKnowKey = TRUE;
  14151. }
  14152. #if 1
  14153. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14154. {
  14155. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14157. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14158. {
  14159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14160. }
  14161. else
  14162. {
  14163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14164. }
  14165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14166. isKnowKey = TRUE;
  14167. }
  14168. #endif
  14169. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14170. {
  14171. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14173. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14174. {
  14175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14176. }
  14177. else
  14178. {
  14179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14180. }
  14181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14182. isKnowKey = TRUE;
  14183. }
  14184. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14185. {
  14186. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14188. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14189. {
  14190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14191. }
  14192. else
  14193. {
  14194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14195. }
  14196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14197. isKnowKey = TRUE;
  14198. }
  14199. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14200. {
  14201. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14203. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14204. {
  14205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14206. }
  14207. else
  14208. {
  14209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14210. }
  14211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14212. isKnowKey = TRUE;
  14213. }
  14214. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14215. {
  14216. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14218. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14219. {
  14220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14221. }
  14222. else
  14223. {
  14224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14225. }
  14226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14227. isKnowKey = TRUE;
  14228. }
  14229. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14230. {
  14231. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14233. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14234. {
  14235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14236. }
  14237. else
  14238. {
  14239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14240. }
  14241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14242. isKnowKey = TRUE;
  14243. }
  14244. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14245. {
  14246. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14248. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14249. {
  14250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14251. }
  14252. else
  14253. {
  14254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14255. }
  14256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14257. isKnowKey = TRUE;
  14258. }
  14259. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14260. {
  14261. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14263. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14264. {
  14265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14266. }
  14267. else
  14268. {
  14269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14270. }
  14271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14272. isKnowKey = TRUE;
  14273. }
  14274. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14275. {
  14276. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14278. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14279. {
  14280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14281. }
  14282. else
  14283. {
  14284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14285. }
  14286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14287. isKnowKey = TRUE;
  14288. }
  14289. //=========================================================
  14290. if(!isEmpty && !isKnowKey)
  14291. {
  14292. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14293. strcpy(unknownkey[UnknownKeynum], keyReq);
  14294. UnknownKeynum = UnknownKeynum + 1;
  14295. }
  14296. }
  14297. void processUnkownKey(void)
  14298. {
  14299. DEBUG_INFO("processUnkownKey...\n");
  14300. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14301. for(int index=0; index < UnknownKeynum; index++)
  14302. {
  14303. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14304. {
  14305. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14306. }
  14307. }
  14308. }
  14309. int setKeyValue(char *key, char *value)
  14310. {
  14311. int isSuccess = NotSupported;
  14312. int check_ascii=0;
  14313. char str[256]={0};
  14314. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14315. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14316. {
  14317. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14319. {
  14320. strcpy(str, (const char*)value);
  14321. for(int i = 0; str[i]; i++){
  14322. str[i] = tolower(str[i]);
  14323. }
  14324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14325. isSuccess = ConfigurationStatus_Accepted;
  14326. }
  14327. else
  14328. {
  14329. isSuccess = ConfigurationStatus_Rejected;
  14330. }
  14331. }
  14332. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14333. {
  14334. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14336. {
  14337. strcpy(str, (const char*)value);
  14338. for(int i = 0; str[i]; i++){
  14339. str[i] = tolower(str[i]);
  14340. }
  14341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14342. isSuccess = ConfigurationStatus_Accepted;
  14343. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14344. }
  14345. else
  14346. {
  14347. isSuccess = ConfigurationStatus_Rejected;
  14348. }
  14349. }
  14350. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14351. {
  14352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14353. {
  14354. strcpy(str, (const char*)value);
  14355. for(int i = 0; str[i]; i++)
  14356. {
  14357. str[i] = tolower(str[i]);
  14358. }
  14359. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14361. isSuccess = ConfigurationStatus_Accepted;
  14362. }
  14363. else
  14364. {
  14365. isSuccess = ConfigurationStatus_Rejected;
  14366. }
  14367. }
  14368. if(strcmp(key, "BlinkRepeat") == 0)
  14369. {
  14370. //Charger.BlinkRepeat = Integer.parseInt(value);
  14371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14372. {
  14373. check_ascii = value[0];
  14374. if( (check_ascii < 48) || (check_ascii > 57) )
  14375. {
  14376. isSuccess = ConfigurationStatus_Rejected;
  14377. }
  14378. else
  14379. {
  14380. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14381. isSuccess = ConfigurationStatus_Accepted;
  14382. }
  14383. }
  14384. else
  14385. {
  14386. isSuccess = ConfigurationStatus_Rejected;
  14387. }
  14388. }
  14389. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14390. {
  14391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14392. {
  14393. check_ascii = value[0];
  14394. if( (check_ascii < 48) || (check_ascii > 57) )
  14395. {
  14396. isSuccess = ConfigurationStatus_Rejected;
  14397. }
  14398. else
  14399. {
  14400. if((atoi(value) == 0) || (atoi(value) >= 10))
  14401. {
  14402. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14404. isSuccess = ConfigurationStatus_Accepted;
  14405. }
  14406. else
  14407. isSuccess = ConfigurationStatus_Rejected;
  14408. }
  14409. }
  14410. else
  14411. {
  14412. isSuccess = ConfigurationStatus_Rejected;
  14413. }
  14414. }
  14415. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14416. {
  14417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14418. {
  14419. check_ascii = value[0];
  14420. if( (check_ascii < 48) || (check_ascii > 57) )
  14421. {
  14422. isSuccess = ConfigurationStatus_Rejected;
  14423. }
  14424. else
  14425. {
  14426. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14428. isSuccess = ConfigurationStatus_Accepted;
  14429. }
  14430. }
  14431. else
  14432. {
  14433. isSuccess = ConfigurationStatus_Rejected;
  14434. }
  14435. }
  14436. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14437. {
  14438. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14439. {
  14440. check_ascii = value[0];
  14441. if( (check_ascii < 48) || (check_ascii > 57) )
  14442. {
  14443. isSuccess = ConfigurationStatus_Rejected;
  14444. }
  14445. else
  14446. {
  14447. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14449. isSuccess = ConfigurationStatus_Accepted;
  14450. }
  14451. }
  14452. else
  14453. {
  14454. isSuccess = ConfigurationStatus_Rejected;
  14455. }
  14456. }
  14457. if(strcmp(key, "HeartbeatInterval") == 0)
  14458. {
  14459. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14460. {
  14461. check_ascii = value[0];
  14462. if( (check_ascii < 48) || (check_ascii > 57) )
  14463. {
  14464. isSuccess = ConfigurationStatus_Rejected;
  14465. }
  14466. else
  14467. {
  14468. if((atoi(value) == 0) || (atoi(value) >= 10))
  14469. {
  14470. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14472. HeartBeatWaitTime = atoi(value);
  14473. isSuccess = ConfigurationStatus_Accepted;
  14474. }
  14475. else
  14476. {
  14477. isSuccess = ConfigurationStatus_Rejected;
  14478. }
  14479. }
  14480. }
  14481. else
  14482. {
  14483. isSuccess = ConfigurationStatus_Rejected;
  14484. }
  14485. }
  14486. if(strcmp(key, "LightIntensity") == 0)
  14487. {
  14488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14489. {
  14490. check_ascii = value[0];
  14491. if( (check_ascii < 48) || (check_ascii > 57) )
  14492. {
  14493. isSuccess = ConfigurationStatus_Rejected;
  14494. }
  14495. else
  14496. {
  14497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14498. isSuccess = ConfigurationStatus_Accepted;
  14499. }
  14500. }
  14501. else
  14502. {
  14503. isSuccess = ConfigurationStatus_Rejected;
  14504. }
  14505. }
  14506. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14507. {
  14508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14509. {
  14510. strcpy(str, (const char*)value);
  14511. for(int i = 0; str[i]; i++)
  14512. {
  14513. str[i] = tolower(str[i]);
  14514. }
  14515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14516. isSuccess = ConfigurationStatus_Accepted;
  14517. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14518. }
  14519. else
  14520. {
  14521. isSuccess = ConfigurationStatus_Rejected;
  14522. }
  14523. }
  14524. if(strcmp(key, "LocalPreAuthorize") == 0)
  14525. {
  14526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14527. {
  14528. strcpy(str, (const char*)value);
  14529. for(int i = 0; str[i]; i++)
  14530. {
  14531. str[i] = tolower(str[i]);
  14532. }
  14533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14534. isSuccess = ConfigurationStatus_Accepted;
  14535. }
  14536. else
  14537. {
  14538. isSuccess = ConfigurationStatus_Rejected;
  14539. }
  14540. }
  14541. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14542. {
  14543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14544. {
  14545. check_ascii = value[0];
  14546. if( (check_ascii < 48) || (check_ascii > 57) )
  14547. {
  14548. isSuccess = ConfigurationStatus_Rejected;
  14549. }
  14550. else
  14551. {
  14552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14553. isSuccess = ConfigurationStatus_Accepted;
  14554. }
  14555. }
  14556. else
  14557. {
  14558. isSuccess = ConfigurationStatus_Rejected;
  14559. }
  14560. }
  14561. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14562. {
  14563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14564. {
  14565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14566. isSuccess = ConfigurationStatus_Accepted;
  14567. }
  14568. else
  14569. {
  14570. isSuccess = ConfigurationStatus_Rejected;
  14571. }
  14572. }
  14573. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14574. {
  14575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14576. {
  14577. check_ascii = value[0];
  14578. if( (check_ascii < 48) || (check_ascii > 57) )
  14579. {
  14580. isSuccess = ConfigurationStatus_Rejected;
  14581. }
  14582. else
  14583. {
  14584. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14586. isSuccess = ConfigurationStatus_Accepted;
  14587. }
  14588. }
  14589. else
  14590. {
  14591. isSuccess = ConfigurationStatus_Rejected;
  14592. }
  14593. }
  14594. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14595. {
  14596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14597. {
  14598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14599. isSuccess = ConfigurationStatus_Accepted;
  14600. }
  14601. else
  14602. {
  14603. isSuccess = ConfigurationStatus_Rejected;
  14604. }
  14605. }
  14606. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14607. {
  14608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14609. {
  14610. check_ascii = value[0];
  14611. if( (check_ascii < 48) || (check_ascii > 57) )
  14612. {
  14613. isSuccess = ConfigurationStatus_Rejected;
  14614. }
  14615. else
  14616. {
  14617. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14619. isSuccess = ConfigurationStatus_Accepted;
  14620. }
  14621. }
  14622. else
  14623. {
  14624. isSuccess = ConfigurationStatus_Rejected;
  14625. }
  14626. }
  14627. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14628. {
  14629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14630. {
  14631. check_ascii = value[0];
  14632. if( (check_ascii < 48) || (check_ascii > 57) )
  14633. {
  14634. isSuccess = ConfigurationStatus_Rejected;
  14635. }
  14636. else
  14637. {
  14638. if((atoi(value) == 0) || (atoi(value) >= 10))
  14639. {
  14640. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14642. isSuccess = ConfigurationStatus_Accepted;
  14643. }
  14644. else
  14645. {
  14646. isSuccess = ConfigurationStatus_Rejected;
  14647. }
  14648. }
  14649. }
  14650. else
  14651. {
  14652. isSuccess = ConfigurationStatus_Rejected;
  14653. }
  14654. }
  14655. if(strcmp(key, "MinimumStatusDuration") == 0)
  14656. {
  14657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14658. {
  14659. check_ascii = value[0];
  14660. if( (check_ascii < 48) || (check_ascii > 57) )
  14661. {
  14662. isSuccess = ConfigurationStatus_Rejected;
  14663. }
  14664. else
  14665. {
  14666. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14667. {
  14668. isSuccess = ConfigurationStatus_Rejected;
  14669. }
  14670. else
  14671. {
  14672. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14674. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14675. isSuccess = ConfigurationStatus_Accepted;
  14676. }
  14677. }
  14678. }
  14679. else
  14680. {
  14681. isSuccess = ConfigurationStatus_Rejected;
  14682. }
  14683. }
  14684. if(strcmp(key, "NumberOfConnectors") == 0)
  14685. {
  14686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14687. {
  14688. check_ascii = value[0];
  14689. if( (check_ascii < 48) || (check_ascii > 57) )
  14690. {
  14691. isSuccess = ConfigurationStatus_Rejected;
  14692. }
  14693. else
  14694. {
  14695. //Charger.ResetRetries = Integer.parseInt(value);
  14696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14697. isSuccess = ConfigurationStatus_Accepted;
  14698. }
  14699. }
  14700. else
  14701. {
  14702. isSuccess = ConfigurationStatus_Rejected;
  14703. }
  14704. }
  14705. if(strcmp(key, "ResetRetries") == 0)
  14706. {
  14707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14708. {
  14709. check_ascii = value[0];
  14710. if( (check_ascii < 48) || (check_ascii > 57) )
  14711. {
  14712. isSuccess = ConfigurationStatus_Rejected;
  14713. }
  14714. else
  14715. {
  14716. //Charger.ResetRetries = Integer.parseInt(value);
  14717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14718. isSuccess = ConfigurationStatus_Accepted;
  14719. }
  14720. }
  14721. else
  14722. {
  14723. isSuccess = ConfigurationStatus_Rejected;
  14724. }
  14725. }
  14726. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14727. {
  14728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14729. {
  14730. strcpy(str, (const char*)value);
  14731. for(int i = 0; str[i]; i++)
  14732. {
  14733. str[i] = tolower(str[i]);
  14734. }
  14735. if(strcmp(str, "notapplicable")== 0)
  14736. {
  14737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14738. isSuccess = ConfigurationStatus_Accepted;
  14739. }
  14740. else if(strcmp(str, "unknown")== 0)
  14741. {
  14742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14743. isSuccess = ConfigurationStatus_Accepted;
  14744. }
  14745. else if(strcmp(str, "rst")== 0)
  14746. {
  14747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14748. isSuccess = ConfigurationStatus_Accepted;
  14749. }
  14750. else if(strcmp(str, "rts")== 0)
  14751. {
  14752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14753. isSuccess = ConfigurationStatus_Accepted;
  14754. }
  14755. else if(strcmp(str, "srt")== 0)
  14756. {
  14757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14758. isSuccess = ConfigurationStatus_Accepted;
  14759. }
  14760. else if(strcmp(str, "str")== 0)
  14761. {
  14762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14763. isSuccess = ConfigurationStatus_Accepted;
  14764. }
  14765. else if(strcmp(str, "trs")== 0)
  14766. {
  14767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14768. isSuccess = ConfigurationStatus_Accepted;
  14769. }
  14770. else if(strcmp(str, "tsr")== 0)
  14771. {
  14772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14773. isSuccess = ConfigurationStatus_Accepted;
  14774. }
  14775. else
  14776. {
  14777. isSuccess = ConfigurationStatus_Rejected;
  14778. }
  14779. }
  14780. else
  14781. {
  14782. isSuccess = ConfigurationStatus_Rejected;
  14783. }
  14784. }
  14785. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14786. {
  14787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14788. {
  14789. check_ascii = value[0];
  14790. if( (check_ascii < 48) || (check_ascii > 57) )
  14791. {
  14792. isSuccess = ConfigurationStatus_Rejected;
  14793. }
  14794. else
  14795. {
  14796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14797. isSuccess = ConfigurationStatus_Accepted;
  14798. }
  14799. }
  14800. else
  14801. {
  14802. isSuccess = ConfigurationStatus_Rejected;
  14803. }
  14804. }
  14805. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14806. {
  14807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14808. {
  14809. strcpy(str, (const char*)value);
  14810. for(int i = 0; str[i]; i++)
  14811. {
  14812. str[i] = tolower(str[i]);
  14813. }
  14814. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14816. isSuccess = ConfigurationStatus_Accepted;
  14817. }
  14818. else
  14819. {
  14820. isSuccess = ConfigurationStatus_Rejected;
  14821. }
  14822. }
  14823. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14824. {
  14825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14826. {
  14827. strcpy(str, (const char*)value);
  14828. for(int i = 0; str[i]; i++)
  14829. {
  14830. str[i] = tolower(str[i]);
  14831. }
  14832. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14834. isSuccess = ConfigurationStatus_Accepted;
  14835. }
  14836. else
  14837. {
  14838. isSuccess = ConfigurationStatus_Rejected;
  14839. }
  14840. }
  14841. if(strcmp(key, "StopTxnAlignedData") == 0)
  14842. {
  14843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14844. {
  14845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14846. isSuccess = ConfigurationStatus_Accepted;
  14847. }
  14848. else
  14849. {
  14850. isSuccess = ConfigurationStatus_Rejected;
  14851. }
  14852. }
  14853. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14854. {
  14855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14856. {
  14857. check_ascii = value[0];
  14858. if( (check_ascii < 48) || (check_ascii > 57) )
  14859. {
  14860. isSuccess = ConfigurationStatus_Rejected;
  14861. }
  14862. else
  14863. {
  14864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14865. isSuccess = ConfigurationStatus_Accepted;
  14866. }
  14867. }
  14868. else
  14869. {
  14870. isSuccess = ConfigurationStatus_Rejected;
  14871. }
  14872. }
  14873. if(strcmp(key, "StopTxnSampledData") == 0)
  14874. {
  14875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14876. {
  14877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14878. isSuccess = ConfigurationStatus_Accepted;
  14879. }
  14880. else
  14881. {
  14882. isSuccess = ConfigurationStatus_Rejected;
  14883. }
  14884. }
  14885. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14886. {
  14887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14888. {
  14889. check_ascii = value[0];
  14890. if( (check_ascii < 48) || (check_ascii > 57) )
  14891. {
  14892. isSuccess = ConfigurationStatus_Rejected;
  14893. }
  14894. else
  14895. {
  14896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14897. isSuccess = ConfigurationStatus_Accepted;
  14898. }
  14899. }
  14900. else
  14901. {
  14902. isSuccess = ConfigurationStatus_Rejected;
  14903. }
  14904. }
  14905. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14906. {
  14907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14908. {
  14909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14910. isSuccess = ConfigurationStatus_Accepted;
  14911. }
  14912. else
  14913. {
  14914. isSuccess = ConfigurationStatus_Rejected;
  14915. }
  14916. }
  14917. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14918. {
  14919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14920. {
  14921. check_ascii = value[0];
  14922. if( (check_ascii < 48) || (check_ascii > 57) )
  14923. {
  14924. isSuccess = ConfigurationStatus_Rejected;
  14925. }
  14926. else
  14927. {
  14928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14929. isSuccess = ConfigurationStatus_Accepted;
  14930. }
  14931. }
  14932. else
  14933. {
  14934. isSuccess = ConfigurationStatus_Rejected;
  14935. }
  14936. }
  14937. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14938. {
  14939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14940. {
  14941. check_ascii = value[0];
  14942. if( (check_ascii < 48) || (check_ascii > 57) )
  14943. {
  14944. isSuccess = ConfigurationStatus_Rejected;
  14945. }
  14946. else
  14947. {
  14948. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14950. TransactionMessageAttemptsValue = atoi(value);
  14951. isSuccess = ConfigurationStatus_Accepted;
  14952. }
  14953. }
  14954. else
  14955. {
  14956. isSuccess = ConfigurationStatus_Rejected;
  14957. }
  14958. }
  14959. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14960. {
  14961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14962. {
  14963. check_ascii = value[0];
  14964. if( (check_ascii < 48) || (check_ascii > 57) )
  14965. {
  14966. isSuccess = ConfigurationStatus_Rejected;
  14967. }
  14968. else
  14969. {
  14970. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14972. TransactionMessageRetryIntervalValue = atoi(value);
  14973. isSuccess = ConfigurationStatus_Accepted;
  14974. }
  14975. }
  14976. else
  14977. {
  14978. isSuccess = ConfigurationStatus_Rejected;
  14979. }
  14980. }
  14981. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14982. {
  14983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14984. {
  14985. strcpy(str, (const char*)value);
  14986. for(int i = 0; str[i]; i++)
  14987. {
  14988. str[i] = tolower(str[i]);
  14989. }
  14990. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14992. isSuccess = ConfigurationStatus_Accepted;
  14993. }
  14994. else
  14995. {
  14996. isSuccess = ConfigurationStatus_Rejected;
  14997. }
  14998. }
  14999. if(strcmp(key, "WebSocketPingInterval") == 0)
  15000. {
  15001. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15002. {
  15003. check_ascii = value[0];
  15004. if( (check_ascii < 48) || (check_ascii > 57) )
  15005. {
  15006. isSuccess = ConfigurationStatus_Rejected;
  15007. }
  15008. else
  15009. {
  15010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15011. isSuccess = ConfigurationStatus_Accepted;
  15012. }
  15013. }
  15014. else
  15015. {
  15016. isSuccess = ConfigurationStatus_Rejected;
  15017. }
  15018. }
  15019. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15020. {
  15021. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15022. {
  15023. strcpy(str, (const char*)value);
  15024. for(int i = 0; str[i]; i++)
  15025. {
  15026. str[i] = tolower(str[i]);
  15027. }
  15028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15029. isSuccess = ConfigurationStatus_Accepted;
  15030. }
  15031. else
  15032. {
  15033. isSuccess = ConfigurationStatus_Rejected;
  15034. }
  15035. }
  15036. if(strcmp(key, "AuthorizationKey") == 0)
  15037. {
  15038. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15039. {
  15040. strcpy(str, (const char*)value);
  15041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15042. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15043. isSuccess = ConfigurationStatus_Accepted;
  15044. }
  15045. else
  15046. {
  15047. isSuccess = ConfigurationStatus_Rejected;
  15048. }
  15049. }
  15050. if(strcmp(key, "SecurityProfile") == 0)
  15051. {
  15052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15053. {
  15054. check_ascii = value[0];
  15055. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15056. {
  15057. isSuccess = ConfigurationStatus_Rejected;
  15058. }
  15059. else if(check_ascii == 0x33)
  15060. {
  15061. isSuccess = NotSupported;
  15062. }
  15063. else
  15064. {
  15065. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15066. {
  15067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15068. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15069. isSuccess = ConfigurationStatus_Accepted;
  15070. }
  15071. else
  15072. isSuccess = ConfigurationStatus_Rejected;
  15073. }
  15074. }
  15075. else
  15076. {
  15077. isSuccess = ConfigurationStatus_Rejected;
  15078. }
  15079. }
  15080. if(strcmp(key, "DefaultPrice") == 0)
  15081. {
  15082. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15083. {
  15084. strcpy(str, (const char*)value);
  15085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15086. isSuccess = ConfigurationStatus_Accepted;
  15087. }
  15088. else
  15089. {
  15090. isSuccess = ConfigurationStatus_Rejected;
  15091. }
  15092. }
  15093. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15094. {
  15095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15096. {
  15097. strcpy(str, (const char*)value);
  15098. for(int i = 0; str[i]; i++)
  15099. {
  15100. str[i] = tolower(str[i]);
  15101. }
  15102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15103. isSuccess = ConfigurationStatus_Accepted;
  15104. }
  15105. else
  15106. {
  15107. isSuccess = ConfigurationStatus_Rejected;
  15108. }
  15109. }
  15110. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15111. {
  15112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15113. {
  15114. strcpy(str, (const char*)value);
  15115. for(int i = 0; str[i]; i++)
  15116. {
  15117. str[i] = tolower(str[i]);
  15118. }
  15119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15120. isSuccess = ConfigurationStatus_Accepted;
  15121. }
  15122. else
  15123. {
  15124. isSuccess = ConfigurationStatus_Rejected;
  15125. }
  15126. }
  15127. if(strcmp(key, "TimeOffset") == 0)
  15128. {
  15129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15130. {
  15131. strcpy(str, (const char*)value);
  15132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15133. isSuccess = ConfigurationStatus_Accepted;
  15134. }
  15135. else
  15136. {
  15137. isSuccess = ConfigurationStatus_Rejected;
  15138. }
  15139. }
  15140. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15141. {
  15142. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15143. {
  15144. strcpy(str, (const char*)value);
  15145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15146. isSuccess = ConfigurationStatus_Accepted;
  15147. }
  15148. else
  15149. {
  15150. isSuccess = ConfigurationStatus_Rejected;
  15151. }
  15152. }
  15153. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15154. {
  15155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15156. {
  15157. strcpy(str, (const char*)value);
  15158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15159. isSuccess = ConfigurationStatus_Accepted;
  15160. }
  15161. else
  15162. {
  15163. isSuccess = ConfigurationStatus_Rejected;
  15164. }
  15165. }
  15166. if(strcmp(key, "SystemUptimeSec") == 0)
  15167. {
  15168. isSuccess = NotSupported;
  15169. }
  15170. if(strcmp(key, "FreeVend") == 0)
  15171. {
  15172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15173. {
  15174. strcpy(str, (const char*)value);
  15175. for(int i = 0; str[i]; i++)
  15176. {
  15177. str[i] = tolower(str[i]);
  15178. }
  15179. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15181. isSuccess = ConfigurationStatus_Accepted;
  15182. }
  15183. else
  15184. {
  15185. isSuccess = ConfigurationStatus_Rejected;
  15186. }
  15187. }
  15188. #if 0
  15189. //For OCPP Test Case
  15190. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15191. {
  15192. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15193. {
  15194. strcpy(str, (const char*)value);
  15195. for(int i = 0; str[i]; i++)
  15196. {
  15197. str[i] = tolower(str[i]);
  15198. }
  15199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15200. isSuccess = ConfigurationStatus_Accepted;
  15201. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15202. }
  15203. else
  15204. {
  15205. isSuccess = ConfigurationStatus_Rejected;
  15206. }
  15207. }
  15208. #endif
  15209. #if 1
  15210. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15211. {
  15212. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15213. {
  15214. strcpy(str, (const char*)value);
  15215. for(int i = 0; str[i]; i++)
  15216. {
  15217. str[i] = tolower(str[i]);
  15218. }
  15219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15220. isSuccess = ConfigurationStatus_Accepted;
  15221. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15222. }
  15223. else
  15224. {
  15225. isSuccess = ConfigurationStatus_Rejected;
  15226. }
  15227. }
  15228. #endif
  15229. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15230. {
  15231. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15232. {
  15233. check_ascii = value[0];
  15234. if( (check_ascii < 48) || (check_ascii > 57) )
  15235. {
  15236. isSuccess = ConfigurationStatus_Rejected;
  15237. }
  15238. else
  15239. {
  15240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15241. isSuccess = ConfigurationStatus_Accepted;
  15242. }
  15243. }
  15244. else
  15245. {
  15246. isSuccess = ConfigurationStatus_Rejected;
  15247. }
  15248. }
  15249. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15250. {
  15251. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15252. {
  15253. check_ascii = value[0];
  15254. if( (check_ascii < 48) || (check_ascii > 57) )
  15255. {
  15256. isSuccess = ConfigurationStatus_Rejected;
  15257. }
  15258. else
  15259. {
  15260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15261. isSuccess = ConfigurationStatus_Accepted;
  15262. }
  15263. }
  15264. else
  15265. {
  15266. isSuccess = ConfigurationStatus_Rejected;
  15267. }
  15268. }
  15269. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15270. {
  15271. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15272. {
  15273. strcpy(str, (const char*)value);
  15274. for(int i = 0; str[i]; i++)
  15275. {
  15276. str[i] = tolower(str[i]);
  15277. }
  15278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15279. isSuccess = ConfigurationStatus_Accepted;
  15280. }
  15281. else
  15282. {
  15283. isSuccess = ConfigurationStatus_Rejected;
  15284. }
  15285. }
  15286. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15287. {
  15288. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15289. {
  15290. check_ascii = value[0];
  15291. if( (check_ascii < 48) || (check_ascii > 57) )
  15292. {
  15293. isSuccess = ConfigurationStatus_Rejected;
  15294. }
  15295. else
  15296. {
  15297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15298. isSuccess = ConfigurationStatus_Accepted;
  15299. }
  15300. }
  15301. else
  15302. {
  15303. isSuccess = ConfigurationStatus_Rejected;
  15304. }
  15305. }
  15306. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15307. {
  15308. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15309. {
  15310. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15311. isSuccess = ConfigurationStatus_Accepted;
  15312. }
  15313. else
  15314. {
  15315. isSuccess = ConfigurationStatus_Rejected;
  15316. }
  15317. }
  15318. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15319. {
  15320. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15321. {
  15322. check_ascii = value[0];
  15323. if( (check_ascii < 48) || (check_ascii > 57) )
  15324. {
  15325. isSuccess = ConfigurationStatus_Rejected;
  15326. }
  15327. else
  15328. {
  15329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15330. isSuccess = ConfigurationStatus_Accepted;
  15331. }
  15332. }
  15333. else
  15334. {
  15335. isSuccess = ConfigurationStatus_Rejected;
  15336. }
  15337. }
  15338. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15339. {
  15340. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15341. {
  15342. strcpy(str, (const char*)value);
  15343. for(int i = 0; str[i]; i++)
  15344. {
  15345. str[i] = tolower(str[i]);
  15346. }
  15347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15348. isSuccess = ConfigurationStatus_Accepted;
  15349. }
  15350. else
  15351. {
  15352. isSuccess = ConfigurationStatus_Rejected;
  15353. }
  15354. }
  15355. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15356. {
  15357. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15358. {
  15359. check_ascii = value[0];
  15360. if( (check_ascii < 48) || (check_ascii > 57) )
  15361. {
  15362. isSuccess = ConfigurationStatus_Rejected;
  15363. }
  15364. else
  15365. {
  15366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15367. isSuccess = ConfigurationStatus_Accepted;
  15368. }
  15369. }
  15370. else
  15371. {
  15372. isSuccess = ConfigurationStatus_Rejected;
  15373. }
  15374. }
  15375. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15376. return isSuccess;
  15377. }
  15378. int TransactionMessageAttemptsGet(void)
  15379. {
  15380. return TransactionMessageAttemptsValue;
  15381. }
  15382. int FirstHeartBeatResponse(void)
  15383. {
  15384. return FirstHeartBeat;
  15385. }
  15386. int TransactionMessageRetryIntervalGet(void)
  15387. {
  15388. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15389. }
  15390. int ReadHttpStatus(int sock)
  15391. {
  15392. //char c;
  15393. char buff[1024]="",*ptr=buff+1;
  15394. int bytes_received, status;
  15395. DEBUG_INFO("Begin Response ..\n");
  15396. while((bytes_received = recv(sock, ptr, 1, 0))){
  15397. if(bytes_received==-1){
  15398. perror("ReadHttpStatus");
  15399. exit(1);
  15400. }
  15401. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15402. ptr++;
  15403. }
  15404. *ptr=0;
  15405. ptr=buff+1;
  15406. sscanf(ptr,"%*s %d ", &status);
  15407. DEBUG_INFO("%s\n",ptr);
  15408. DEBUG_INFO("status=%d\n",status);
  15409. DEBUG_INFO("End Response ..\n");
  15410. return (bytes_received>0)?status:0;
  15411. }
  15412. //the only filed that it parsed is 'Content-Length'
  15413. int ParseHeader(int sock)
  15414. {
  15415. //char c;
  15416. char buff[1024]="",*ptr=buff+4;
  15417. int bytes_received;
  15418. DEBUG_INFO("Begin HEADER ..\n");
  15419. while((bytes_received = recv(sock, ptr, 1, 0))){
  15420. if(bytes_received==-1){
  15421. perror("Parse Header");
  15422. exit(1);
  15423. }
  15424. if(
  15425. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15426. (ptr[-1]=='\r') && (*ptr=='\n' )
  15427. ) break;
  15428. ptr++;
  15429. }
  15430. *ptr=0;
  15431. ptr=buff+4;
  15432. //printf("%s",ptr);
  15433. if(bytes_received){
  15434. ptr=strstr(ptr,"Content-Length:");
  15435. if(ptr){
  15436. sscanf(ptr,"%*s %d",&bytes_received);
  15437. }else
  15438. bytes_received=-1; //unknown size
  15439. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15440. }
  15441. DEBUG_INFO("End HEADER ..\n");
  15442. return bytes_received ;
  15443. }
  15444. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15445. {
  15446. int result = TRUE;
  15447. char rmFileCmd[100]={0};
  15448. char FilePath[100]={0};
  15449. char ftpbuf[200];
  15450. int systemresult;
  15451. sprintf(FilePath,"/mnt/%s",filename);
  15452. system("ping 8.8.8.8 &");
  15453. if((access(FilePath,F_OK))!=-1)
  15454. {
  15455. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15456. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15457. system(rmFileCmd);
  15458. }
  15459. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15460. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15461. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15462. systemresult = system(ftpbuf);
  15463. if(systemresult != 0)
  15464. {
  15465. DEBUG_INFO("http DownLoad error!\n");
  15466. result = FALSE;
  15467. }
  15468. system("pkill ping");
  15469. return result;
  15470. }
  15471. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15472. {
  15473. int result = TRUE;
  15474. char rmFileCmd[100]={0};
  15475. char FilePath[100]={0};
  15476. char ftpbuf[200];
  15477. int systemresult;
  15478. sprintf(FilePath,"/mnt/%s",filename);
  15479. system("ping 8.8.8.8 &");
  15480. if((access(FilePath,F_OK))!=-1)
  15481. {
  15482. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15483. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15484. system(rmFileCmd);
  15485. }
  15486. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15487. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15488. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15489. systemresult = system(ftpbuf);
  15490. if(systemresult != 0)
  15491. {
  15492. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15493. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15494. systemresult = system(ftpbuf);
  15495. if(systemresult != 0)
  15496. {
  15497. DEBUG_WARN("wget error!\n");
  15498. result = FALSE;
  15499. }
  15500. }
  15501. system("pkill ping");
  15502. return result;
  15503. }
  15504. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15505. {
  15506. char rmFileCmd[100]={0};
  15507. char FilePath[100]={0};
  15508. char buf[512];
  15509. int systemresult = 0;
  15510. //DEBUG_INFO("filename=%s\n",filename);
  15511. //DEBUG_INFO("url=%s\n",url);
  15512. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15513. if((access(FilePath,F_OK))!=-1)
  15514. {
  15515. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15516. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15517. system(rmFileCmd);
  15518. }
  15519. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15520. if(fp == NULL)
  15521. {
  15522. DEBUG_INFO("log is NULL\n");
  15523. return FALSE;
  15524. }
  15525. else
  15526. {
  15527. fprintf(fp, "%s\n", url);
  15528. fprintf(fp, "%s\n", filename);
  15529. fclose(fp);
  15530. }
  15531. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15532. if(phpFP == NULL)
  15533. {
  15534. DEBUG_INFO("PHP upload fail.\n");
  15535. return FALSE;
  15536. }
  15537. else
  15538. {
  15539. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15540. {
  15541. if(strstr(buf, "result") != NULL)
  15542. {
  15543. sscanf(buf, "result: %d", &systemresult);
  15544. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15545. }
  15546. }
  15547. pclose(phpFP);
  15548. }
  15549. if(systemresult != 1)
  15550. {
  15551. DEBUG_INFO("HTTP upload error!\n");
  15552. return FALSE;
  15553. }
  15554. return TRUE;
  15555. }
  15556. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15557. {
  15558. struct hostent* server;
  15559. char *IPbuffer;
  15560. char ftpbuf[200];
  15561. int systemresult;
  15562. // To retrieve host information
  15563. server = gethostbyname(location);
  15564. // To convert an Internet network
  15565. // address into ASCII string
  15566. IPbuffer = inet_ntoa(*((struct in_addr*)
  15567. server->h_addr_list[0]));
  15568. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15569. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15570. /* format : ftpput -u username -p passwd IP target source*/
  15571. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15572. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15573. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15574. systemresult = system(ftpbuf);
  15575. DEBUG_INFO("systemresult=%d\n",systemresult);
  15576. if(systemresult != 0)
  15577. {
  15578. DEBUG_INFO("ftpput error!\n");
  15579. return FALSE;
  15580. }
  15581. return TRUE;
  15582. }
  15583. int GetOcppServerURL()
  15584. {
  15585. int result = FALSE;
  15586. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15587. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15588. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15589. struct yuarel url;
  15590. char urlStr[512];
  15591. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15592. {
  15593. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15594. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15595. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15596. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15597. if(yuarel_parse(&url, urlStr) != -1)
  15598. {
  15599. sprintf(OcppProtocol, "%s", url.scheme);
  15600. sprintf(OcppHost, "%s", url.host);
  15601. if(url.path == NULL)
  15602. OcppTempPath[0] = '\0';
  15603. else
  15604. {
  15605. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15606. {
  15607. sprintf(OcppTempPath, "%s/", url.path);
  15608. }
  15609. else
  15610. {
  15611. sprintf(OcppTempPath, "%s", url.path);
  15612. }
  15613. }
  15614. if(url.port == 0)
  15615. {
  15616. if(strcmp(OcppProtocol, "wss") == 0)
  15617. OcppPort = 443;
  15618. else
  15619. OcppPort = 80;
  15620. }
  15621. else
  15622. OcppPort = url.port;
  15623. result = TRUE;
  15624. }
  15625. }
  15626. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15627. {
  15628. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15629. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15630. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15631. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15632. if(yuarel_parse(&url, urlStr) != -1)
  15633. {
  15634. sprintf(OcppProtocol, "%s", url.scheme);
  15635. sprintf(OcppHost, "%s", url.host);
  15636. if(url.path == NULL)
  15637. OcppTempPath[0] = '\0';
  15638. else
  15639. sprintf(OcppTempPath, "%s", url.path);
  15640. if(url.port == 0)
  15641. {
  15642. if(strcmp(OcppProtocol, "wss") == 0)
  15643. OcppPort = 443;
  15644. else
  15645. OcppPort = 80;
  15646. }
  15647. else
  15648. OcppPort = url.port;
  15649. result = TRUE;
  15650. }
  15651. }
  15652. else
  15653. {
  15654. strcpy(OcppHost,"");
  15655. }
  15656. return result;
  15657. }
  15658. int GetOcppPath()
  15659. {
  15660. int result = FALSE;
  15661. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15662. {
  15663. if(OcppTempPath == NULL)
  15664. {
  15665. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15666. }
  15667. else
  15668. {
  15669. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15670. }
  15671. result = TRUE;
  15672. goto End;
  15673. }
  15674. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15675. {
  15676. if(OcppTempPath == NULL)
  15677. {
  15678. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15679. }
  15680. else
  15681. {
  15682. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15683. }
  15684. result = TRUE;
  15685. goto End;
  15686. }
  15687. else
  15688. {
  15689. strcpy(OcppPath,"");
  15690. }
  15691. End:
  15692. return result;
  15693. }
  15694. int GetOcppPort()
  15695. {
  15696. return OcppPort;
  15697. }
  15698. int GetOcppConnStatus(void)
  15699. {
  15700. return ShmOCPP16Data->OcppConnStatus;
  15701. }
  15702. void SetOcppConnStatus(uint8_t status)
  15703. {
  15704. ShmOCPP16Data->OcppConnStatus = status;
  15705. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15706. }
  15707. int GetHeartBeatWithNOResponse(void)
  15708. {
  15709. return HeartBeatWithNOResponse;
  15710. }
  15711. void SetHeartBeatWithNOResponse(void)
  15712. {
  15713. HeartBeatWithNOResponse = 0;
  15714. }
  15715. void GetStartTransactionIdTag(int gun_index)
  15716. {
  15717. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15718. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15719. }
  15720. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15721. {
  15722. char ch;
  15723. FILE *fptr1;
  15724. int temptransactionId;
  15725. char str[100]={0};
  15726. temptransactionId = 0;
  15727. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15728. {
  15729. DEBUG_INFO("IdTag is empty.\n");
  15730. return temptransactionId;
  15731. }
  15732. /*------ Read the file ----------------*/
  15733. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15734. if (!fptr1)
  15735. {
  15736. DEBUG_INFO("QueueTransactionId file open error.\n");
  15737. //printf(" File not found or unable to open the input file!!\n");
  15738. return temptransactionId;
  15739. }
  15740. ch=fgetc(fptr1);
  15741. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15742. rewind(fptr1);
  15743. if(ch!=EOF)
  15744. {
  15745. // printf("%c",ch);
  15746. while (fgets(str, 100, fptr1) != NULL)
  15747. {
  15748. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15749. if(str[0]=='\0')
  15750. {
  15751. break;
  15752. }
  15753. char *revbuf[8] = {0}; // Variable store string split
  15754. int num = 0;// Quantity after string split
  15755. DEBUG_INFO("Transaction queue data= %s\n", str);
  15756. splitstring(str,",",revbuf,&num); // String split
  15757. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15758. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15759. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15760. DEBUG_INFO("------------------------------\n");
  15761. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15762. {
  15763. if(isStopTransaction)
  15764. {
  15765. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15766. {
  15767. temptransactionId = atoi(revbuf[2]);
  15768. //break;
  15769. }
  15770. }
  15771. else
  15772. {
  15773. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15774. {
  15775. temptransactionId = atoi(revbuf[2]);
  15776. //break;
  15777. }
  15778. }
  15779. }
  15780. }
  15781. }
  15782. else
  15783. DEBUG_INFO("EOF\n");
  15784. fclose(fptr1);
  15785. /*------- End of reading ---------------*/
  15786. return temptransactionId;
  15787. }
  15788. void SetTransactionIdZero(int transactionId)
  15789. {
  15790. char ch;
  15791. FILE *fptr1, *fptr2;
  15792. int temptransactionId = 0;
  15793. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15794. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15795. if (!fptr1)
  15796. {
  15797. //printf(" File not found or unable to open the input file!!\n");
  15798. return ;
  15799. }
  15800. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15801. if (!fptr2)
  15802. {
  15803. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15804. fclose(fptr1);
  15805. return ;
  15806. }
  15807. ch=fgetc(fptr1);
  15808. rewind(fptr1);
  15809. if(ch!=EOF)
  15810. {
  15811. // copy all contents to the temporary file except the specific line
  15812. while (fgets(str, 100, fptr1) != NULL)
  15813. {
  15814. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15815. if(str[0]=='\0')
  15816. {
  15817. break;
  15818. }
  15819. char *revbuf[8] = {0};
  15820. int num = 0;
  15821. strcpy(strtemp, str);
  15822. splitstring(str,",",revbuf,&num);
  15823. if(revbuf[2][0] != '\0')
  15824. {
  15825. temptransactionId = atoi(revbuf[2]);
  15826. if(transactionId != temptransactionId)
  15827. {
  15828. fprintf(fptr2, "%s\n", strtemp);
  15829. }
  15830. }
  15831. }
  15832. }
  15833. fclose(fptr1);
  15834. fclose(fptr2);
  15835. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15836. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15837. /*------ Read the file ----------------*/
  15838. }
  15839. int InternetDisconnect(void)
  15840. {
  15841. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15842. }
  15843. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15844. void storeTempStopTransaction(int gun_index)
  15845. {
  15846. char guid[37]={0};
  15847. int tempIndex = 0;
  15848. char TempStopTransaction[256];
  15849. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15850. DEBUG_INFO("storeTempStopTransaction...\n");
  15851. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15852. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15853. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15854. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15855. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15856. {
  15857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15858. {
  15859. tempIndex = ((gun_index==2) ? 1: 0);
  15860. }
  15861. else
  15862. {
  15863. tempIndex = gun_index;
  15864. }
  15865. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15866. {
  15867. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15868. {
  15869. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15870. }
  15871. }// END OF CHAdeMO_QUANTITY
  15872. }
  15873. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15874. {
  15875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15876. {
  15877. tempIndex = ((gun_index==2) ? 1: 0);
  15878. }
  15879. else
  15880. {
  15881. tempIndex = gun_index;
  15882. }
  15883. for (int index = 0; index < CCS_QUANTITY; index++)
  15884. {
  15885. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15886. {
  15887. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15888. }
  15889. }// END OF CCS_QUANTITY
  15890. }
  15891. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15892. {
  15893. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15894. {
  15895. tempIndex = ((gun_index==2) ? 1: 0);
  15896. }
  15897. else
  15898. {
  15899. tempIndex = gun_index;
  15900. }
  15901. for (int index = 0; index < GB_QUANTITY; index++)
  15902. {
  15903. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15904. {
  15905. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15906. }
  15907. }// END OF GB_QUANTITY
  15908. }
  15909. else if(gunType[gun_index] == GUN_TYPE_DO)
  15910. {
  15911. tempIndex = gun_index;
  15912. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15913. {
  15914. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15915. {
  15916. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15917. }
  15918. }
  15919. }
  15920. else
  15921. {
  15922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15923. {
  15924. tempIndex = 2;
  15925. }
  15926. else
  15927. {
  15928. tempIndex = gun_index;
  15929. }
  15930. for (int index = 0; index < AC_QUANTITY; index++)
  15931. {
  15932. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15933. {
  15934. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15935. }
  15936. }// END OF AC_QUANTITY
  15937. }
  15938. //Stop Transaction Time
  15939. struct timeval tmnow;
  15940. struct tm *tm;
  15941. char buf[28];//, usec_buf[6];
  15942. gettimeofday(&tmnow, NULL);
  15943. time_t t;
  15944. t = time(NULL);
  15945. /*UTC time and date*/
  15946. tm = gmtime(&t);
  15947. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15949. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15951. random_uuid(guid);
  15952. /***********************************transactionData******************************************************/
  15953. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15955. //=================================
  15956. //1. Transaction_Begin
  15957. //=================================
  15958. //============================== Energy.Active.Import.Interval ===========================================
  15959. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15960. {
  15961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15964. 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*/]);
  15965. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15966. 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))
  15967. {
  15968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15969. }
  15970. else
  15971. {
  15972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15973. }
  15974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15976. }
  15977. //=================================
  15978. //2. Transaction_End
  15979. //=================================
  15980. //2.1====================================== Current.Import L1 ==============================================
  15981. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15982. {
  15983. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15984. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15985. {
  15986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15987. {
  15988. tempIndex = ((gun_index==2) ? 1: 0);
  15989. }
  15990. else
  15991. {
  15992. tempIndex = gun_index;
  15993. }
  15994. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15995. {
  15996. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15997. {
  15998. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15999. }
  16000. }// End of for CHAdeMO_QUANTITY
  16001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16002. }
  16003. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16004. {
  16005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16006. {
  16007. tempIndex = ((gun_index==2) ? 1: 0);
  16008. }
  16009. else
  16010. {
  16011. tempIndex = gun_index;
  16012. }
  16013. for (int index = 0; index < CCS_QUANTITY; index++)
  16014. {
  16015. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16016. {
  16017. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16018. }
  16019. }// End of for CCS_QUANTITY
  16020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16021. }
  16022. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16023. {
  16024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16025. {
  16026. tempIndex = ((gun_index==2) ? 1: 0);
  16027. }
  16028. else
  16029. {
  16030. tempIndex = gun_index;
  16031. }
  16032. for (int index = 0; index < GB_QUANTITY; index++)
  16033. {
  16034. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16035. {
  16036. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16037. }
  16038. }// End of for GB_QUANTITY
  16039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16040. }
  16041. else if(gunType[gun_index] == GUN_TYPE_DO)
  16042. {
  16043. tempIndex = gun_index;
  16044. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16045. {
  16046. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16047. {
  16048. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16049. }
  16050. }
  16051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16052. }
  16053. else
  16054. {
  16055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16056. {
  16057. tempIndex = 2;
  16058. }
  16059. else
  16060. {
  16061. tempIndex = gun_index;
  16062. }
  16063. for (int index = 0; index < AC_QUANTITY; index++)
  16064. {
  16065. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16066. {
  16067. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16068. }
  16069. }// End of for AC_QUANTITY
  16070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16071. }
  16072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16075. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16078. }
  16079. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16080. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16081. {
  16082. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16083. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16084. {
  16085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16086. {
  16087. tempIndex = ((gun_index==2) ? 1: 0);
  16088. }
  16089. else
  16090. {
  16091. tempIndex = gun_index;
  16092. }
  16093. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16094. {
  16095. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16096. {
  16097. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16098. }
  16099. }// END OF CHAdeMO_QUANTITY
  16100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16101. }
  16102. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16103. {
  16104. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16105. {
  16106. tempIndex = ((gun_index==2) ? 1: 0);
  16107. }
  16108. else
  16109. {
  16110. tempIndex = gun_index;
  16111. }
  16112. for (int index = 0; index < CCS_QUANTITY; index++)
  16113. {
  16114. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16115. {
  16116. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16117. }
  16118. }// END OF CCS_QUANTITY
  16119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16120. }
  16121. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16122. {
  16123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16124. {
  16125. tempIndex = ((gun_index==2) ? 1: 0);
  16126. }
  16127. else
  16128. {
  16129. tempIndex = gun_index;
  16130. }
  16131. for (int index = 0; index < GB_QUANTITY; index++)
  16132. {
  16133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16134. {
  16135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16136. }
  16137. }// END OF GB_QUANTITY
  16138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16139. }
  16140. else if(gunType[gun_index] == GUN_TYPE_DO)
  16141. {
  16142. tempIndex = gun_index;
  16143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16144. {
  16145. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16146. {
  16147. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16148. }
  16149. }
  16150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16151. }
  16152. else
  16153. {
  16154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16155. {
  16156. tempIndex = 2;
  16157. }
  16158. else
  16159. {
  16160. tempIndex = gun_index;
  16161. }
  16162. for (int index = 0; index < AC_QUANTITY; index++)
  16163. {
  16164. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16165. {
  16166. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16167. }
  16168. }// END OF AC_QUANTITY
  16169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16170. }
  16171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16174. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16177. }
  16178. //2.3====================================== Power.Active.Import =========================================
  16179. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16180. {
  16181. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16182. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16183. {
  16184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16185. {
  16186. tempIndex = ((gun_index==2) ? 1: 0);
  16187. }
  16188. else
  16189. {
  16190. tempIndex = gun_index;
  16191. }
  16192. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16193. {
  16194. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16195. {
  16196. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16197. }
  16198. } // End for CHAdeMO_QUANTITY
  16199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16200. }
  16201. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16202. {
  16203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16204. {
  16205. tempIndex = ((gun_index==2) ? 1: 0);
  16206. }
  16207. else
  16208. {
  16209. tempIndex = gun_index;
  16210. }
  16211. for (int index = 0; index < CCS_QUANTITY; index++)
  16212. {
  16213. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16214. {
  16215. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16216. }
  16217. } // END for CCS_QUANTITY
  16218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16219. }
  16220. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16221. {
  16222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16223. {
  16224. tempIndex = ((gun_index==2) ? 1: 0);
  16225. }
  16226. else
  16227. {
  16228. tempIndex = gun_index;
  16229. }
  16230. for (int index = 0; index < GB_QUANTITY; index++)
  16231. {
  16232. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16233. {
  16234. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16235. }
  16236. }// END for GB_QUANTITY
  16237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16238. }
  16239. else if(gunType[gun_index] == GUN_TYPE_DO)
  16240. {
  16241. tempIndex = gun_index;
  16242. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16243. {
  16244. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16245. {
  16246. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16247. }
  16248. }
  16249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16250. }
  16251. else
  16252. {
  16253. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16254. {
  16255. tempIndex = 2;
  16256. }
  16257. else
  16258. {
  16259. tempIndex = gun_index;
  16260. }
  16261. for (int index = 0; index < AC_QUANTITY; index++)
  16262. {
  16263. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16264. {
  16265. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16266. }
  16267. } // END for AC_QUANTITY
  16268. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16269. }
  16270. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16273. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16276. }
  16277. //2.4====================================== Voltage L1 ====================================================
  16278. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16279. {
  16280. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16281. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16282. {
  16283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16284. {
  16285. tempIndex = ((gun_index==2) ? 1: 0);
  16286. }
  16287. else
  16288. {
  16289. tempIndex = gun_index;
  16290. }
  16291. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16292. {
  16293. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16294. {
  16295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16296. }
  16297. } // END OF FOR CHAdeMO_QUANTITY
  16298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16299. }
  16300. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16301. {
  16302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16303. {
  16304. tempIndex = ((gun_index==2) ? 1: 0);
  16305. }
  16306. else
  16307. {
  16308. tempIndex = gun_index;
  16309. }
  16310. for (int index = 0; index < CCS_QUANTITY; index++)
  16311. {
  16312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16313. {
  16314. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16315. }
  16316. } // END OF FOR CCS_QUANTITY
  16317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16318. }
  16319. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16320. {
  16321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16322. {
  16323. tempIndex = ((gun_index==2) ? 1: 0);
  16324. }
  16325. else
  16326. {
  16327. tempIndex = gun_index;
  16328. }
  16329. for (int index = 0; index < GB_QUANTITY; index++)
  16330. {
  16331. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16332. {
  16333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16334. }
  16335. } // END OF FOR GB_QUANTITY
  16336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16337. }
  16338. else if(gunType[gun_index] == GUN_TYPE_DO)
  16339. {
  16340. tempIndex = gun_index;
  16341. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16342. {
  16343. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16344. {
  16345. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16346. }
  16347. }
  16348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16349. }
  16350. else
  16351. {
  16352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16353. {
  16354. tempIndex = 2;
  16355. }
  16356. else
  16357. {
  16358. tempIndex = gun_index;
  16359. }
  16360. for (int index = 0; index < AC_QUANTITY; index++)
  16361. {
  16362. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16363. {
  16364. 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
  16365. }
  16366. } // END OF FOR AC_QUANTITY
  16367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16368. }
  16369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16372. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16375. }
  16376. //2.5============================================== End SoC =========================================================
  16377. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16378. {
  16379. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16380. 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))
  16381. {
  16382. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16383. {
  16384. tempIndex = ((gun_index==2) ? 1: 0);
  16385. }
  16386. else
  16387. {
  16388. tempIndex = gun_index;
  16389. }
  16390. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16391. {
  16392. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16393. {
  16394. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16395. {
  16396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16397. }
  16398. }
  16399. }
  16400. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16401. {
  16402. for (int index = 0; index < CCS_QUANTITY; index++)
  16403. {
  16404. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16405. {
  16406. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16407. }
  16408. }
  16409. }
  16410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16411. {
  16412. for (int index = 0; index < GB_QUANTITY; index++)
  16413. {
  16414. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16415. {
  16416. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16417. }
  16418. }
  16419. }
  16420. else if(gunType[gun_index] == GUN_TYPE_DO)
  16421. {
  16422. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16423. {
  16424. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16425. {
  16426. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16427. }
  16428. }
  16429. }
  16430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16436. } // END FOR DC CASE
  16437. }
  16438. //2.6====================================== Current.Import L2 ==============================================
  16439. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16440. {
  16441. // AC 3 phase L2 current
  16442. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16443. {
  16444. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16445. {
  16446. tempIndex = 2;
  16447. }
  16448. else
  16449. {
  16450. tempIndex = gun_index;
  16451. }
  16452. for (int index = 0; index < AC_QUANTITY; index++)
  16453. {
  16454. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16455. {
  16456. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16457. }
  16458. }// End of for AC_QUANTITY
  16459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16460. }
  16461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16466. }
  16467. //2.7====================================== Current.Import L3 ==============================================
  16468. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16469. {
  16470. // AC 3 phase L3 current
  16471. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16472. {
  16473. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16474. {
  16475. tempIndex = 2;
  16476. }
  16477. else
  16478. {
  16479. tempIndex = gun_index;
  16480. }
  16481. for (int index = 0; index < AC_QUANTITY; index++)
  16482. {
  16483. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16484. {
  16485. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16486. }
  16487. }// End of for AC_QUANTITY
  16488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16489. }
  16490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16495. }
  16496. //2.9====================================== Voltage L2 ====================================================
  16497. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16498. {
  16499. // AC 3 phase L2 volatge
  16500. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16501. {
  16502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16503. {
  16504. tempIndex = 2;
  16505. }
  16506. else
  16507. {
  16508. tempIndex = gun_index;
  16509. }
  16510. for (int index = 0; index < AC_QUANTITY; index++)
  16511. {
  16512. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16513. {
  16514. 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
  16515. }
  16516. } // END OF FOR AC_QUANTITY
  16517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16518. }
  16519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16524. }
  16525. //2.10====================================== Voltage L3 ====================================================
  16526. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16527. {
  16528. // AC 3 phase L3 volatge
  16529. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16530. {
  16531. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16532. {
  16533. tempIndex = 2;
  16534. }
  16535. else
  16536. {
  16537. tempIndex = gun_index;
  16538. }
  16539. for (int index = 0; index < AC_QUANTITY; index++)
  16540. {
  16541. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16542. {
  16543. 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
  16544. }
  16545. } // END OF FOR AC_QUANTITY
  16546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16547. }
  16548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16553. }
  16554. //====================== Start SoC ================================
  16555. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16556. {
  16557. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16558. 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))
  16559. {
  16560. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16561. {
  16562. tempIndex = ((gun_index==2) ? 1: 0);
  16563. }
  16564. else
  16565. {
  16566. tempIndex = gun_index;
  16567. }
  16568. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16569. {
  16570. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16571. {
  16572. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16573. {
  16574. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16575. }
  16576. }
  16577. }
  16578. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16579. {
  16580. for (int index = 0; index < CCS_QUANTITY; index++)
  16581. {
  16582. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16583. {
  16584. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16585. }
  16586. }
  16587. }
  16588. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16589. {
  16590. for (int index = 0; index < GB_QUANTITY; index++)
  16591. {
  16592. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16593. {
  16594. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16595. }
  16596. }
  16597. }
  16598. else if(gunType[gun_index] == GUN_TYPE_DO)
  16599. {
  16600. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16601. {
  16602. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16603. {
  16604. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16605. }
  16606. }
  16607. }
  16608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16614. } // END FOR DC CASE
  16615. }
  16616. //======================================== Message create ==============================================
  16617. json_object *StopTransaction = json_object_new_object();
  16618. json_object *transactionDatas = json_object_new_array();
  16619. json_object *sampledValues = json_object_new_array();
  16620. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16621. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16622. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16623. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16624. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16625. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16626. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16627. {
  16628. json_object *transactionData = json_object_new_object();
  16629. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16630. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16631. {
  16632. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16633. {
  16634. json_object *sampledValue = json_object_new_object();
  16635. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16636. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16637. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16638. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16639. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16640. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16641. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16642. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16643. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16644. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16645. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16646. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16647. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16648. json_object_array_add(sampledValues, sampledValue);
  16649. }
  16650. }
  16651. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16652. json_object_array_add(transactionDatas, transactionData);
  16653. }
  16654. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16655. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16656. ,MESSAGE_TYPE_CALL
  16657. ,guid
  16658. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16659. json_object_put(StopTransaction);
  16660. // Check File "TempStopTransaction" Exist
  16661. if((access(TempStopTransaction,F_OK))!=-1)
  16662. {
  16663. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16664. fclose(fopen(TempStopTransaction, "w"));
  16665. }
  16666. else
  16667. {
  16668. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16669. FILE *log = fopen(TempStopTransaction, "w+");
  16670. if(log == NULL)
  16671. {
  16672. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16673. return ;
  16674. }
  16675. else
  16676. {
  16677. fclose(log);
  16678. }
  16679. }
  16680. //Add TempStopTransaction | Update TempStopTransaction
  16681. // open file for writing
  16682. FILE *outfile;
  16683. outfile = fopen (TempStopTransaction, "a");
  16684. //DEBUG_INFO("data = %s\n", queuedata);
  16685. fputs(queuedata, outfile);
  16686. fputs("\n", outfile);
  16687. fclose (outfile);
  16688. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16689. }
  16690. void checkTempStopTransaction(int gun_index)
  16691. {
  16692. FILE *fptr1;
  16693. char ch;
  16694. char str[QUEUE_MESSAGE_LENGTH]={0};
  16695. char guid[37]={0};
  16696. char tempdata[65]={0};
  16697. char connectorStr[2]={0};
  16698. char TempStopTransaction[256];
  16699. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16700. fptr1 = fopen(TempStopTransaction, "r");
  16701. //TempStopTransaction格式: 槍號,StopTransaction封包
  16702. if (!fptr1)
  16703. {
  16704. //printf(" File not found or unable to open the input file!!\n");
  16705. return ;
  16706. }
  16707. ch=fgetc(fptr1);
  16708. //printf(" Now the content of the file %s is : \n",fname);
  16709. rewind(fptr1);
  16710. if(ch!=EOF)
  16711. {
  16712. // copy all contents to the temporary file except the specific line
  16713. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16714. {
  16715. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16716. if(str[0]=='\0')
  16717. {
  16718. break;
  16719. }
  16720. //TempStopTransaction格式: 槍號,StopTransaction封包
  16721. strncpy(connectorStr, str, 1);
  16722. if(atoi(connectorStr) != (gun_index+1))
  16723. {
  16724. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16725. fclose(fptr1);
  16726. return ;
  16727. }
  16728. //random_uuid(guid);
  16729. strncpy(guid, str+6, 36); //copy guid
  16730. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16731. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16732. {
  16733. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16734. }
  16735. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16736. OCPP_insert_transaction_msg(NO, str);
  16737. memset(str,0,ARRAY_SIZE(str));
  16738. }
  16739. }
  16740. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16741. fclose(fptr1);
  16742. remove(TempStopTransaction); // remove the original file
  16743. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16744. }
  16745. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16746. {
  16747. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16748. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16749. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16750. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16751. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16752. }
  16753. int GetWebSocketPingInterval(void)
  16754. {
  16755. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16756. }
  16757. int GetServerSign(void)
  16758. {
  16759. return server_sign;
  16760. }
  16761. uint8_t GetOcppSecurityProfile()
  16762. {
  16763. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16764. }
  16765. void GetOcppChargerBoxId(uint8_t *data)
  16766. {
  16767. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16768. }
  16769. void GetOcppSecurityPassword(uint8_t *data)
  16770. {
  16771. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16772. }
  16773. void SetOcppVersion(uint8_t *version)
  16774. {
  16775. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16776. DEBUG_INFO("ocpp version: %s\n", version);
  16777. if(strstr((char*)version, "ocpp1.6") != NULL)
  16778. {
  16779. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16780. }
  16781. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16782. {
  16783. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16784. system("pkill OcppBackend");
  16785. }
  16786. }
  16787. void SetServerSign(int value)
  16788. {
  16789. server_sign = value;
  16790. }
  16791. int GetBootNotificationInterval(void)
  16792. {
  16793. return BootNotificationInterval;
  16794. }
  16795. int GetInternetConn(void)
  16796. {
  16797. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16798. }
  16799. int GetBackendConnectionTimeout(void)
  16800. {
  16801. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16802. }
  16803. int isConnectorInitMode(int gun_index)
  16804. {
  16805. int tempIndex = 0;
  16806. int result = TRUE;
  16807. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16808. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16809. {
  16810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16811. {
  16812. tempIndex = ((gun_index==2) ? 1: 0);
  16813. }
  16814. else
  16815. {
  16816. tempIndex = gun_index;
  16817. }
  16818. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16819. {
  16820. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16821. {
  16822. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16823. } //end of the same index
  16824. }//end of for CHAdeMO_QUANTITY
  16825. }
  16826. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16827. {
  16828. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16829. {
  16830. tempIndex = ((gun_index==2) ? 1: 0);
  16831. }
  16832. else
  16833. {
  16834. tempIndex = gun_index;
  16835. }
  16836. for (int index = 0; index < CCS_QUANTITY; index++)
  16837. {
  16838. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16839. {
  16840. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16841. } //end of the same index
  16842. } // end of for CCS_QUANTITY
  16843. }
  16844. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16845. {
  16846. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16847. {
  16848. tempIndex = ((gun_index==2) ? 1: 0);
  16849. }
  16850. else
  16851. {
  16852. tempIndex = gun_index;
  16853. }
  16854. for (int index = 0; index < GB_QUANTITY; index++)
  16855. {
  16856. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16857. {
  16858. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16859. } //end of the same index
  16860. } // end of for GB_QUANTITY
  16861. }
  16862. else if(gunType[gun_index] == GUN_TYPE_DO)
  16863. {
  16864. tempIndex = gun_index;
  16865. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16866. {
  16867. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16868. {
  16869. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16870. } //end of the same index
  16871. }
  16872. }
  16873. else
  16874. {
  16875. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16876. {
  16877. tempIndex = 2;
  16878. }
  16879. else
  16880. {
  16881. tempIndex = gun_index;
  16882. }
  16883. for (int index = 0; index < AC_QUANTITY; index++)
  16884. {
  16885. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16886. {
  16887. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16888. }//end of the same index
  16889. }//end of for AC_QUANTITY
  16890. }
  16891. return result;
  16892. }
  16893. void refreshProcDogTimer()
  16894. {
  16895. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16896. }
  16897. void InitialSystemValue(void)
  16898. {
  16899. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16900. locallistVersion=0;
  16901. BootNotificationInterval = 0;
  16902. authorizeRetryTimes = 0;
  16903. GunStatusInterval = 10;
  16904. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16905. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16906. //Hear Beat
  16907. HeartBeatWithNOResponse = 0;
  16908. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16909. FirstHeartBeat = 0;
  16910. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16911. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16912. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16913. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16914. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16915. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16916. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16917. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16918. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16919. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16920. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16921. //Status && ConnectorPlugIn Setting
  16922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16923. {
  16924. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16925. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16926. }
  16927. for (int index = 0; index < CCS_QUANTITY; index++)
  16928. {
  16929. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16930. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16931. }
  16932. for (int index = 0; index < GB_QUANTITY; index++)
  16933. {
  16934. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16935. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16936. }
  16937. for (int index = 0; index < AC_QUANTITY; index++)
  16938. {
  16939. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16940. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16941. }
  16942. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16943. {
  16944. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16945. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16946. }
  16947. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16948. {
  16949. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16950. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16951. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16952. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16953. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16954. }
  16955. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16956. clientTime.Heartbeat=time((time_t*)NULL);
  16957. sleep(1);
  16958. }
  16959. void LWS_Send(char *str)
  16960. {
  16961. //=====================================================
  16962. // Check InternetConn 0: disconnected, 1: connected
  16963. //====================================================
  16964. if(GetOcppConnStatus() == 0)
  16965. {
  16966. DEBUG_INFO("offline now !!!\n");
  16967. return;
  16968. }
  16969. // Only disable isWebsocketSendable operation initiated by charger
  16970. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16971. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16972. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16973. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16974. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16975. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16976. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16977. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16978. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16979. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16980. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16981. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16982. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16983. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16984. {
  16985. isWebsocketSendable = 0;
  16986. }
  16987. pthread_mutex_lock(&lock_send);
  16988. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16989. sprintf((char *)SendBuffer, "%s", str);
  16990. SendBufLen = strlen(str);
  16991. pthread_mutex_unlock(&lock_send);
  16992. lws_callback_on_writable(wsi_client);
  16993. //lws_service(context, 0);
  16994. //sleep(1);
  16995. }
  16996. void LWS_SendNow(char *str)
  16997. {
  16998. //=====================================================
  16999. // Check InternetConn 0: disconnected, 1: connected
  17000. //====================================================
  17001. if(GetOcppConnStatus() == 0)
  17002. {
  17003. DEBUG_INFO("offline now !!!\n");
  17004. return;
  17005. }
  17006. // Only disable isWebsocketSendable operation initiated by charger
  17007. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17008. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17009. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17010. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17011. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17012. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17013. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17014. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17015. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17016. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17017. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17018. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17019. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17020. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17021. {
  17022. isWebsocketSendable = 0;
  17023. }
  17024. pthread_mutex_lock(&lock_send);
  17025. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17026. sprintf((char *)SendBuffer, "%s", str);
  17027. SendBufLen = strlen(str);
  17028. pthread_mutex_unlock(&lock_send);
  17029. lws_callback_on_writable(wsi_client);
  17030. lws_service(context, 0);
  17031. //sleep(1);
  17032. }