MessageHandler.c 850 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550
  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 = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  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. }
  12272. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12273. {
  12274. mtrace();
  12275. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12276. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12277. }
  12278. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12279. {
  12280. mtrace();
  12281. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12282. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12283. }
  12284. void handleSignCertificateResponse(char *payload, int gun_index)
  12285. {
  12286. mtrace();
  12287. DEBUG_INFO("handleSignCertificateResponse...\n");
  12288. json_object *SignCertificate;
  12289. SignCertificate = json_tokener_parse(payload);
  12290. if(!is_error(SignCertificate))
  12291. {
  12292. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12293. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12294. }
  12295. json_object_put(SignCertificate);
  12296. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12297. }
  12298. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12299. {
  12300. mtrace();
  12301. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12302. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12303. }
  12304. //==========================================
  12305. // Handle Error routine
  12306. //==========================================
  12307. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12308. {
  12309. mtrace();
  12310. #ifdef SystemLogMessage
  12311. DEBUG_INFO("errorCode: %s\n", errorCode);
  12312. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12313. DEBUG_INFO("errorDetails: %s\n", payload);
  12314. #endif
  12315. }
  12316. //===============================================
  12317. // Common routine
  12318. //===============================================
  12319. int initialConfigurationTable(void)
  12320. {
  12321. //clock_t start_t, end_t, total_t;
  12322. FILE *fp;
  12323. FILE *outfile;
  12324. char str[512]={0};
  12325. char sstr[256]={0};
  12326. int c = 0;
  12327. char *loc;
  12328. int confVersion = 10;
  12329. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12330. //start_t = clock();
  12331. //printf("Starting of the program, start_t = %ld\n", start_t);
  12332. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12333. // Check configuration file size is correct
  12334. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12335. {
  12336. struct stat st;
  12337. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12338. if(st.st_size < 3100)
  12339. {
  12340. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12341. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12342. }
  12343. }
  12344. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12345. {
  12346. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12347. if(outfile == NULL)
  12348. {
  12349. DEBUG_INFO("Error opening file\n");
  12350. return FALSE;
  12351. }
  12352. /*Core Profile*/
  12353. //AllowOfflineTxForUnknownId
  12354. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12358. //AuthorizationCacheEnabled
  12359. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12363. //AuthorizeRemoteTxRequests
  12364. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12368. //BlinkRepeat
  12369. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12373. //ClockAlignedDataInterval
  12374. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12378. //ConnectionTimeOut
  12379. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12383. //GetConfigurationMaxKeys
  12384. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12388. // HeartbeatInterval
  12389. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12393. // LightIntensity
  12394. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12398. // LocalAuthorizeOffline
  12399. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12403. // LocalPreAuthorize
  12404. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12408. // MaxEnergyOnInvalidId
  12409. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12413. // MeterValuesAlignedData
  12414. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12417. 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" );
  12418. else
  12419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12421. // MeterValuesAlignedDataMaxLength
  12422. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12426. else
  12427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12429. // MeterValuesSampledData
  12430. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12433. 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" );
  12434. else
  12435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12437. // MeterValuesSampledDataMaxLength
  12438. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12442. else
  12443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12445. // MeterValueSampleInterval
  12446. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12450. // MinimumStatusDuration
  12451. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12454. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12456. // NumberOfConnectors
  12457. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12460. {
  12461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12462. }
  12463. else
  12464. {
  12465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12466. }
  12467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12468. // ResetRetries
  12469. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12473. // ConnectorPhaseRotation
  12474. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12478. // ConnectorPhaseRotationMaxLength
  12479. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12483. // StopTransactionOnEVSideDisconnect
  12484. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12488. // StopTransactionOnInvalidId
  12489. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12493. // StopTxnAlignedData
  12494. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12498. // StopTxnAlignedDataMaxLength
  12499. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12503. // StopTxnSampledData
  12504. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12506. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12508. else
  12509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12511. // StopTxnSampledDataMaxLength
  12512. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12514. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12515. {
  12516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12517. }
  12518. else
  12519. {
  12520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12521. }
  12522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12523. // SupportedFeatureProfiles
  12524. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12528. // SupportedFeatureProfilesMaxLength
  12529. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12533. // TransactionMessageAttempts
  12534. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12537. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12539. // TransactionMessageRetryInterval
  12540. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12543. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12545. // UnlockConnectorOnEVSideDisconnect
  12546. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12550. // WebSocketPingInterval
  12551. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12555. // QueueOffLineMeterValues
  12556. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12560. // AuthorizationKey
  12561. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12565. // SecurityProfile
  12566. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12570. // DefaultPrice
  12571. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12575. // CustomDisplayCostAndPrice
  12576. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12580. // CustomIdleFeeAfterStop
  12581. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12585. // TimeOffset
  12586. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12590. // NextTimeOffsetTransitionDateTime
  12591. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12595. // TimeOffsetNextTransition
  12596. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12600. // SystemUptimeSec
  12601. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  12602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  12603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  12604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  12605. // FreeVend
  12606. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  12607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  12608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  12609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  12610. // Configuration Version
  12611. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12615. //* Local Auth List Management Profile*/
  12616. #if 0
  12617. //For OCTT Test Case
  12618. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12621. #endif
  12622. #if 1
  12623. //LocalAuthListEnabled
  12624. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12628. #endif
  12629. //LocalAuthListMaxLength
  12630. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12634. //SendLocalListMaxLength
  12635. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12639. //ReserveConnectorZeroSupported
  12640. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12644. //* Smart Charging Profile */
  12645. //ChargeProfileMaxStackLevel
  12646. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12650. // ChargingScheduleAllowedChargingRateUnit
  12651. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12655. // ChargingScheduleMaxPeriods
  12656. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12660. // ConnectorSwitch3to1PhaseSupported
  12661. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12665. // MaxChargingProfilesInstalled
  12666. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12670. fclose(outfile);
  12671. }
  12672. else
  12673. {
  12674. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12675. char keystr[60]={0};
  12676. char readonlystr[10]={0};
  12677. char valuestr[256]={0};
  12678. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12679. if(fp == NULL) {
  12680. DEBUG_INFO("Error opening file");
  12681. return FALSE;
  12682. }
  12683. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12684. {
  12685. //DEBUG_INFO("Get Configuration \n");
  12686. if(strlen(str) > 0)
  12687. {
  12688. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12689. //*************************key*********************************/
  12690. if(strstr(str, "key") != NULL)
  12691. {
  12692. loc = strstr(str, "key");
  12693. c = 0;
  12694. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12695. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12696. {
  12697. sstr[c] = loc[strlen("key")+3+c];
  12698. c++;
  12699. }
  12700. sstr[c] = '\0';
  12701. strcpy(keystr,sstr);
  12702. }
  12703. //*************************readonly*********************************/
  12704. if(strstr(str, "readonly") != NULL)
  12705. {
  12706. loc = strstr(str, "readonly");
  12707. c = 0;
  12708. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12709. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12710. {
  12711. sstr[c] = loc[strlen("readonly")+2+c];
  12712. c++;
  12713. }
  12714. sstr[c] = '\0';
  12715. strcpy(readonlystr,sstr);
  12716. }
  12717. //*************************value*********************************/
  12718. if(strstr(str, "value") != NULL)
  12719. {
  12720. loc = strstr(str, "value");
  12721. c = 0;
  12722. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12723. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12724. {
  12725. sstr[c] = loc[strlen("value")+3+c];
  12726. c++;
  12727. }
  12728. sstr[c] = '\0';
  12729. strcpy(valuestr,sstr);
  12730. }
  12731. // DEBUG_INFO("keystr=%s\n",keystr);
  12732. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12733. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12734. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12735. {
  12736. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12737. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12739. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12740. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12741. }
  12742. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12743. {
  12744. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12745. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12747. }
  12748. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12749. {
  12750. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12751. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12752. }
  12753. if(strcmp(keystr, "BlinkRepeat") == 0)
  12754. {
  12755. //Charger.BlinkRepeat = Integer.parseInt(value);
  12756. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12758. }
  12759. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12760. {
  12761. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12763. }
  12764. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12765. {
  12766. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12768. }
  12769. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12770. {
  12771. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12773. }
  12774. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12775. {
  12776. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12778. HeartBeatWaitTime = atoi(valuestr);
  12779. }
  12780. if(strcmp(keystr, "LightIntensity") == 0)
  12781. {
  12782. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12784. }
  12785. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12786. {
  12787. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12789. }
  12790. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12791. {
  12792. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12794. }
  12795. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12796. {
  12797. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12799. }
  12800. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12801. {
  12802. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12804. }
  12805. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12806. {
  12807. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12809. }
  12810. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12811. {
  12812. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12814. }
  12815. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12816. {
  12817. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12819. }
  12820. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12821. {
  12822. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12823. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12824. }
  12825. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12826. {
  12827. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12829. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12830. }
  12831. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12832. {
  12833. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12835. }
  12836. if(strcmp(keystr, "ResetRetries") == 0)
  12837. {
  12838. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12840. }
  12841. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12842. {
  12843. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12845. }
  12846. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12847. {
  12848. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12850. }
  12851. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12852. {
  12853. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12855. }
  12856. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12857. {
  12858. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12860. }
  12861. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12862. {
  12863. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12865. }
  12866. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12867. {
  12868. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12870. }
  12871. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12872. {
  12873. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12875. }
  12876. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12877. {
  12878. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12880. }
  12881. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12882. {
  12883. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12885. }
  12886. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12887. {
  12888. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12890. }
  12891. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12892. {
  12893. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12895. TransactionMessageAttemptsValue = atoi(valuestr);
  12896. }
  12897. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12898. {
  12899. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12901. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12902. }
  12903. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12904. {
  12905. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12907. }
  12908. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12909. {
  12910. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12912. }
  12913. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12914. {
  12915. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12917. }
  12918. if(strcmp(keystr, "AuthorizationKey") == 0)
  12919. {
  12920. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12921. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12923. }
  12924. if(strcmp(keystr, "SecurityProfile") == 0)
  12925. {
  12926. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12928. }
  12929. if(strcmp(keystr, "DefaultPrice") == 0)
  12930. {
  12931. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12933. }
  12934. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12935. {
  12936. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12938. }
  12939. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12940. {
  12941. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12943. }
  12944. if(strcmp(keystr, "TimeOffset") == 0)
  12945. {
  12946. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12948. }
  12949. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12950. {
  12951. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12952. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12953. }
  12954. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12955. {
  12956. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12958. }
  12959. if(strcmp(keystr, "SystemUptimeSec") == 0)
  12960. {
  12961. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12962. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  12963. }
  12964. if(strcmp(keystr, "FreeVend") == 0)
  12965. {
  12966. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  12968. }
  12969. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12970. {
  12971. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12973. }
  12974. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12975. {
  12976. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12978. }
  12979. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12980. {
  12981. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12983. }
  12984. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12985. {
  12986. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12988. }
  12989. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12990. {
  12991. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12993. }
  12994. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12995. {
  12996. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12998. }
  12999. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13000. {
  13001. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13003. }
  13004. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13005. {
  13006. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13008. }
  13009. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13010. {
  13011. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13013. }
  13014. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13015. {
  13016. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13018. }
  13019. }
  13020. }
  13021. fclose(fp);
  13022. }
  13023. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13024. {
  13025. return PASS;
  13026. }
  13027. else
  13028. {
  13029. return FAIL;
  13030. }
  13031. }
  13032. void StoreConfigurationTable(void)
  13033. {
  13034. FILE *outfile;
  13035. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13036. if(outfile == NULL)
  13037. {
  13038. DEBUG_INFO("Error opening file");
  13039. return ;
  13040. }
  13041. /*Core Profile*/
  13042. //AllowOfflineTxForUnknownId
  13043. /*
  13044. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13045. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13048. */
  13049. //DEBUG_INFO("data=%s\n",data);
  13050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13051. //AuthorizationCacheEnabled
  13052. /*
  13053. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13056. */
  13057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13058. //AuthorizeRemoteTxRequests
  13059. /*
  13060. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13063. */
  13064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13065. //BlinkRepeat
  13066. /*
  13067. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13070. */
  13071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13072. //ClockAlignedDataInterval
  13073. /*
  13074. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13077. */
  13078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13079. //ConnectionTimeOut
  13080. /*
  13081. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13084. */
  13085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13086. //GetConfigurationMaxKeys
  13087. /*
  13088. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13091. */
  13092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13093. // HeartbeatInterval
  13094. /*
  13095. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13098. */
  13099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13100. // LightIntensity
  13101. /*
  13102. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13105. */
  13106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13107. // LocalAuthorizeOffline
  13108. /*
  13109. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13112. */
  13113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13114. // LocalPreAuthorize
  13115. /*
  13116. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13119. */
  13120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13121. // MaxEnergyOnInvalidId
  13122. /*
  13123. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13126. */
  13127. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13129. // MeterValuesAlignedData
  13130. /*
  13131. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13134. */
  13135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13136. // MeterValuesAlignedDataMaxLength
  13137. /*
  13138. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13141. */
  13142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13143. // MeterValuesSampledData
  13144. /*
  13145. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13148. */
  13149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13150. // MeterValuesSampledDataMaxLength
  13151. /*
  13152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13155. */
  13156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13157. // MeterValueSampleInterval
  13158. /*
  13159. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13162. */
  13163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13164. // MinimumStatusDuration
  13165. /*
  13166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13169. */
  13170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13171. // NumberOfConnectors
  13172. /*
  13173. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13175. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13176. {
  13177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13178. }
  13179. else
  13180. {
  13181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13182. }
  13183. */
  13184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13185. // ResetRetries
  13186. /*
  13187. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13190. */
  13191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13192. // ConnectorPhaseRotation
  13193. /*
  13194. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13197. */
  13198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13199. // ConnectorPhaseRotationMaxLength
  13200. /*
  13201. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13204. */
  13205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13206. // StopTransactionOnEVSideDisconnect
  13207. /*
  13208. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13211. */
  13212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13213. // StopTransactionOnInvalidId
  13214. /*
  13215. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13218. */
  13219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13220. // StopTxnAlignedData
  13221. /*
  13222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13225. */
  13226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13227. // StopTxnAlignedDataMaxLength
  13228. /*
  13229. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13232. */
  13233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13234. // StopTxnSampledData
  13235. /*
  13236. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13239. */
  13240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13241. // StopTxnSampledDataMaxLength
  13242. /*
  13243. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13246. */
  13247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13248. // SupportedFeatureProfiles
  13249. /*
  13250. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13253. */
  13254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13255. // SupportedFeatureProfilesMaxLength
  13256. /*
  13257. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13260. */
  13261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13262. // TransactionMessageAttempts
  13263. /*
  13264. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13267. */
  13268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13269. // TransactionMessageRetryInterval
  13270. /*
  13271. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13274. */
  13275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13276. // UnlockConnectorOnEVSideDisconnect
  13277. /*
  13278. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13281. */
  13282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13283. // WebSocketPingInterval
  13284. /*
  13285. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13288. */
  13289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13290. // QueueOffLineMeterValues
  13291. /*
  13292. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13295. */
  13296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13297. // AuthorizationKey
  13298. /*
  13299. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13302. */
  13303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13304. // SecurityProfile
  13305. /*
  13306. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13309. */
  13310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13311. // DefaultPrice
  13312. /*
  13313. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13316. */
  13317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13318. // CustomDisplayCostAndPrice
  13319. /*
  13320. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13323. */
  13324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13325. // CustomIdleFeeAfterStop
  13326. /*
  13327. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13330. */
  13331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13332. // TimeOffset
  13333. /*
  13334. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13337. */
  13338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13339. // NextTimeOffsetTransitionDateTime
  13340. /*
  13341. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13344. */
  13345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13346. // TimeOffsetNextTransition
  13347. /*
  13348. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13351. */
  13352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13353. // SystemUptimeSec
  13354. /*
  13355. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13358. */
  13359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13360. // FreeVend
  13361. /*
  13362. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  13365. */
  13366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13367. // ConfigurationVersion
  13368. /*
  13369. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13372. */
  13373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13374. //* Local Auth List Management Profile*/
  13375. //LocalAuthListEnabled
  13376. /*
  13377. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13380. */
  13381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13382. //LocalAuthListMaxLength
  13383. /*
  13384. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13387. */
  13388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13389. //SendLocalListMaxLength
  13390. /*
  13391. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13394. */
  13395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13396. //ReserveConnectorZeroSupported
  13397. /*
  13398. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13401. */
  13402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13403. //* Smart Charging Profile */
  13404. //ChargeProfileMaxStackLevel
  13405. /*
  13406. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13409. */
  13410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13411. // ChargingScheduleAllowedChargingRateUnit
  13412. /*
  13413. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13416. */
  13417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13418. // ChargingScheduleMaxPeriods
  13419. /*
  13420. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13423. */
  13424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13425. // ConnectorSwitch3to1PhaseSupported
  13426. /*
  13427. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13430. */
  13431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13432. // MaxChargingProfilesInstalled
  13433. /*
  13434. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13437. */
  13438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13439. fclose(outfile);
  13440. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13441. }
  13442. void getKeyValue(char *keyReq)
  13443. {
  13444. int isEmpty = FALSE;
  13445. int isKnowKey = FALSE;
  13446. DEBUG_INFO("keyReq = %s\n", keyReq);
  13447. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13448. isEmpty = TRUE;
  13449. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13450. {
  13451. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13453. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13454. {
  13455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13456. }
  13457. else
  13458. {
  13459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13460. }
  13461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13462. isKnowKey = TRUE;
  13463. }
  13464. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13465. {
  13466. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13469. {
  13470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13471. }
  13472. else
  13473. {
  13474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13475. }
  13476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13477. isKnowKey = TRUE;
  13478. }
  13479. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13480. {
  13481. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13484. {
  13485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13486. }
  13487. else
  13488. {
  13489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13490. }
  13491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13492. isKnowKey = TRUE;
  13493. }
  13494. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13495. {
  13496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13498. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13499. {
  13500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13501. }
  13502. else
  13503. {
  13504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13505. }
  13506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13507. isKnowKey = TRUE;
  13508. }
  13509. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13510. {
  13511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13514. {
  13515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13516. }
  13517. else
  13518. {
  13519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13520. }
  13521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13522. isKnowKey = TRUE;
  13523. }
  13524. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13525. {
  13526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13529. {
  13530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13531. }
  13532. else
  13533. {
  13534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13535. }
  13536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13537. isKnowKey = TRUE;
  13538. }
  13539. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13540. {
  13541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13544. {
  13545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13546. }
  13547. else
  13548. {
  13549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13550. }
  13551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13552. isKnowKey = TRUE;
  13553. }
  13554. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13555. {
  13556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13559. {
  13560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13561. }
  13562. else
  13563. {
  13564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13565. }
  13566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13567. isKnowKey = TRUE;
  13568. }
  13569. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13570. {
  13571. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13574. {
  13575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13576. }
  13577. else
  13578. {
  13579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13580. }
  13581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13582. isKnowKey = TRUE;
  13583. }
  13584. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13585. {
  13586. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13589. {
  13590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13591. }
  13592. else
  13593. {
  13594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13595. }
  13596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13597. isKnowKey = TRUE;
  13598. }
  13599. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13600. {
  13601. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13603. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13604. {
  13605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13606. }
  13607. else
  13608. {
  13609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13610. }
  13611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13612. isKnowKey = TRUE;
  13613. }
  13614. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13615. {
  13616. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13619. {
  13620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13621. }
  13622. else
  13623. {
  13624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13625. }
  13626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13627. isKnowKey = TRUE;
  13628. }
  13629. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13630. {
  13631. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13634. {
  13635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13636. }
  13637. else
  13638. {
  13639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13640. }
  13641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13642. isKnowKey = TRUE;
  13643. }
  13644. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13645. {
  13646. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13649. {
  13650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13651. }
  13652. else
  13653. {
  13654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13655. }
  13656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13657. isKnowKey = TRUE;
  13658. }
  13659. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13660. {
  13661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13664. {
  13665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13666. }
  13667. else
  13668. {
  13669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13670. }
  13671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13672. isKnowKey = TRUE;
  13673. }
  13674. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13675. {
  13676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13679. {
  13680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13681. }
  13682. else
  13683. {
  13684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13685. }
  13686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13687. isKnowKey = TRUE;
  13688. }
  13689. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13690. {
  13691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13694. {
  13695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13696. }
  13697. else
  13698. {
  13699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13700. }
  13701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13702. isKnowKey = TRUE;
  13703. }
  13704. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13705. {
  13706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13709. {
  13710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13711. }
  13712. else
  13713. {
  13714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13715. }
  13716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13717. isKnowKey = TRUE;
  13718. }
  13719. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13720. {
  13721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13724. {
  13725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13726. }
  13727. else
  13728. {
  13729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13730. }
  13731. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13733. isKnowKey = TRUE;
  13734. }
  13735. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13736. {
  13737. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13740. {
  13741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13742. }
  13743. else
  13744. {
  13745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13746. }
  13747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13748. isKnowKey = TRUE;
  13749. }
  13750. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13751. {
  13752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13755. {
  13756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13757. }
  13758. else
  13759. {
  13760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13761. }
  13762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13763. isKnowKey = TRUE;
  13764. }
  13765. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13766. {
  13767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13770. {
  13771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13772. }
  13773. else
  13774. {
  13775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13776. }
  13777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13778. isKnowKey = TRUE;
  13779. }
  13780. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13781. {
  13782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13785. {
  13786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13787. }
  13788. else
  13789. {
  13790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13791. }
  13792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13793. isKnowKey = TRUE;
  13794. }
  13795. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13796. {
  13797. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13800. {
  13801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13802. }
  13803. else
  13804. {
  13805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13806. }
  13807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13808. isKnowKey = TRUE;
  13809. }
  13810. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13811. {
  13812. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13815. {
  13816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13817. }
  13818. else
  13819. {
  13820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13821. }
  13822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13823. isKnowKey = TRUE;
  13824. }
  13825. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13826. {
  13827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13830. {
  13831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13832. }
  13833. else
  13834. {
  13835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13836. }
  13837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13838. isKnowKey = TRUE;
  13839. }
  13840. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13841. {
  13842. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13845. {
  13846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13847. }
  13848. else
  13849. {
  13850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13851. }
  13852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13853. isKnowKey = TRUE;
  13854. }
  13855. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13856. {
  13857. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13860. {
  13861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13862. }
  13863. else
  13864. {
  13865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13866. }
  13867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13868. isKnowKey = TRUE;
  13869. }
  13870. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13871. {
  13872. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13875. {
  13876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13877. }
  13878. else
  13879. {
  13880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13881. }
  13882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13883. isKnowKey = TRUE;
  13884. }
  13885. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13886. {
  13887. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13890. {
  13891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13892. }
  13893. else
  13894. {
  13895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13896. }
  13897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13898. isKnowKey = TRUE;
  13899. }
  13900. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13901. {
  13902. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13905. {
  13906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13907. }
  13908. else
  13909. {
  13910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13911. }
  13912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13913. isKnowKey = TRUE;
  13914. }
  13915. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13916. {
  13917. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13920. {
  13921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13922. }
  13923. else
  13924. {
  13925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13926. }
  13927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13928. isKnowKey = TRUE;
  13929. }
  13930. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13931. {
  13932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13935. {
  13936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13937. }
  13938. else
  13939. {
  13940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13941. }
  13942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13943. isKnowKey = TRUE;
  13944. }
  13945. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13946. {
  13947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13950. {
  13951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13952. }
  13953. else
  13954. {
  13955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13956. }
  13957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13958. isKnowKey = TRUE;
  13959. }
  13960. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13961. {
  13962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13965. {
  13966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13967. }
  13968. else
  13969. {
  13970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13971. }
  13972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13973. isKnowKey = TRUE;
  13974. }
  13975. /*
  13976. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13977. {
  13978. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13981. {
  13982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13983. }
  13984. else
  13985. {
  13986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13987. }
  13988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13989. isKnowKey = TRUE;
  13990. }*/
  13991. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13992. {
  13993. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13996. {
  13997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13998. }
  13999. else
  14000. {
  14001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14002. }
  14003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14004. isKnowKey = TRUE;
  14005. }
  14006. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14007. {
  14008. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14011. {
  14012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14013. }
  14014. else
  14015. {
  14016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14017. }
  14018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14019. isKnowKey = TRUE;
  14020. }
  14021. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14022. {
  14023. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14026. {
  14027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14028. }
  14029. else
  14030. {
  14031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14032. }
  14033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14034. isKnowKey = TRUE;
  14035. }
  14036. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14037. {
  14038. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14041. {
  14042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14043. }
  14044. else
  14045. {
  14046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14047. }
  14048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14049. isKnowKey = TRUE;
  14050. }
  14051. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14052. {
  14053. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14056. {
  14057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14058. }
  14059. else
  14060. {
  14061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14062. }
  14063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14064. isKnowKey = TRUE;
  14065. }
  14066. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14067. {
  14068. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14071. {
  14072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14073. }
  14074. else
  14075. {
  14076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14077. }
  14078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14079. isKnowKey = TRUE;
  14080. }
  14081. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14082. {
  14083. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14086. {
  14087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14088. }
  14089. else
  14090. {
  14091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14092. }
  14093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14094. isKnowKey = TRUE;
  14095. }
  14096. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14097. {
  14098. struct sysinfo s_info;
  14099. int error = sysinfo(&s_info);
  14100. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14103. {
  14104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14105. }
  14106. else
  14107. {
  14108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14109. }
  14110. if(error != 0)
  14111. {
  14112. DEBUG_WARN("System uptime get error: %d\n", error);
  14113. }
  14114. else
  14115. {
  14116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14117. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14118. }
  14119. isKnowKey = TRUE;
  14120. }
  14121. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14122. {
  14123. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14126. {
  14127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14128. }
  14129. else
  14130. {
  14131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14132. }
  14133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  14134. isKnowKey = TRUE;
  14135. }
  14136. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14137. {
  14138. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14141. {
  14142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14143. }
  14144. else
  14145. {
  14146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14147. }
  14148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14149. isKnowKey = TRUE;
  14150. }
  14151. #if 1
  14152. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14153. {
  14154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14156. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14157. {
  14158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14159. }
  14160. else
  14161. {
  14162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14163. }
  14164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14165. isKnowKey = TRUE;
  14166. }
  14167. #endif
  14168. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14169. {
  14170. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14172. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14173. {
  14174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14175. }
  14176. else
  14177. {
  14178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14179. }
  14180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14181. isKnowKey = TRUE;
  14182. }
  14183. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14184. {
  14185. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14187. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14188. {
  14189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14190. }
  14191. else
  14192. {
  14193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14194. }
  14195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14196. isKnowKey = TRUE;
  14197. }
  14198. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14199. {
  14200. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14202. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14203. {
  14204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14205. }
  14206. else
  14207. {
  14208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14209. }
  14210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14211. isKnowKey = TRUE;
  14212. }
  14213. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14214. {
  14215. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14217. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14218. {
  14219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14220. }
  14221. else
  14222. {
  14223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14224. }
  14225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14226. isKnowKey = TRUE;
  14227. }
  14228. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14229. {
  14230. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14232. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14233. {
  14234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14235. }
  14236. else
  14237. {
  14238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14239. }
  14240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14241. isKnowKey = TRUE;
  14242. }
  14243. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14244. {
  14245. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14247. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14248. {
  14249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14250. }
  14251. else
  14252. {
  14253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14254. }
  14255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14256. isKnowKey = TRUE;
  14257. }
  14258. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14259. {
  14260. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14262. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14263. {
  14264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14265. }
  14266. else
  14267. {
  14268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14269. }
  14270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14271. isKnowKey = TRUE;
  14272. }
  14273. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14274. {
  14275. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14277. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14278. {
  14279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14280. }
  14281. else
  14282. {
  14283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14284. }
  14285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14286. isKnowKey = TRUE;
  14287. }
  14288. //=========================================================
  14289. if(!isEmpty && !isKnowKey)
  14290. {
  14291. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14292. strcpy(unknownkey[UnknownKeynum], keyReq);
  14293. UnknownKeynum = UnknownKeynum + 1;
  14294. }
  14295. }
  14296. void processUnkownKey(void)
  14297. {
  14298. DEBUG_INFO("processUnkownKey...\n");
  14299. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14300. for(int index=0; index < UnknownKeynum; index++)
  14301. {
  14302. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14303. {
  14304. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14305. }
  14306. }
  14307. }
  14308. int setKeyValue(char *key, char *value)
  14309. {
  14310. int isSuccess = NotSupported;
  14311. int check_ascii=0;
  14312. char str[256]={0};
  14313. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14314. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14315. {
  14316. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14317. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14318. {
  14319. strcpy(str, (const char*)value);
  14320. for(int i = 0; str[i]; i++){
  14321. str[i] = tolower(str[i]);
  14322. }
  14323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14324. isSuccess = ConfigurationStatus_Accepted;
  14325. }
  14326. else
  14327. {
  14328. isSuccess = ConfigurationStatus_Rejected;
  14329. }
  14330. }
  14331. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14332. {
  14333. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14335. {
  14336. strcpy(str, (const char*)value);
  14337. for(int i = 0; str[i]; i++){
  14338. str[i] = tolower(str[i]);
  14339. }
  14340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14341. isSuccess = ConfigurationStatus_Accepted;
  14342. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14343. }
  14344. else
  14345. {
  14346. isSuccess = ConfigurationStatus_Rejected;
  14347. }
  14348. }
  14349. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14350. {
  14351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14352. {
  14353. strcpy(str, (const char*)value);
  14354. for(int i = 0; str[i]; i++)
  14355. {
  14356. str[i] = tolower(str[i]);
  14357. }
  14358. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14360. isSuccess = ConfigurationStatus_Accepted;
  14361. }
  14362. else
  14363. {
  14364. isSuccess = ConfigurationStatus_Rejected;
  14365. }
  14366. }
  14367. if(strcmp(key, "BlinkRepeat") == 0)
  14368. {
  14369. //Charger.BlinkRepeat = Integer.parseInt(value);
  14370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14371. {
  14372. check_ascii = value[0];
  14373. if( (check_ascii < 48) || (check_ascii > 57) )
  14374. {
  14375. isSuccess = ConfigurationStatus_Rejected;
  14376. }
  14377. else
  14378. {
  14379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14380. isSuccess = ConfigurationStatus_Accepted;
  14381. }
  14382. }
  14383. else
  14384. {
  14385. isSuccess = ConfigurationStatus_Rejected;
  14386. }
  14387. }
  14388. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14389. {
  14390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14391. {
  14392. check_ascii = value[0];
  14393. if( (check_ascii < 48) || (check_ascii > 57) )
  14394. {
  14395. isSuccess = ConfigurationStatus_Rejected;
  14396. }
  14397. else
  14398. {
  14399. if((atoi(value) == 0) || (atoi(value) >= 10))
  14400. {
  14401. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14403. isSuccess = ConfigurationStatus_Accepted;
  14404. }
  14405. else
  14406. isSuccess = ConfigurationStatus_Rejected;
  14407. }
  14408. }
  14409. else
  14410. {
  14411. isSuccess = ConfigurationStatus_Rejected;
  14412. }
  14413. }
  14414. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14415. {
  14416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14417. {
  14418. check_ascii = value[0];
  14419. if( (check_ascii < 48) || (check_ascii > 57) )
  14420. {
  14421. isSuccess = ConfigurationStatus_Rejected;
  14422. }
  14423. else
  14424. {
  14425. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14427. isSuccess = ConfigurationStatus_Accepted;
  14428. }
  14429. }
  14430. else
  14431. {
  14432. isSuccess = ConfigurationStatus_Rejected;
  14433. }
  14434. }
  14435. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14436. {
  14437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14438. {
  14439. check_ascii = value[0];
  14440. if( (check_ascii < 48) || (check_ascii > 57) )
  14441. {
  14442. isSuccess = ConfigurationStatus_Rejected;
  14443. }
  14444. else
  14445. {
  14446. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14448. isSuccess = ConfigurationStatus_Accepted;
  14449. }
  14450. }
  14451. else
  14452. {
  14453. isSuccess = ConfigurationStatus_Rejected;
  14454. }
  14455. }
  14456. if(strcmp(key, "HeartbeatInterval") == 0)
  14457. {
  14458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14459. {
  14460. check_ascii = value[0];
  14461. if( (check_ascii < 48) || (check_ascii > 57) )
  14462. {
  14463. isSuccess = ConfigurationStatus_Rejected;
  14464. }
  14465. else
  14466. {
  14467. if((atoi(value) == 0) || (atoi(value) >= 10))
  14468. {
  14469. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14471. HeartBeatWaitTime = atoi(value);
  14472. isSuccess = ConfigurationStatus_Accepted;
  14473. }
  14474. else
  14475. {
  14476. isSuccess = ConfigurationStatus_Rejected;
  14477. }
  14478. }
  14479. }
  14480. else
  14481. {
  14482. isSuccess = ConfigurationStatus_Rejected;
  14483. }
  14484. }
  14485. if(strcmp(key, "LightIntensity") == 0)
  14486. {
  14487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14488. {
  14489. check_ascii = value[0];
  14490. if( (check_ascii < 48) || (check_ascii > 57) )
  14491. {
  14492. isSuccess = ConfigurationStatus_Rejected;
  14493. }
  14494. else
  14495. {
  14496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14497. isSuccess = ConfigurationStatus_Accepted;
  14498. }
  14499. }
  14500. else
  14501. {
  14502. isSuccess = ConfigurationStatus_Rejected;
  14503. }
  14504. }
  14505. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14506. {
  14507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14508. {
  14509. strcpy(str, (const char*)value);
  14510. for(int i = 0; str[i]; i++)
  14511. {
  14512. str[i] = tolower(str[i]);
  14513. }
  14514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14515. isSuccess = ConfigurationStatus_Accepted;
  14516. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14517. }
  14518. else
  14519. {
  14520. isSuccess = ConfigurationStatus_Rejected;
  14521. }
  14522. }
  14523. if(strcmp(key, "LocalPreAuthorize") == 0)
  14524. {
  14525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14526. {
  14527. strcpy(str, (const char*)value);
  14528. for(int i = 0; str[i]; i++)
  14529. {
  14530. str[i] = tolower(str[i]);
  14531. }
  14532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14533. isSuccess = ConfigurationStatus_Accepted;
  14534. }
  14535. else
  14536. {
  14537. isSuccess = ConfigurationStatus_Rejected;
  14538. }
  14539. }
  14540. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14541. {
  14542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14543. {
  14544. check_ascii = value[0];
  14545. if( (check_ascii < 48) || (check_ascii > 57) )
  14546. {
  14547. isSuccess = ConfigurationStatus_Rejected;
  14548. }
  14549. else
  14550. {
  14551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14552. isSuccess = ConfigurationStatus_Accepted;
  14553. }
  14554. }
  14555. else
  14556. {
  14557. isSuccess = ConfigurationStatus_Rejected;
  14558. }
  14559. }
  14560. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14561. {
  14562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14563. {
  14564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14565. isSuccess = ConfigurationStatus_Accepted;
  14566. }
  14567. else
  14568. {
  14569. isSuccess = ConfigurationStatus_Rejected;
  14570. }
  14571. }
  14572. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14573. {
  14574. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14575. {
  14576. check_ascii = value[0];
  14577. if( (check_ascii < 48) || (check_ascii > 57) )
  14578. {
  14579. isSuccess = ConfigurationStatus_Rejected;
  14580. }
  14581. else
  14582. {
  14583. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14585. isSuccess = ConfigurationStatus_Accepted;
  14586. }
  14587. }
  14588. else
  14589. {
  14590. isSuccess = ConfigurationStatus_Rejected;
  14591. }
  14592. }
  14593. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14594. {
  14595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14596. {
  14597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14598. isSuccess = ConfigurationStatus_Accepted;
  14599. }
  14600. else
  14601. {
  14602. isSuccess = ConfigurationStatus_Rejected;
  14603. }
  14604. }
  14605. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14606. {
  14607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14608. {
  14609. check_ascii = value[0];
  14610. if( (check_ascii < 48) || (check_ascii > 57) )
  14611. {
  14612. isSuccess = ConfigurationStatus_Rejected;
  14613. }
  14614. else
  14615. {
  14616. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14618. isSuccess = ConfigurationStatus_Accepted;
  14619. }
  14620. }
  14621. else
  14622. {
  14623. isSuccess = ConfigurationStatus_Rejected;
  14624. }
  14625. }
  14626. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14627. {
  14628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14629. {
  14630. check_ascii = value[0];
  14631. if( (check_ascii < 48) || (check_ascii > 57) )
  14632. {
  14633. isSuccess = ConfigurationStatus_Rejected;
  14634. }
  14635. else
  14636. {
  14637. if((atoi(value) == 0) || (atoi(value) >= 10))
  14638. {
  14639. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14641. isSuccess = ConfigurationStatus_Accepted;
  14642. }
  14643. else
  14644. {
  14645. isSuccess = ConfigurationStatus_Rejected;
  14646. }
  14647. }
  14648. }
  14649. else
  14650. {
  14651. isSuccess = ConfigurationStatus_Rejected;
  14652. }
  14653. }
  14654. if(strcmp(key, "MinimumStatusDuration") == 0)
  14655. {
  14656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14657. {
  14658. check_ascii = value[0];
  14659. if( (check_ascii < 48) || (check_ascii > 57) )
  14660. {
  14661. isSuccess = ConfigurationStatus_Rejected;
  14662. }
  14663. else
  14664. {
  14665. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14666. {
  14667. isSuccess = ConfigurationStatus_Rejected;
  14668. }
  14669. else
  14670. {
  14671. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14673. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14674. isSuccess = ConfigurationStatus_Accepted;
  14675. }
  14676. }
  14677. }
  14678. else
  14679. {
  14680. isSuccess = ConfigurationStatus_Rejected;
  14681. }
  14682. }
  14683. if(strcmp(key, "NumberOfConnectors") == 0)
  14684. {
  14685. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14686. {
  14687. check_ascii = value[0];
  14688. if( (check_ascii < 48) || (check_ascii > 57) )
  14689. {
  14690. isSuccess = ConfigurationStatus_Rejected;
  14691. }
  14692. else
  14693. {
  14694. //Charger.ResetRetries = Integer.parseInt(value);
  14695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14696. isSuccess = ConfigurationStatus_Accepted;
  14697. }
  14698. }
  14699. else
  14700. {
  14701. isSuccess = ConfigurationStatus_Rejected;
  14702. }
  14703. }
  14704. if(strcmp(key, "ResetRetries") == 0)
  14705. {
  14706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14707. {
  14708. check_ascii = value[0];
  14709. if( (check_ascii < 48) || (check_ascii > 57) )
  14710. {
  14711. isSuccess = ConfigurationStatus_Rejected;
  14712. }
  14713. else
  14714. {
  14715. //Charger.ResetRetries = Integer.parseInt(value);
  14716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14717. isSuccess = ConfigurationStatus_Accepted;
  14718. }
  14719. }
  14720. else
  14721. {
  14722. isSuccess = ConfigurationStatus_Rejected;
  14723. }
  14724. }
  14725. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14726. {
  14727. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14728. {
  14729. strcpy(str, (const char*)value);
  14730. for(int i = 0; str[i]; i++)
  14731. {
  14732. str[i] = tolower(str[i]);
  14733. }
  14734. if(strcmp(str, "notapplicable")== 0)
  14735. {
  14736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14737. isSuccess = ConfigurationStatus_Accepted;
  14738. }
  14739. else if(strcmp(str, "unknown")== 0)
  14740. {
  14741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14742. isSuccess = ConfigurationStatus_Accepted;
  14743. }
  14744. else if(strcmp(str, "rst")== 0)
  14745. {
  14746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14747. isSuccess = ConfigurationStatus_Accepted;
  14748. }
  14749. else if(strcmp(str, "rts")== 0)
  14750. {
  14751. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14752. isSuccess = ConfigurationStatus_Accepted;
  14753. }
  14754. else if(strcmp(str, "srt")== 0)
  14755. {
  14756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14757. isSuccess = ConfigurationStatus_Accepted;
  14758. }
  14759. else if(strcmp(str, "str")== 0)
  14760. {
  14761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14762. isSuccess = ConfigurationStatus_Accepted;
  14763. }
  14764. else if(strcmp(str, "trs")== 0)
  14765. {
  14766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14767. isSuccess = ConfigurationStatus_Accepted;
  14768. }
  14769. else if(strcmp(str, "tsr")== 0)
  14770. {
  14771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14772. isSuccess = ConfigurationStatus_Accepted;
  14773. }
  14774. else
  14775. {
  14776. isSuccess = ConfigurationStatus_Rejected;
  14777. }
  14778. }
  14779. else
  14780. {
  14781. isSuccess = ConfigurationStatus_Rejected;
  14782. }
  14783. }
  14784. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14785. {
  14786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14787. {
  14788. check_ascii = value[0];
  14789. if( (check_ascii < 48) || (check_ascii > 57) )
  14790. {
  14791. isSuccess = ConfigurationStatus_Rejected;
  14792. }
  14793. else
  14794. {
  14795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14796. isSuccess = ConfigurationStatus_Accepted;
  14797. }
  14798. }
  14799. else
  14800. {
  14801. isSuccess = ConfigurationStatus_Rejected;
  14802. }
  14803. }
  14804. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14805. {
  14806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14807. {
  14808. strcpy(str, (const char*)value);
  14809. for(int i = 0; str[i]; i++)
  14810. {
  14811. str[i] = tolower(str[i]);
  14812. }
  14813. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14815. isSuccess = ConfigurationStatus_Accepted;
  14816. }
  14817. else
  14818. {
  14819. isSuccess = ConfigurationStatus_Rejected;
  14820. }
  14821. }
  14822. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14823. {
  14824. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14825. {
  14826. strcpy(str, (const char*)value);
  14827. for(int i = 0; str[i]; i++)
  14828. {
  14829. str[i] = tolower(str[i]);
  14830. }
  14831. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14833. isSuccess = ConfigurationStatus_Accepted;
  14834. }
  14835. else
  14836. {
  14837. isSuccess = ConfigurationStatus_Rejected;
  14838. }
  14839. }
  14840. if(strcmp(key, "StopTxnAlignedData") == 0)
  14841. {
  14842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14843. {
  14844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14845. isSuccess = ConfigurationStatus_Accepted;
  14846. }
  14847. else
  14848. {
  14849. isSuccess = ConfigurationStatus_Rejected;
  14850. }
  14851. }
  14852. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14853. {
  14854. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14855. {
  14856. check_ascii = value[0];
  14857. if( (check_ascii < 48) || (check_ascii > 57) )
  14858. {
  14859. isSuccess = ConfigurationStatus_Rejected;
  14860. }
  14861. else
  14862. {
  14863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14864. isSuccess = ConfigurationStatus_Accepted;
  14865. }
  14866. }
  14867. else
  14868. {
  14869. isSuccess = ConfigurationStatus_Rejected;
  14870. }
  14871. }
  14872. if(strcmp(key, "StopTxnSampledData") == 0)
  14873. {
  14874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14875. {
  14876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14877. isSuccess = ConfigurationStatus_Accepted;
  14878. }
  14879. else
  14880. {
  14881. isSuccess = ConfigurationStatus_Rejected;
  14882. }
  14883. }
  14884. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14885. {
  14886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14887. {
  14888. check_ascii = value[0];
  14889. if( (check_ascii < 48) || (check_ascii > 57) )
  14890. {
  14891. isSuccess = ConfigurationStatus_Rejected;
  14892. }
  14893. else
  14894. {
  14895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14896. isSuccess = ConfigurationStatus_Accepted;
  14897. }
  14898. }
  14899. else
  14900. {
  14901. isSuccess = ConfigurationStatus_Rejected;
  14902. }
  14903. }
  14904. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14905. {
  14906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14907. {
  14908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14909. isSuccess = ConfigurationStatus_Accepted;
  14910. }
  14911. else
  14912. {
  14913. isSuccess = ConfigurationStatus_Rejected;
  14914. }
  14915. }
  14916. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14917. {
  14918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14919. {
  14920. check_ascii = value[0];
  14921. if( (check_ascii < 48) || (check_ascii > 57) )
  14922. {
  14923. isSuccess = ConfigurationStatus_Rejected;
  14924. }
  14925. else
  14926. {
  14927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14928. isSuccess = ConfigurationStatus_Accepted;
  14929. }
  14930. }
  14931. else
  14932. {
  14933. isSuccess = ConfigurationStatus_Rejected;
  14934. }
  14935. }
  14936. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14937. {
  14938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14939. {
  14940. check_ascii = value[0];
  14941. if( (check_ascii < 48) || (check_ascii > 57) )
  14942. {
  14943. isSuccess = ConfigurationStatus_Rejected;
  14944. }
  14945. else
  14946. {
  14947. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14949. TransactionMessageAttemptsValue = atoi(value);
  14950. isSuccess = ConfigurationStatus_Accepted;
  14951. }
  14952. }
  14953. else
  14954. {
  14955. isSuccess = ConfigurationStatus_Rejected;
  14956. }
  14957. }
  14958. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14959. {
  14960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14961. {
  14962. check_ascii = value[0];
  14963. if( (check_ascii < 48) || (check_ascii > 57) )
  14964. {
  14965. isSuccess = ConfigurationStatus_Rejected;
  14966. }
  14967. else
  14968. {
  14969. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14971. TransactionMessageRetryIntervalValue = atoi(value);
  14972. isSuccess = ConfigurationStatus_Accepted;
  14973. }
  14974. }
  14975. else
  14976. {
  14977. isSuccess = ConfigurationStatus_Rejected;
  14978. }
  14979. }
  14980. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14981. {
  14982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14983. {
  14984. strcpy(str, (const char*)value);
  14985. for(int i = 0; str[i]; i++)
  14986. {
  14987. str[i] = tolower(str[i]);
  14988. }
  14989. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14991. isSuccess = ConfigurationStatus_Accepted;
  14992. }
  14993. else
  14994. {
  14995. isSuccess = ConfigurationStatus_Rejected;
  14996. }
  14997. }
  14998. if(strcmp(key, "WebSocketPingInterval") == 0)
  14999. {
  15000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15001. {
  15002. check_ascii = value[0];
  15003. if( (check_ascii < 48) || (check_ascii > 57) )
  15004. {
  15005. isSuccess = ConfigurationStatus_Rejected;
  15006. }
  15007. else
  15008. {
  15009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15010. isSuccess = ConfigurationStatus_Accepted;
  15011. }
  15012. }
  15013. else
  15014. {
  15015. isSuccess = ConfigurationStatus_Rejected;
  15016. }
  15017. }
  15018. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15019. {
  15020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15021. {
  15022. strcpy(str, (const char*)value);
  15023. for(int i = 0; str[i]; i++)
  15024. {
  15025. str[i] = tolower(str[i]);
  15026. }
  15027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15028. isSuccess = ConfigurationStatus_Accepted;
  15029. }
  15030. else
  15031. {
  15032. isSuccess = ConfigurationStatus_Rejected;
  15033. }
  15034. }
  15035. if(strcmp(key, "AuthorizationKey") == 0)
  15036. {
  15037. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15038. {
  15039. strcpy(str, (const char*)value);
  15040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15041. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15042. isSuccess = ConfigurationStatus_Accepted;
  15043. }
  15044. else
  15045. {
  15046. isSuccess = ConfigurationStatus_Rejected;
  15047. }
  15048. }
  15049. if(strcmp(key, "SecurityProfile") == 0)
  15050. {
  15051. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15052. {
  15053. check_ascii = value[0];
  15054. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15055. {
  15056. isSuccess = ConfigurationStatus_Rejected;
  15057. }
  15058. else if(check_ascii == 0x33)
  15059. {
  15060. isSuccess = NotSupported;
  15061. }
  15062. else
  15063. {
  15064. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15065. {
  15066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15067. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15068. isSuccess = ConfigurationStatus_Accepted;
  15069. }
  15070. else
  15071. isSuccess = ConfigurationStatus_Rejected;
  15072. }
  15073. }
  15074. else
  15075. {
  15076. isSuccess = ConfigurationStatus_Rejected;
  15077. }
  15078. }
  15079. if(strcmp(key, "DefaultPrice") == 0)
  15080. {
  15081. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15082. {
  15083. strcpy(str, (const char*)value);
  15084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15085. isSuccess = ConfigurationStatus_Accepted;
  15086. }
  15087. else
  15088. {
  15089. isSuccess = ConfigurationStatus_Rejected;
  15090. }
  15091. }
  15092. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15093. {
  15094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15095. {
  15096. strcpy(str, (const char*)value);
  15097. for(int i = 0; str[i]; i++)
  15098. {
  15099. str[i] = tolower(str[i]);
  15100. }
  15101. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15102. isSuccess = ConfigurationStatus_Accepted;
  15103. }
  15104. else
  15105. {
  15106. isSuccess = ConfigurationStatus_Rejected;
  15107. }
  15108. }
  15109. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15110. {
  15111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15112. {
  15113. strcpy(str, (const char*)value);
  15114. for(int i = 0; str[i]; i++)
  15115. {
  15116. str[i] = tolower(str[i]);
  15117. }
  15118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15119. isSuccess = ConfigurationStatus_Accepted;
  15120. }
  15121. else
  15122. {
  15123. isSuccess = ConfigurationStatus_Rejected;
  15124. }
  15125. }
  15126. if(strcmp(key, "TimeOffset") == 0)
  15127. {
  15128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15129. {
  15130. strcpy(str, (const char*)value);
  15131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15132. isSuccess = ConfigurationStatus_Accepted;
  15133. }
  15134. else
  15135. {
  15136. isSuccess = ConfigurationStatus_Rejected;
  15137. }
  15138. }
  15139. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15140. {
  15141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15142. {
  15143. strcpy(str, (const char*)value);
  15144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15145. isSuccess = ConfigurationStatus_Accepted;
  15146. }
  15147. else
  15148. {
  15149. isSuccess = ConfigurationStatus_Rejected;
  15150. }
  15151. }
  15152. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15153. {
  15154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15155. {
  15156. strcpy(str, (const char*)value);
  15157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15158. isSuccess = ConfigurationStatus_Accepted;
  15159. }
  15160. else
  15161. {
  15162. isSuccess = ConfigurationStatus_Rejected;
  15163. }
  15164. }
  15165. if(strcmp(key, "SystemUptimeSec") == 0)
  15166. {
  15167. isSuccess = NotSupported;
  15168. }
  15169. if(strcmp(key, "FreeVend") == 0)
  15170. {
  15171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15172. {
  15173. strcpy(str, (const char*)value);
  15174. for(int i = 0; str[i]; i++)
  15175. {
  15176. str[i] = tolower(str[i]);
  15177. }
  15178. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15180. isSuccess = ConfigurationStatus_Accepted;
  15181. }
  15182. else
  15183. {
  15184. isSuccess = ConfigurationStatus_Rejected;
  15185. }
  15186. }
  15187. #if 0
  15188. //For OCPP Test Case
  15189. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15190. {
  15191. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15192. {
  15193. strcpy(str, (const char*)value);
  15194. for(int i = 0; str[i]; i++)
  15195. {
  15196. str[i] = tolower(str[i]);
  15197. }
  15198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15199. isSuccess = ConfigurationStatus_Accepted;
  15200. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15201. }
  15202. else
  15203. {
  15204. isSuccess = ConfigurationStatus_Rejected;
  15205. }
  15206. }
  15207. #endif
  15208. #if 1
  15209. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15210. {
  15211. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15212. {
  15213. strcpy(str, (const char*)value);
  15214. for(int i = 0; str[i]; i++)
  15215. {
  15216. str[i] = tolower(str[i]);
  15217. }
  15218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15219. isSuccess = ConfigurationStatus_Accepted;
  15220. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15221. }
  15222. else
  15223. {
  15224. isSuccess = ConfigurationStatus_Rejected;
  15225. }
  15226. }
  15227. #endif
  15228. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15229. {
  15230. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15231. {
  15232. check_ascii = value[0];
  15233. if( (check_ascii < 48) || (check_ascii > 57) )
  15234. {
  15235. isSuccess = ConfigurationStatus_Rejected;
  15236. }
  15237. else
  15238. {
  15239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15240. isSuccess = ConfigurationStatus_Accepted;
  15241. }
  15242. }
  15243. else
  15244. {
  15245. isSuccess = ConfigurationStatus_Rejected;
  15246. }
  15247. }
  15248. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15249. {
  15250. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15251. {
  15252. check_ascii = value[0];
  15253. if( (check_ascii < 48) || (check_ascii > 57) )
  15254. {
  15255. isSuccess = ConfigurationStatus_Rejected;
  15256. }
  15257. else
  15258. {
  15259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15260. isSuccess = ConfigurationStatus_Accepted;
  15261. }
  15262. }
  15263. else
  15264. {
  15265. isSuccess = ConfigurationStatus_Rejected;
  15266. }
  15267. }
  15268. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15269. {
  15270. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15271. {
  15272. strcpy(str, (const char*)value);
  15273. for(int i = 0; str[i]; i++)
  15274. {
  15275. str[i] = tolower(str[i]);
  15276. }
  15277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15278. isSuccess = ConfigurationStatus_Accepted;
  15279. }
  15280. else
  15281. {
  15282. isSuccess = ConfigurationStatus_Rejected;
  15283. }
  15284. }
  15285. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15286. {
  15287. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15288. {
  15289. check_ascii = value[0];
  15290. if( (check_ascii < 48) || (check_ascii > 57) )
  15291. {
  15292. isSuccess = ConfigurationStatus_Rejected;
  15293. }
  15294. else
  15295. {
  15296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15297. isSuccess = ConfigurationStatus_Accepted;
  15298. }
  15299. }
  15300. else
  15301. {
  15302. isSuccess = ConfigurationStatus_Rejected;
  15303. }
  15304. }
  15305. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15306. {
  15307. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15308. {
  15309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15310. isSuccess = ConfigurationStatus_Accepted;
  15311. }
  15312. else
  15313. {
  15314. isSuccess = ConfigurationStatus_Rejected;
  15315. }
  15316. }
  15317. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15318. {
  15319. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15320. {
  15321. check_ascii = value[0];
  15322. if( (check_ascii < 48) || (check_ascii > 57) )
  15323. {
  15324. isSuccess = ConfigurationStatus_Rejected;
  15325. }
  15326. else
  15327. {
  15328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15329. isSuccess = ConfigurationStatus_Accepted;
  15330. }
  15331. }
  15332. else
  15333. {
  15334. isSuccess = ConfigurationStatus_Rejected;
  15335. }
  15336. }
  15337. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15338. {
  15339. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15340. {
  15341. strcpy(str, (const char*)value);
  15342. for(int i = 0; str[i]; i++)
  15343. {
  15344. str[i] = tolower(str[i]);
  15345. }
  15346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15347. isSuccess = ConfigurationStatus_Accepted;
  15348. }
  15349. else
  15350. {
  15351. isSuccess = ConfigurationStatus_Rejected;
  15352. }
  15353. }
  15354. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15355. {
  15356. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15357. {
  15358. check_ascii = value[0];
  15359. if( (check_ascii < 48) || (check_ascii > 57) )
  15360. {
  15361. isSuccess = ConfigurationStatus_Rejected;
  15362. }
  15363. else
  15364. {
  15365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15366. isSuccess = ConfigurationStatus_Accepted;
  15367. }
  15368. }
  15369. else
  15370. {
  15371. isSuccess = ConfigurationStatus_Rejected;
  15372. }
  15373. }
  15374. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15375. return isSuccess;
  15376. }
  15377. int TransactionMessageAttemptsGet(void)
  15378. {
  15379. return TransactionMessageAttemptsValue;
  15380. }
  15381. int FirstHeartBeatResponse(void)
  15382. {
  15383. return FirstHeartBeat;
  15384. }
  15385. int TransactionMessageRetryIntervalGet(void)
  15386. {
  15387. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15388. }
  15389. int ReadHttpStatus(int sock)
  15390. {
  15391. //char c;
  15392. char buff[1024]="",*ptr=buff+1;
  15393. int bytes_received, status;
  15394. DEBUG_INFO("Begin Response ..\n");
  15395. while((bytes_received = recv(sock, ptr, 1, 0))){
  15396. if(bytes_received==-1){
  15397. perror("ReadHttpStatus");
  15398. exit(1);
  15399. }
  15400. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15401. ptr++;
  15402. }
  15403. *ptr=0;
  15404. ptr=buff+1;
  15405. sscanf(ptr,"%*s %d ", &status);
  15406. DEBUG_INFO("%s\n",ptr);
  15407. DEBUG_INFO("status=%d\n",status);
  15408. DEBUG_INFO("End Response ..\n");
  15409. return (bytes_received>0)?status:0;
  15410. }
  15411. //the only filed that it parsed is 'Content-Length'
  15412. int ParseHeader(int sock)
  15413. {
  15414. //char c;
  15415. char buff[1024]="",*ptr=buff+4;
  15416. int bytes_received;
  15417. DEBUG_INFO("Begin HEADER ..\n");
  15418. while((bytes_received = recv(sock, ptr, 1, 0))){
  15419. if(bytes_received==-1){
  15420. perror("Parse Header");
  15421. exit(1);
  15422. }
  15423. if(
  15424. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15425. (ptr[-1]=='\r') && (*ptr=='\n' )
  15426. ) break;
  15427. ptr++;
  15428. }
  15429. *ptr=0;
  15430. ptr=buff+4;
  15431. //printf("%s",ptr);
  15432. if(bytes_received){
  15433. ptr=strstr(ptr,"Content-Length:");
  15434. if(ptr){
  15435. sscanf(ptr,"%*s %d",&bytes_received);
  15436. }else
  15437. bytes_received=-1; //unknown size
  15438. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15439. }
  15440. DEBUG_INFO("End HEADER ..\n");
  15441. return bytes_received ;
  15442. }
  15443. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15444. {
  15445. int result = TRUE;
  15446. char rmFileCmd[100]={0};
  15447. char FilePath[100]={0};
  15448. char ftpbuf[200];
  15449. int systemresult;
  15450. sprintf(FilePath,"/mnt/%s",filename);
  15451. system("ping 8.8.8.8 &");
  15452. if((access(FilePath,F_OK))!=-1)
  15453. {
  15454. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15455. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15456. system(rmFileCmd);
  15457. }
  15458. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15459. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15460. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15461. systemresult = system(ftpbuf);
  15462. if(systemresult != 0)
  15463. {
  15464. DEBUG_INFO("http DownLoad error!\n");
  15465. result = FALSE;
  15466. }
  15467. system("pkill ping");
  15468. return result;
  15469. }
  15470. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15471. {
  15472. int result = TRUE;
  15473. char rmFileCmd[100]={0};
  15474. char FilePath[100]={0};
  15475. char ftpbuf[200];
  15476. int systemresult;
  15477. sprintf(FilePath,"/mnt/%s",filename);
  15478. system("ping 8.8.8.8 &");
  15479. if((access(FilePath,F_OK))!=-1)
  15480. {
  15481. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15482. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15483. system(rmFileCmd);
  15484. }
  15485. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15486. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15487. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15488. systemresult = system(ftpbuf);
  15489. if(systemresult != 0)
  15490. {
  15491. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15492. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15493. systemresult = system(ftpbuf);
  15494. if(systemresult != 0)
  15495. {
  15496. DEBUG_WARN("wget error!\n");
  15497. result = FALSE;
  15498. }
  15499. }
  15500. system("pkill ping");
  15501. return result;
  15502. }
  15503. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15504. {
  15505. char rmFileCmd[100]={0};
  15506. char FilePath[100]={0};
  15507. char buf[512];
  15508. int systemresult = 0;
  15509. //DEBUG_INFO("filename=%s\n",filename);
  15510. //DEBUG_INFO("url=%s\n",url);
  15511. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15512. if((access(FilePath,F_OK))!=-1)
  15513. {
  15514. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15515. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15516. system(rmFileCmd);
  15517. }
  15518. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15519. if(fp == NULL)
  15520. {
  15521. DEBUG_INFO("log is NULL\n");
  15522. return FALSE;
  15523. }
  15524. else
  15525. {
  15526. fprintf(fp, "%s\n", url);
  15527. fprintf(fp, "%s\n", filename);
  15528. fclose(fp);
  15529. }
  15530. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15531. if(phpFP == NULL)
  15532. {
  15533. DEBUG_INFO("PHP upload fail.\n");
  15534. return FALSE;
  15535. }
  15536. else
  15537. {
  15538. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15539. {
  15540. if(strstr(buf, "result") != NULL)
  15541. {
  15542. sscanf(buf, "result: %d", &systemresult);
  15543. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15544. }
  15545. }
  15546. pclose(phpFP);
  15547. }
  15548. if(systemresult != 1)
  15549. {
  15550. DEBUG_INFO("HTTP upload error!\n");
  15551. return FALSE;
  15552. }
  15553. return TRUE;
  15554. }
  15555. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15556. {
  15557. struct hostent* server;
  15558. char *IPbuffer;
  15559. char ftpbuf[200];
  15560. int systemresult;
  15561. // To retrieve host information
  15562. server = gethostbyname(location);
  15563. // To convert an Internet network
  15564. // address into ASCII string
  15565. IPbuffer = inet_ntoa(*((struct in_addr*)
  15566. server->h_addr_list[0]));
  15567. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15568. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15569. /* format : ftpput -u username -p passwd IP target source*/
  15570. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15571. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15572. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15573. systemresult = system(ftpbuf);
  15574. DEBUG_INFO("systemresult=%d\n",systemresult);
  15575. if(systemresult != 0)
  15576. {
  15577. DEBUG_INFO("ftpput error!\n");
  15578. return FALSE;
  15579. }
  15580. return TRUE;
  15581. }
  15582. int GetOcppServerURL()
  15583. {
  15584. int result = FALSE;
  15585. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15586. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15587. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15588. struct yuarel url;
  15589. char urlStr[512];
  15590. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15591. {
  15592. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15593. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15594. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15595. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15596. if(yuarel_parse(&url, urlStr) != -1)
  15597. {
  15598. sprintf(OcppProtocol, "%s", url.scheme);
  15599. sprintf(OcppHost, "%s", url.host);
  15600. if(url.path == NULL)
  15601. OcppTempPath[0] = '\0';
  15602. else
  15603. {
  15604. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15605. {
  15606. sprintf(OcppTempPath, "%s/", url.path);
  15607. }
  15608. else
  15609. {
  15610. sprintf(OcppTempPath, "%s", url.path);
  15611. }
  15612. }
  15613. if(url.port == 0)
  15614. {
  15615. if(strcmp(OcppProtocol, "wss") == 0)
  15616. OcppPort = 443;
  15617. else
  15618. OcppPort = 80;
  15619. }
  15620. else
  15621. OcppPort = url.port;
  15622. result = TRUE;
  15623. }
  15624. }
  15625. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15626. {
  15627. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15628. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15629. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15630. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15631. if(yuarel_parse(&url, urlStr) != -1)
  15632. {
  15633. sprintf(OcppProtocol, "%s", url.scheme);
  15634. sprintf(OcppHost, "%s", url.host);
  15635. if(url.path == NULL)
  15636. OcppTempPath[0] = '\0';
  15637. else
  15638. sprintf(OcppTempPath, "%s", url.path);
  15639. if(url.port == 0)
  15640. {
  15641. if(strcmp(OcppProtocol, "wss") == 0)
  15642. OcppPort = 443;
  15643. else
  15644. OcppPort = 80;
  15645. }
  15646. else
  15647. OcppPort = url.port;
  15648. result = TRUE;
  15649. }
  15650. }
  15651. else
  15652. {
  15653. strcpy(OcppHost,"");
  15654. }
  15655. return result;
  15656. }
  15657. int GetOcppPath()
  15658. {
  15659. int result = FALSE;
  15660. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15661. {
  15662. if(OcppTempPath == NULL)
  15663. {
  15664. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15665. }
  15666. else
  15667. {
  15668. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15669. }
  15670. result = TRUE;
  15671. goto End;
  15672. }
  15673. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15674. {
  15675. if(OcppTempPath == NULL)
  15676. {
  15677. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15678. }
  15679. else
  15680. {
  15681. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15682. }
  15683. result = TRUE;
  15684. goto End;
  15685. }
  15686. else
  15687. {
  15688. strcpy(OcppPath,"");
  15689. }
  15690. End:
  15691. return result;
  15692. }
  15693. int GetOcppPort()
  15694. {
  15695. return OcppPort;
  15696. }
  15697. int GetOcppConnStatus(void)
  15698. {
  15699. return ShmOCPP16Data->OcppConnStatus;
  15700. }
  15701. void SetOcppConnStatus(uint8_t status)
  15702. {
  15703. ShmOCPP16Data->OcppConnStatus = status;
  15704. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15705. }
  15706. int GetHeartBeatWithNOResponse(void)
  15707. {
  15708. return HeartBeatWithNOResponse;
  15709. }
  15710. void SetHeartBeatWithNOResponse(void)
  15711. {
  15712. HeartBeatWithNOResponse = 0;
  15713. }
  15714. void GetStartTransactionIdTag(int gun_index)
  15715. {
  15716. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15717. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15718. }
  15719. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15720. {
  15721. char ch;
  15722. FILE *fptr1;
  15723. int temptransactionId;
  15724. char str[100]={0};
  15725. temptransactionId = 0;
  15726. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15727. {
  15728. DEBUG_INFO("IdTag is empty.\n");
  15729. return temptransactionId;
  15730. }
  15731. /*------ Read the file ----------------*/
  15732. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15733. if (!fptr1)
  15734. {
  15735. DEBUG_INFO("QueueTransactionId file open error.\n");
  15736. //printf(" File not found or unable to open the input file!!\n");
  15737. return temptransactionId;
  15738. }
  15739. ch=fgetc(fptr1);
  15740. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15741. rewind(fptr1);
  15742. if(ch!=EOF)
  15743. {
  15744. // printf("%c",ch);
  15745. while (fgets(str, 100, fptr1) != NULL)
  15746. {
  15747. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15748. if(str[0]=='\0')
  15749. {
  15750. break;
  15751. }
  15752. char *revbuf[8] = {0}; // Variable store string split
  15753. int num = 0;// Quantity after string split
  15754. DEBUG_INFO("Transaction queue data= %s\n", str);
  15755. splitstring(str,",",revbuf,&num); // String split
  15756. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15757. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15758. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15759. DEBUG_INFO("------------------------------\n");
  15760. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15761. {
  15762. if(isStopTransaction)
  15763. {
  15764. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15765. {
  15766. temptransactionId = atoi(revbuf[2]);
  15767. //break;
  15768. }
  15769. }
  15770. else
  15771. {
  15772. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15773. {
  15774. temptransactionId = atoi(revbuf[2]);
  15775. //break;
  15776. }
  15777. }
  15778. }
  15779. }
  15780. }
  15781. else
  15782. DEBUG_INFO("EOF\n");
  15783. fclose(fptr1);
  15784. /*------- End of reading ---------------*/
  15785. return temptransactionId;
  15786. }
  15787. void SetTransactionIdZero(int transactionId)
  15788. {
  15789. char ch;
  15790. FILE *fptr1, *fptr2;
  15791. int temptransactionId = 0;
  15792. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15793. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15794. if (!fptr1)
  15795. {
  15796. //printf(" File not found or unable to open the input file!!\n");
  15797. return ;
  15798. }
  15799. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15800. if (!fptr2)
  15801. {
  15802. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15803. fclose(fptr1);
  15804. return ;
  15805. }
  15806. ch=fgetc(fptr1);
  15807. rewind(fptr1);
  15808. if(ch!=EOF)
  15809. {
  15810. // copy all contents to the temporary file except the specific line
  15811. while (fgets(str, 100, fptr1) != NULL)
  15812. {
  15813. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15814. if(str[0]=='\0')
  15815. {
  15816. break;
  15817. }
  15818. char *revbuf[8] = {0};
  15819. int num = 0;
  15820. strcpy(strtemp, str);
  15821. splitstring(str,",",revbuf,&num);
  15822. if(revbuf[2][0] != '\0')
  15823. {
  15824. temptransactionId = atoi(revbuf[2]);
  15825. if(transactionId != temptransactionId)
  15826. {
  15827. fprintf(fptr2, "%s\n", strtemp);
  15828. }
  15829. }
  15830. }
  15831. }
  15832. fclose(fptr1);
  15833. fclose(fptr2);
  15834. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15835. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15836. /*------ Read the file ----------------*/
  15837. }
  15838. int InternetDisconnect(void)
  15839. {
  15840. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15841. }
  15842. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15843. void storeTempStopTransaction(int gun_index)
  15844. {
  15845. char guid[37]={0};
  15846. int tempIndex = 0;
  15847. char TempStopTransaction[256];
  15848. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15849. DEBUG_INFO("storeTempStopTransaction...\n");
  15850. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15851. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15852. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15853. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15854. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15855. {
  15856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15857. {
  15858. tempIndex = ((gun_index==2) ? 1: 0);
  15859. }
  15860. else
  15861. {
  15862. tempIndex = gun_index;
  15863. }
  15864. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15865. {
  15866. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15867. {
  15868. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15869. }
  15870. }// END OF CHAdeMO_QUANTITY
  15871. }
  15872. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15873. {
  15874. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15875. {
  15876. tempIndex = ((gun_index==2) ? 1: 0);
  15877. }
  15878. else
  15879. {
  15880. tempIndex = gun_index;
  15881. }
  15882. for (int index = 0; index < CCS_QUANTITY; index++)
  15883. {
  15884. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15885. {
  15886. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15887. }
  15888. }// END OF CCS_QUANTITY
  15889. }
  15890. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15891. {
  15892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15893. {
  15894. tempIndex = ((gun_index==2) ? 1: 0);
  15895. }
  15896. else
  15897. {
  15898. tempIndex = gun_index;
  15899. }
  15900. for (int index = 0; index < GB_QUANTITY; index++)
  15901. {
  15902. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15903. {
  15904. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15905. }
  15906. }// END OF GB_QUANTITY
  15907. }
  15908. else if(gunType[gun_index] == GUN_TYPE_DO)
  15909. {
  15910. tempIndex = gun_index;
  15911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15912. {
  15913. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15914. {
  15915. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15916. }
  15917. }
  15918. }
  15919. else
  15920. {
  15921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15922. {
  15923. tempIndex = 2;
  15924. }
  15925. else
  15926. {
  15927. tempIndex = gun_index;
  15928. }
  15929. for (int index = 0; index < AC_QUANTITY; index++)
  15930. {
  15931. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15932. {
  15933. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15934. }
  15935. }// END OF AC_QUANTITY
  15936. }
  15937. //Stop Transaction Time
  15938. struct timeval tmnow;
  15939. struct tm *tm;
  15940. char buf[28];//, usec_buf[6];
  15941. gettimeofday(&tmnow, NULL);
  15942. time_t t;
  15943. t = time(NULL);
  15944. /*UTC time and date*/
  15945. tm = gmtime(&t);
  15946. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15948. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15949. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15950. random_uuid(guid);
  15951. /***********************************transactionData******************************************************/
  15952. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15954. //=================================
  15955. //1. Transaction_Begin
  15956. //=================================
  15957. //============================== Energy.Active.Import.Interval ===========================================
  15958. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15959. {
  15960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15963. 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*/]);
  15964. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15965. 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))
  15966. {
  15967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15968. }
  15969. else
  15970. {
  15971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15972. }
  15973. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15975. }
  15976. //=================================
  15977. //2. Transaction_End
  15978. //=================================
  15979. //2.1====================================== Current.Import L1 ==============================================
  15980. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15981. {
  15982. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15983. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15984. {
  15985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15986. {
  15987. tempIndex = ((gun_index==2) ? 1: 0);
  15988. }
  15989. else
  15990. {
  15991. tempIndex = gun_index;
  15992. }
  15993. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15994. {
  15995. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15996. {
  15997. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15998. }
  15999. }// End of for CHAdeMO_QUANTITY
  16000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16001. }
  16002. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16003. {
  16004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16005. {
  16006. tempIndex = ((gun_index==2) ? 1: 0);
  16007. }
  16008. else
  16009. {
  16010. tempIndex = gun_index;
  16011. }
  16012. for (int index = 0; index < CCS_QUANTITY; index++)
  16013. {
  16014. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16015. {
  16016. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16017. }
  16018. }// End of for CCS_QUANTITY
  16019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16020. }
  16021. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16022. {
  16023. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16024. {
  16025. tempIndex = ((gun_index==2) ? 1: 0);
  16026. }
  16027. else
  16028. {
  16029. tempIndex = gun_index;
  16030. }
  16031. for (int index = 0; index < GB_QUANTITY; index++)
  16032. {
  16033. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16034. {
  16035. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16036. }
  16037. }// End of for GB_QUANTITY
  16038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16039. }
  16040. else if(gunType[gun_index] == GUN_TYPE_DO)
  16041. {
  16042. tempIndex = gun_index;
  16043. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16044. {
  16045. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16046. {
  16047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16048. }
  16049. }
  16050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16051. }
  16052. else
  16053. {
  16054. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16055. {
  16056. tempIndex = 2;
  16057. }
  16058. else
  16059. {
  16060. tempIndex = gun_index;
  16061. }
  16062. for (int index = 0; index < AC_QUANTITY; index++)
  16063. {
  16064. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16065. {
  16066. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16067. }
  16068. }// End of for AC_QUANTITY
  16069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16070. }
  16071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16074. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16077. }
  16078. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16079. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16080. {
  16081. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16082. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16083. {
  16084. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16085. {
  16086. tempIndex = ((gun_index==2) ? 1: 0);
  16087. }
  16088. else
  16089. {
  16090. tempIndex = gun_index;
  16091. }
  16092. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16093. {
  16094. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16095. {
  16096. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16097. }
  16098. }// END OF CHAdeMO_QUANTITY
  16099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16100. }
  16101. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16102. {
  16103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16104. {
  16105. tempIndex = ((gun_index==2) ? 1: 0);
  16106. }
  16107. else
  16108. {
  16109. tempIndex = gun_index;
  16110. }
  16111. for (int index = 0; index < CCS_QUANTITY; index++)
  16112. {
  16113. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16114. {
  16115. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16116. }
  16117. }// END OF CCS_QUANTITY
  16118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16119. }
  16120. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16121. {
  16122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16123. {
  16124. tempIndex = ((gun_index==2) ? 1: 0);
  16125. }
  16126. else
  16127. {
  16128. tempIndex = gun_index;
  16129. }
  16130. for (int index = 0; index < GB_QUANTITY; index++)
  16131. {
  16132. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16133. {
  16134. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16135. }
  16136. }// END OF GB_QUANTITY
  16137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16138. }
  16139. else if(gunType[gun_index] == GUN_TYPE_DO)
  16140. {
  16141. tempIndex = gun_index;
  16142. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16143. {
  16144. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16145. {
  16146. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16147. }
  16148. }
  16149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16150. }
  16151. else
  16152. {
  16153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16154. {
  16155. tempIndex = 2;
  16156. }
  16157. else
  16158. {
  16159. tempIndex = gun_index;
  16160. }
  16161. for (int index = 0; index < AC_QUANTITY; index++)
  16162. {
  16163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16164. {
  16165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16166. }
  16167. }// END OF AC_QUANTITY
  16168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16169. }
  16170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16173. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16176. }
  16177. //2.3====================================== Power.Active.Import =========================================
  16178. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16179. {
  16180. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16181. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16182. {
  16183. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16184. {
  16185. tempIndex = ((gun_index==2) ? 1: 0);
  16186. }
  16187. else
  16188. {
  16189. tempIndex = gun_index;
  16190. }
  16191. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16192. {
  16193. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16194. {
  16195. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16196. }
  16197. } // End for CHAdeMO_QUANTITY
  16198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16199. }
  16200. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16201. {
  16202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16203. {
  16204. tempIndex = ((gun_index==2) ? 1: 0);
  16205. }
  16206. else
  16207. {
  16208. tempIndex = gun_index;
  16209. }
  16210. for (int index = 0; index < CCS_QUANTITY; index++)
  16211. {
  16212. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16213. {
  16214. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16215. }
  16216. } // END for CCS_QUANTITY
  16217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16218. }
  16219. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16220. {
  16221. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16222. {
  16223. tempIndex = ((gun_index==2) ? 1: 0);
  16224. }
  16225. else
  16226. {
  16227. tempIndex = gun_index;
  16228. }
  16229. for (int index = 0; index < GB_QUANTITY; index++)
  16230. {
  16231. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16232. {
  16233. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16234. }
  16235. }// END for GB_QUANTITY
  16236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16237. }
  16238. else if(gunType[gun_index] == GUN_TYPE_DO)
  16239. {
  16240. tempIndex = gun_index;
  16241. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16242. {
  16243. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16244. {
  16245. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16246. }
  16247. }
  16248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16249. }
  16250. else
  16251. {
  16252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16253. {
  16254. tempIndex = 2;
  16255. }
  16256. else
  16257. {
  16258. tempIndex = gun_index;
  16259. }
  16260. for (int index = 0; index < AC_QUANTITY; index++)
  16261. {
  16262. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16263. {
  16264. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16265. }
  16266. } // END for AC_QUANTITY
  16267. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16268. }
  16269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16270. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16272. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16275. }
  16276. //2.4====================================== Voltage L1 ====================================================
  16277. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16278. {
  16279. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16280. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16281. {
  16282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16283. {
  16284. tempIndex = ((gun_index==2) ? 1: 0);
  16285. }
  16286. else
  16287. {
  16288. tempIndex = gun_index;
  16289. }
  16290. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16291. {
  16292. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16293. {
  16294. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16295. }
  16296. } // END OF FOR CHAdeMO_QUANTITY
  16297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16298. }
  16299. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16300. {
  16301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16302. {
  16303. tempIndex = ((gun_index==2) ? 1: 0);
  16304. }
  16305. else
  16306. {
  16307. tempIndex = gun_index;
  16308. }
  16309. for (int index = 0; index < CCS_QUANTITY; index++)
  16310. {
  16311. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16312. {
  16313. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16314. }
  16315. } // END OF FOR CCS_QUANTITY
  16316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16317. }
  16318. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16319. {
  16320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16321. {
  16322. tempIndex = ((gun_index==2) ? 1: 0);
  16323. }
  16324. else
  16325. {
  16326. tempIndex = gun_index;
  16327. }
  16328. for (int index = 0; index < GB_QUANTITY; index++)
  16329. {
  16330. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16331. {
  16332. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16333. }
  16334. } // END OF FOR GB_QUANTITY
  16335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16336. }
  16337. else if(gunType[gun_index] == GUN_TYPE_DO)
  16338. {
  16339. tempIndex = gun_index;
  16340. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16341. {
  16342. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16343. {
  16344. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16345. }
  16346. }
  16347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16348. }
  16349. else
  16350. {
  16351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16352. {
  16353. tempIndex = 2;
  16354. }
  16355. else
  16356. {
  16357. tempIndex = gun_index;
  16358. }
  16359. for (int index = 0; index < AC_QUANTITY; index++)
  16360. {
  16361. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16362. {
  16363. 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
  16364. }
  16365. } // END OF FOR AC_QUANTITY
  16366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16367. }
  16368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16371. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16374. }
  16375. //2.5============================================== End SoC =========================================================
  16376. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16377. {
  16378. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16379. 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))
  16380. {
  16381. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16382. {
  16383. tempIndex = ((gun_index==2) ? 1: 0);
  16384. }
  16385. else
  16386. {
  16387. tempIndex = gun_index;
  16388. }
  16389. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16390. {
  16391. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16392. {
  16393. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16394. {
  16395. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16396. }
  16397. }
  16398. }
  16399. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16400. {
  16401. for (int index = 0; index < CCS_QUANTITY; index++)
  16402. {
  16403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16404. {
  16405. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16406. }
  16407. }
  16408. }
  16409. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16410. {
  16411. for (int index = 0; index < GB_QUANTITY; index++)
  16412. {
  16413. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16414. {
  16415. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16416. }
  16417. }
  16418. }
  16419. else if(gunType[gun_index] == GUN_TYPE_DO)
  16420. {
  16421. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16422. {
  16423. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16424. {
  16425. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16426. }
  16427. }
  16428. }
  16429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16435. } // END FOR DC CASE
  16436. }
  16437. //2.6====================================== Current.Import L2 ==============================================
  16438. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16439. {
  16440. // AC 3 phase L2 current
  16441. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16442. {
  16443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16444. {
  16445. tempIndex = 2;
  16446. }
  16447. else
  16448. {
  16449. tempIndex = gun_index;
  16450. }
  16451. for (int index = 0; index < AC_QUANTITY; index++)
  16452. {
  16453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16454. {
  16455. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16456. }
  16457. }// End of for AC_QUANTITY
  16458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16459. }
  16460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16465. }
  16466. //2.7====================================== Current.Import L3 ==============================================
  16467. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16468. {
  16469. // AC 3 phase L3 current
  16470. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16471. {
  16472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16473. {
  16474. tempIndex = 2;
  16475. }
  16476. else
  16477. {
  16478. tempIndex = gun_index;
  16479. }
  16480. for (int index = 0; index < AC_QUANTITY; index++)
  16481. {
  16482. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16483. {
  16484. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16485. }
  16486. }// End of for AC_QUANTITY
  16487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16488. }
  16489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16494. }
  16495. //2.9====================================== Voltage L2 ====================================================
  16496. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16497. {
  16498. // AC 3 phase L2 volatge
  16499. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16500. {
  16501. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16502. {
  16503. tempIndex = 2;
  16504. }
  16505. else
  16506. {
  16507. tempIndex = gun_index;
  16508. }
  16509. for (int index = 0; index < AC_QUANTITY; index++)
  16510. {
  16511. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16512. {
  16513. 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
  16514. }
  16515. } // END OF FOR AC_QUANTITY
  16516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16517. }
  16518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16523. }
  16524. //2.10====================================== Voltage L3 ====================================================
  16525. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16526. {
  16527. // AC 3 phase L3 volatge
  16528. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16529. {
  16530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16531. {
  16532. tempIndex = 2;
  16533. }
  16534. else
  16535. {
  16536. tempIndex = gun_index;
  16537. }
  16538. for (int index = 0; index < AC_QUANTITY; index++)
  16539. {
  16540. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16541. {
  16542. 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
  16543. }
  16544. } // END OF FOR AC_QUANTITY
  16545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16546. }
  16547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16552. }
  16553. //====================== Start SoC ================================
  16554. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16555. {
  16556. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16557. 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))
  16558. {
  16559. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16560. {
  16561. tempIndex = ((gun_index==2) ? 1: 0);
  16562. }
  16563. else
  16564. {
  16565. tempIndex = gun_index;
  16566. }
  16567. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16568. {
  16569. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16570. {
  16571. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16572. {
  16573. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16574. }
  16575. }
  16576. }
  16577. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16578. {
  16579. for (int index = 0; index < CCS_QUANTITY; index++)
  16580. {
  16581. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16582. {
  16583. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16584. }
  16585. }
  16586. }
  16587. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16588. {
  16589. for (int index = 0; index < GB_QUANTITY; index++)
  16590. {
  16591. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16592. {
  16593. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16594. }
  16595. }
  16596. }
  16597. else if(gunType[gun_index] == GUN_TYPE_DO)
  16598. {
  16599. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16600. {
  16601. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16602. {
  16603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16604. }
  16605. }
  16606. }
  16607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16613. } // END FOR DC CASE
  16614. }
  16615. //======================================== Message create ==============================================
  16616. json_object *StopTransaction = json_object_new_object();
  16617. json_object *transactionDatas = json_object_new_array();
  16618. json_object *sampledValues = json_object_new_array();
  16619. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16620. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16621. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16622. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16623. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16624. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16625. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16626. {
  16627. json_object *transactionData = json_object_new_object();
  16628. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16629. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16630. {
  16631. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16632. {
  16633. json_object *sampledValue = json_object_new_object();
  16634. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16635. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16636. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16637. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16638. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16639. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16640. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16641. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16642. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16643. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16644. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16645. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16646. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16647. json_object_array_add(sampledValues, sampledValue);
  16648. }
  16649. }
  16650. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16651. json_object_array_add(transactionDatas, transactionData);
  16652. }
  16653. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16654. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16655. ,MESSAGE_TYPE_CALL
  16656. ,guid
  16657. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16658. json_object_put(StopTransaction);
  16659. // Check File "TempStopTransaction" Exist
  16660. if((access(TempStopTransaction,F_OK))!=-1)
  16661. {
  16662. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16663. fclose(fopen(TempStopTransaction, "w"));
  16664. }
  16665. else
  16666. {
  16667. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16668. FILE *log = fopen(TempStopTransaction, "w+");
  16669. if(log == NULL)
  16670. {
  16671. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16672. return ;
  16673. }
  16674. else
  16675. {
  16676. fclose(log);
  16677. }
  16678. }
  16679. //Add TempStopTransaction | Update TempStopTransaction
  16680. // open file for writing
  16681. FILE *outfile;
  16682. outfile = fopen (TempStopTransaction, "a");
  16683. //DEBUG_INFO("data = %s\n", queuedata);
  16684. fputs(queuedata, outfile);
  16685. fputs("\n", outfile);
  16686. fclose (outfile);
  16687. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16688. }
  16689. void checkTempStopTransaction(int gun_index)
  16690. {
  16691. FILE *fptr1;
  16692. char ch;
  16693. char str[QUEUE_MESSAGE_LENGTH]={0};
  16694. char guid[37]={0};
  16695. char tempdata[65]={0};
  16696. char connectorStr[2]={0};
  16697. char TempStopTransaction[256];
  16698. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16699. fptr1 = fopen(TempStopTransaction, "r");
  16700. //TempStopTransaction格式: 槍號,StopTransaction封包
  16701. if (!fptr1)
  16702. {
  16703. //printf(" File not found or unable to open the input file!!\n");
  16704. return ;
  16705. }
  16706. ch=fgetc(fptr1);
  16707. //printf(" Now the content of the file %s is : \n",fname);
  16708. rewind(fptr1);
  16709. if(ch!=EOF)
  16710. {
  16711. // copy all contents to the temporary file except the specific line
  16712. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16713. {
  16714. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16715. if(str[0]=='\0')
  16716. {
  16717. break;
  16718. }
  16719. //TempStopTransaction格式: 槍號,StopTransaction封包
  16720. strncpy(connectorStr, str, 1);
  16721. if(atoi(connectorStr) != (gun_index+1))
  16722. {
  16723. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16724. fclose(fptr1);
  16725. return ;
  16726. }
  16727. //random_uuid(guid);
  16728. strncpy(guid, str+6, 36); //copy guid
  16729. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16730. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16731. {
  16732. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16733. }
  16734. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16735. OCPP_insert_transaction_msg(NO, str);
  16736. memset(str,0,ARRAY_SIZE(str));
  16737. }
  16738. }
  16739. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16740. fclose(fptr1);
  16741. remove(TempStopTransaction); // remove the original file
  16742. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16743. }
  16744. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16745. {
  16746. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16747. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16748. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16749. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16750. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16751. }
  16752. int GetWebSocketPingInterval(void)
  16753. {
  16754. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16755. }
  16756. int GetServerSign(void)
  16757. {
  16758. return server_sign;
  16759. }
  16760. uint8_t GetOcppSecurityProfile()
  16761. {
  16762. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16763. }
  16764. void GetOcppChargerBoxId(uint8_t *data)
  16765. {
  16766. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16767. }
  16768. void GetOcppSecurityPassword(uint8_t *data)
  16769. {
  16770. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16771. }
  16772. void SetOcppVersion(uint8_t *version)
  16773. {
  16774. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16775. DEBUG_INFO("ocpp version: %s\n", version);
  16776. if(strstr((char*)version, "ocpp1.6") != NULL)
  16777. {
  16778. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16779. }
  16780. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16781. {
  16782. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16783. system("pkill OcppBackend");
  16784. }
  16785. }
  16786. void SetServerSign(int value)
  16787. {
  16788. server_sign = value;
  16789. }
  16790. int GetBootNotificationInterval(void)
  16791. {
  16792. return BootNotificationInterval;
  16793. }
  16794. int GetInternetConn(void)
  16795. {
  16796. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16797. }
  16798. int GetBackendConnectionTimeout(void)
  16799. {
  16800. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16801. }
  16802. int isConnectorInitMode(int gun_index)
  16803. {
  16804. int tempIndex = 0;
  16805. int result = TRUE;
  16806. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16807. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16808. {
  16809. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16810. {
  16811. tempIndex = ((gun_index==2) ? 1: 0);
  16812. }
  16813. else
  16814. {
  16815. tempIndex = gun_index;
  16816. }
  16817. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16818. {
  16819. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16820. {
  16821. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16822. } //end of the same index
  16823. }//end of for CHAdeMO_QUANTITY
  16824. }
  16825. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16826. {
  16827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16828. {
  16829. tempIndex = ((gun_index==2) ? 1: 0);
  16830. }
  16831. else
  16832. {
  16833. tempIndex = gun_index;
  16834. }
  16835. for (int index = 0; index < CCS_QUANTITY; index++)
  16836. {
  16837. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16838. {
  16839. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16840. } //end of the same index
  16841. } // end of for CCS_QUANTITY
  16842. }
  16843. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16844. {
  16845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16846. {
  16847. tempIndex = ((gun_index==2) ? 1: 0);
  16848. }
  16849. else
  16850. {
  16851. tempIndex = gun_index;
  16852. }
  16853. for (int index = 0; index < GB_QUANTITY; index++)
  16854. {
  16855. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16856. {
  16857. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16858. } //end of the same index
  16859. } // end of for GB_QUANTITY
  16860. }
  16861. else if(gunType[gun_index] == GUN_TYPE_DO)
  16862. {
  16863. tempIndex = gun_index;
  16864. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16865. {
  16866. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16867. {
  16868. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16869. } //end of the same index
  16870. }
  16871. }
  16872. else
  16873. {
  16874. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16875. {
  16876. tempIndex = 2;
  16877. }
  16878. else
  16879. {
  16880. tempIndex = gun_index;
  16881. }
  16882. for (int index = 0; index < AC_QUANTITY; index++)
  16883. {
  16884. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16885. {
  16886. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16887. }//end of the same index
  16888. }//end of for AC_QUANTITY
  16889. }
  16890. return result;
  16891. }
  16892. void refreshProcDogTimer()
  16893. {
  16894. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16895. }
  16896. void InitialSystemValue(void)
  16897. {
  16898. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16899. locallistVersion=0;
  16900. BootNotificationInterval = 0;
  16901. authorizeRetryTimes = 0;
  16902. GunStatusInterval = 10;
  16903. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16904. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16905. //Hear Beat
  16906. HeartBeatWithNOResponse = 0;
  16907. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16908. FirstHeartBeat = 0;
  16909. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16910. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16911. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16912. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16913. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16914. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16915. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16916. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16917. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16918. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16919. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16920. //Status && ConnectorPlugIn Setting
  16921. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16922. {
  16923. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16924. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16925. }
  16926. for (int index = 0; index < CCS_QUANTITY; index++)
  16927. {
  16928. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16929. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16930. }
  16931. for (int index = 0; index < GB_QUANTITY; index++)
  16932. {
  16933. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16934. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16935. }
  16936. for (int index = 0; index < AC_QUANTITY; index++)
  16937. {
  16938. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16939. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16940. }
  16941. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16942. {
  16943. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16944. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16945. }
  16946. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16947. {
  16948. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16949. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16950. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16951. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16952. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16953. }
  16954. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16955. clientTime.Heartbeat=time((time_t*)NULL);
  16956. sleep(1);
  16957. }
  16958. void LWS_Send(char *str)
  16959. {
  16960. //=====================================================
  16961. // Check InternetConn 0: disconnected, 1: connected
  16962. //====================================================
  16963. if(GetOcppConnStatus() == 0)
  16964. {
  16965. DEBUG_INFO("offline now !!!\n");
  16966. return;
  16967. }
  16968. // Only disable isWebsocketSendable operation initiated by charger
  16969. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16970. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16971. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16972. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16973. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16974. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16975. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16976. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16977. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16978. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16979. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16980. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16981. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16982. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16983. {
  16984. isWebsocketSendable = 0;
  16985. }
  16986. pthread_mutex_lock(&lock_send);
  16987. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16988. sprintf((char *)SendBuffer, "%s", str);
  16989. SendBufLen = strlen(str);
  16990. pthread_mutex_unlock(&lock_send);
  16991. lws_callback_on_writable(wsi_client);
  16992. //lws_service(context, 0);
  16993. //sleep(1);
  16994. }
  16995. void LWS_SendNow(char *str)
  16996. {
  16997. //=====================================================
  16998. // Check InternetConn 0: disconnected, 1: connected
  16999. //====================================================
  17000. if(GetOcppConnStatus() == 0)
  17001. {
  17002. DEBUG_INFO("offline now !!!\n");
  17003. return;
  17004. }
  17005. // Only disable isWebsocketSendable operation initiated by charger
  17006. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17007. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17008. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17009. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17010. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17011. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17012. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17013. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17014. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17015. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17016. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17017. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17018. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17019. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17020. {
  17021. isWebsocketSendable = 0;
  17022. }
  17023. pthread_mutex_lock(&lock_send);
  17024. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17025. sprintf((char *)SendBuffer, "%s", str);
  17026. SendBufLen = strlen(str);
  17027. pthread_mutex_unlock(&lock_send);
  17028. lws_callback_on_writable(wsi_client);
  17029. lws_service(context, 0);
  17030. //sleep(1);
  17031. }