MessageHandler.c 1.0 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. //===============================
  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. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  54. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. //============================================
  90. // OCPP California Pricing Requirements
  91. //============================================
  92. static char dmsVersion[21] = {0};
  93. extern sqlite3 *db;
  94. int TransactionMessageAttemptsGet(void);
  95. int TransactionMessageRetryIntervalGet(void);
  96. int GetOcppConnStatus(void);
  97. void SetOcppConnStatus(uint8_t status);
  98. int setKeyValue(char *key, char *value);
  99. void OCPP_get_TableAuthlocalAllData(void);
  100. void processUnkownKey(void);
  101. struct InterLock
  102. {
  103. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  104. unsigned char isGetDiagnosticGoing:1;
  105. unsigned char isUpdateFirmwareGoing:1;
  106. }interLock;
  107. struct ClientTime
  108. {
  109. struct timespec Heartbeat;
  110. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  111. struct timespec StartTransaction;
  112. struct timespec StopTransaction;
  113. struct timespec MeterValues[CONNECTOR_QUANTITY];
  114. struct timespec RemoteStartWait;
  115. struct timespec TcciQueryDeduct;
  116. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  117. }clientTime;
  118. typedef union
  119. {
  120. //Operations Initiated by Central System
  121. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  122. struct
  123. {
  124. //CsMsgValue[0]
  125. unsigned char StatusNotificationReq:1; //bit 0,
  126. unsigned char StatusNotificationConf:1; //bit 1,
  127. unsigned char TriggerMeterValue:1; //bit 2,
  128. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  129. unsigned char isOnCharging:1; //bit 4,
  130. unsigned char :3; //bit5~7
  131. }bits[CONNECTOR_QUANTITY];
  132. }CpinitiateMsg;
  133. CpinitiateMsg cpinitateMsg;
  134. //GetConfiguration Array
  135. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  136. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  138. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  139. static char *ChargePointErrorCodeStr[] = {
  140. MACROSTR(ConnectorLockFailure),
  141. MACROSTR(EVCommunicationError),
  142. MACROSTR(GroundFailure),
  143. MACROSTR(HighTemperature),
  144. MACROSTR(InternalError),
  145. MACROSTR(LocalListConflict),
  146. MACROSTR(NoError),
  147. MACROSTR(OtherError),
  148. MACROSTR(OverCurrentFailure),
  149. MACROSTR(OverVoltage),
  150. MACROSTR(PowerMeterFailure),
  151. MACROSTR(PowerSwitchFailure),
  152. MACROSTR(ReaderFailure),
  153. MACROSTR(ResetFailure),
  154. MACROSTR(UnderVoltage),
  155. MACROSTR(WeakSignal)
  156. };
  157. static char * ChargePointStatusStr[] = {
  158. MACROSTR(Available),
  159. MACROSTR(Preparing),
  160. MACROSTR(Charging),
  161. MACROSTR(SuspendedEVSE),
  162. MACROSTR(SuspendedEV),
  163. MACROSTR(Finishing),
  164. MACROSTR(Reserved),
  165. MACROSTR(Unavailable),
  166. MACROSTR(Faulted)
  167. };
  168. static char *RegistrationStatusStr[] = {
  169. MACROSTR(Accepted),
  170. MACROSTR(Pending),
  171. MACROSTR(Rejected)
  172. };
  173. static char *AvailabilityTypeStr[] = {
  174. MACROSTR(Inoperative),
  175. MACROSTR(Operative)
  176. };
  177. static char *AvailabilityStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(Scheduled)
  181. };
  182. static char *ConfigurationStatusStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(RebootRequired),
  186. MACROSTR(NotSupported)
  187. };
  188. static char *ClearCacheStatusStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Rejected)
  191. };
  192. static char *ChargingProfilePurposeTypeStr[] = {
  193. MACROSTR(ChargePointMaxProfile),
  194. MACROSTR(TxDefaultProfile),
  195. MACROSTR(TxProfile)
  196. };
  197. static char *ChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Rejected),
  200. MACROSTR(NotSupported)
  201. };
  202. static char *ClearChargingProfileStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Unknown)
  205. };
  206. static char *GetCompositeScheduleStatusStr[] = {
  207. MACROSTR(Accepted),
  208. MACROSTR(Rejected)
  209. };
  210. static char *UpdateTypeStr[] = {
  211. MACROSTR(Differential),
  212. MACROSTR(Full)
  213. };
  214. static char *UpdateStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Failed),
  217. MACROSTR(NotSupported),
  218. MACROSTR(VersionMismatch)
  219. };
  220. static char *RemoteStartStopStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Rejected)
  223. };
  224. static char *ReservationStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Faulted),
  227. MACROSTR(Occupied),
  228. MACROSTR(Rejected),
  229. MACROSTR(Unavailable)
  230. };
  231. static char *ResetTypeStr[] = {
  232. MACROSTR(Hard),
  233. MACROSTR(Soft)
  234. };
  235. static char *ResetStatusStr[] = {
  236. MACROSTR(Accepted),
  237. MACROSTR(Rejected)
  238. };
  239. static char * DiagnosticsStatusStr[] = {
  240. MACROSTR(Idle),
  241. MACROSTR(Uploaded),
  242. MACROSTR(UploadFailed),
  243. MACROSTR(Uploading)
  244. };
  245. static char * FirmwareStatusStr[] = {
  246. MACROSTR(Downloaded),
  247. MACROSTR(DownloadFailed),
  248. MACROSTR(Downloading),
  249. MACROSTR(Idle),
  250. MACROSTR(InstallationFailed),
  251. MACROSTR(Installing),
  252. MACROSTR(Installed)
  253. };
  254. static char * MessageTriggerStr[] = {
  255. MACROSTR(BootNotification),
  256. MACROSTR(DiagnosticsStatusNotification),
  257. MACROSTR(FirmwareStatusNotification),
  258. MACROSTR(Heartbeat),
  259. MACROSTR(MeterValues),
  260. MACROSTR(StatusNotification)
  261. };
  262. static char * TriggerMessageStatusStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected),
  265. MACROSTR(NotImplemented)
  266. };
  267. static char * UnlockStatusStr[] = {
  268. MACROSTR(Unlocked),
  269. MACROSTR(UnlockFailed),
  270. MACROSTR(NotSupported)
  271. };
  272. #if 0
  273. static char * StopTransactionReasonStr[] = {
  274. MACROSTR(EmergencyStop),
  275. MACROSTR(EVDisconnected),
  276. MACROSTR(HardReset),
  277. MACROSTR(Local),
  278. MACROSTR(Other),
  279. MACROSTR(PowerLoss),
  280. MACROSTR(Reboot),
  281. MACROSTR(Remote),
  282. MACROSTR(SoftReset),
  283. MACROSTR(UnlockCommand),
  284. MACROSTR(DeAuthorized)
  285. };
  286. #endif
  287. static char * CancelReservationStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Rejected)
  290. };
  291. static char * ReadingContextStr[] = {
  292. MACROSTR(Interruption.Begin),
  293. MACROSTR(Interruption.End),
  294. MACROSTR(Other),
  295. MACROSTR(Sample.Clock),
  296. MACROSTR(Sample.Periodic),
  297. MACROSTR(Transaction.Begin),
  298. MACROSTR(Transaction.End),
  299. MACROSTR(Trigger)
  300. };
  301. static char * ValueFormatStr[] = {
  302. MACROSTR(Raw),
  303. MACROSTR(SignedData)
  304. };
  305. static char * MeasurandStr[] = {
  306. MACROSTR(Current.Export),
  307. MACROSTR(Current.Import),
  308. MACROSTR(Current.Offered),
  309. MACROSTR(Energy.Active.Export.Register),
  310. MACROSTR(Energy.Active.Import.Register),
  311. MACROSTR(Energy.Reactive.Export.Register),
  312. MACROSTR(Energy.Reactive.Import.Register),
  313. MACROSTR(Energy.Active.Export.Interval),
  314. MACROSTR(Energy.Active.Import.Interval),
  315. MACROSTR(Energy.Reactive.Export.Interval),
  316. MACROSTR(Energy.Reactive.Import.Interval),
  317. MACROSTR(Frequency),
  318. MACROSTR(Power.Active.Export),
  319. MACROSTR(Power.Active.Import),
  320. MACROSTR(Power.Factor),
  321. MACROSTR(Power.Offered),
  322. MACROSTR(Power.Reactive.ExportMACROSTR),
  323. MACROSTR(Power.Reactive.Import),
  324. MACROSTR(RPM),
  325. MACROSTR(SoC),
  326. MACROSTR(Temperature),
  327. MACROSTR(Voltage)
  328. };
  329. static char * LocationStr[] = {
  330. MACROSTR(Body),
  331. MACROSTR(Cable),
  332. MACROSTR(EV),
  333. MACROSTR(Inlet),
  334. MACROSTR(Outlet)
  335. };
  336. static char * PhaseStr[] = {
  337. MACROSTR(L1),
  338. MACROSTR(L2),
  339. MACROSTR(L3),
  340. MACROSTR(N),
  341. MACROSTR(L1-N),
  342. MACROSTR(L2-N),
  343. MACROSTR(L3-N),
  344. MACROSTR(L1-L2),
  345. MACROSTR(L2-L3),
  346. MACROSTR(L3-L1)
  347. };
  348. static char * UnitOfMeasureStr[] = {
  349. MACROSTR(Wh),
  350. MACROSTR(kWh),
  351. MACROSTR(varh),
  352. MACROSTR(kvarh),
  353. MACROSTR(W),
  354. MACROSTR(kW),
  355. MACROSTR(VA),
  356. MACROSTR(kVA),
  357. MACROSTR(var),
  358. MACROSTR(kvar),
  359. MACROSTR(A),
  360. MACROSTR(V),
  361. MACROSTR(Celsius),
  362. MACROSTR(Fahrenheit),
  363. MACROSTR(K),
  364. MACROSTR(Percent)
  365. };
  366. //=========================================
  367. // Certificate related routine
  368. //=========================================
  369. int certVerify(char *privateKey, char *cert)
  370. {
  371. int result = PASS;
  372. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  373. // Load certificate file
  374. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  375. {
  376. DEBUG_ERROR("Load certificate error!\n");
  377. result = FAIL;
  378. }
  379. // Load private key file
  380. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  381. {
  382. DEBUG_ERROR("Load private key error!\n");
  383. result = FAIL;
  384. }
  385. if(!SSL_CTX_check_private_key(ctx))
  386. {
  387. result = FAIL;
  388. }
  389. SSL_CTX_free(ctx);
  390. return result;
  391. }
  392. //=========================================
  393. // TTIA routine
  394. //=========================================
  395. int sendTTIAInfo(uint8_t gun_index)
  396. {
  397. static int sn = 0;
  398. int result = FAIL;
  399. struct hostent *server;
  400. int udp_socket_fd;
  401. struct sockaddr_in dest_addr = {0};
  402. uint8_t tx_buf[80] = {0};
  403. uint8_t logBuf[256]= {0};
  404. uint8_t tx_len, tempIndex, socStart, socEnd;
  405. uint16_t PresentChargedEnergy;
  406. struct tm tmStart, tmEnd;
  407. DEBUG_INFO("sendTTIAInfo...\n");
  408. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  409. {
  410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  411. {
  412. tempIndex = ((gun_index==2) ? 1: 0);
  413. }
  414. else
  415. {
  416. tempIndex = gun_index;
  417. }
  418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  419. {
  420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  421. {
  422. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  423. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  424. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  425. }
  426. }
  427. }
  428. else if(gunType[gun_index] == GUN_TYPE_CCS)
  429. {
  430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  431. {
  432. tempIndex = ((gun_index==2) ? 1: 0);
  433. }
  434. else
  435. {
  436. tempIndex = gun_index;
  437. }
  438. for (int index = 0; index < CCS_QUANTITY; index++)
  439. {
  440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  441. {
  442. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  443. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  444. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  445. }
  446. }
  447. }
  448. else if(gunType[gun_index] == GUN_TYPE_GBT)
  449. {
  450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  451. {
  452. tempIndex = ((gun_index==2) ? 1: 0);
  453. }
  454. else
  455. {
  456. tempIndex = gun_index;
  457. }
  458. for (int index = 0; index < GB_QUANTITY; index++)
  459. {
  460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  461. {
  462. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  463. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  464. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  465. }
  466. }
  467. }
  468. else if(gunType[gun_index] == GUN_TYPE_DO)
  469. {
  470. tempIndex = gun_index;
  471. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  472. {
  473. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  474. {
  475. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  476. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  477. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  478. }
  479. }
  480. }
  481. else
  482. {
  483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  484. {
  485. tempIndex = 2;
  486. }
  487. else
  488. {
  489. tempIndex = gun_index;
  490. }
  491. for (int index = 0; index < AC_QUANTITY; index++)
  492. {
  493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  494. {
  495. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  496. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  497. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  498. }
  499. }// END
  500. }
  501. // Message assembly
  502. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  503. tx_buf[4] = 0x02; // Protocol Version
  504. tx_buf[5] = 0xb0; // Message ID
  505. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  506. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  507. tx_buf[8] = 0x00; // CarID low byte
  508. tx_buf[9] = 0x00; // CarID high byte
  509. tx_buf[10] = 0x00; // ID Storage
  510. tx_buf[11] = 0x00; // Driver lowest byte
  511. tx_buf[12] = 0x00; // Driver 2nd byte
  512. tx_buf[13] = 0x00; // Driver 3rd byte
  513. tx_buf[14] = 0x00; // Driver highest byte
  514. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  515. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  516. tx_buf[17] = 0x00; // Reserve
  517. tx_buf[18] = 60 & 0xff; // Payload length low byte
  518. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  519. // EVSE provider
  520. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  521. // EVSE provider
  522. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  523. // EVSE id
  524. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  525. // Connector id
  526. tx_buf[37] = gun_index;
  527. // EVSE station
  528. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  529. // Vehicle SN
  530. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  531. // Mileage
  532. tx_buf[61] = 0x00; // lowest byte
  533. tx_buf[62] = 0x00; // 2nd byte
  534. tx_buf[63] = 0x00; // highest byte
  535. // Start date time 6 bytes
  536. 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))
  537. {
  538. struct tm *tmTarget;
  539. struct timeb tbTarget;
  540. tmStart.tm_year -= 1900;
  541. tmStart.tm_mon -= 1;
  542. tmStart.tm_gmtoff = 0;
  543. tbTarget.time = mktime(&tmStart);
  544. tbTarget.timezone = 0;
  545. tbTarget.time += (8*3600);
  546. tmTarget = gmtime(&tbTarget.time);
  547. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  548. tx_buf[65] = (tmTarget->tm_mon+1);
  549. tx_buf[66] = tmTarget->tm_mday;
  550. tx_buf[67] = tmTarget->tm_hour;
  551. tx_buf[68] = tmTarget->tm_min;
  552. tx_buf[69] = tmTarget->tm_sec;
  553. }
  554. // Stop date time 6 bytes
  555. 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))
  556. {
  557. struct tm *tmTarget;
  558. struct timeb tbTarget;
  559. tmEnd.tm_year -= 1900;
  560. tmEnd.tm_mon -= 1;
  561. tmEnd.tm_gmtoff = 0;
  562. tbTarget.time = mktime(&tmEnd);
  563. tbTarget.timezone = 0;
  564. tbTarget.time += (8*3600);
  565. tmTarget = gmtime(&tbTarget.time);
  566. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  567. tx_buf[71] = (tmTarget->tm_mon+1);
  568. tx_buf[72] = tmTarget->tm_mday;
  569. tx_buf[73] = tmTarget->tm_hour;
  570. tx_buf[74] = tmTarget->tm_min;
  571. tx_buf[75] = tmTarget->tm_sec;
  572. }
  573. // Session energy 2 bytes
  574. tx_buf[76] = PresentChargedEnergy & 0xff;
  575. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  576. // Start SOC 1 byte
  577. tx_buf[78] = socStart;
  578. // Stop SOC 1 byte
  579. tx_buf[79] = socEnd;
  580. // Open socket
  581. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  582. if(udp_socket_fd == -1)
  583. {
  584. DEBUG_ERROR("UDP socket create failed!\n");
  585. }
  586. else
  587. {
  588. // Get server DNS entry
  589. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  590. if (server == NULL)
  591. {
  592. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  593. }
  594. else
  595. {
  596. // Build the server's Internet address
  597. bzero((char *) &dest_addr, sizeof(dest_addr));
  598. dest_addr.sin_family = AF_INET;
  599. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  600. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  601. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  602. {
  603. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  604. {
  605. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  606. }
  607. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  608. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  609. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  610. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  611. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  612. DEBUG_TTIA_INFO("---------- Header ----------\n");
  613. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  614. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  615. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  616. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  617. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  618. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  619. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  620. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  621. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  622. DEBUG_TTIA_INFO("Len: 0x3C\n");
  623. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  624. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  625. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  626. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  627. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  628. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  629. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  630. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  631. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  632. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  633. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  634. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  635. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  636. DEBUG_TTIA_INFO("=========================================\n");
  637. sn++;
  638. result = PASS;
  639. }
  640. else
  641. {
  642. DEBUG_ERROR("UDP sent out fail.\n");
  643. }
  644. }
  645. }
  646. return result;
  647. }
  648. //=========================================
  649. // Save configuration
  650. //=========================================
  651. int runShellCmd(const char*cmd)
  652. {
  653. int result = FAIL;
  654. char buf[256];
  655. FILE *fp;
  656. fp = popen(cmd, "r");
  657. if(fp != NULL)
  658. {
  659. while(fgets(buf, sizeof(buf), fp) != NULL)
  660. {
  661. DEBUG_INFO("%s\n", buf);
  662. }
  663. result = PASS;
  664. }
  665. pclose(fp);
  666. return result;
  667. }
  668. int StoreUsrConfigData(struct SysConfigData *UsrData)
  669. {
  670. int result = PASS;
  671. int fd,wrd;
  672. unsigned int i,Chk;
  673. unsigned char *ptr, *BufTmp;
  674. int MtdBlockSize = 0x300000;
  675. Chk=0;
  676. ptr=(unsigned char *)UsrData;
  677. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  678. {
  679. memset(BufTmp,0,MtdBlockSize);
  680. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  681. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  682. Chk+=*(BufTmp+i);
  683. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  684. // Output configuration to file.
  685. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  686. if (fd < 0)
  687. {
  688. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  689. free(BufTmp);
  690. return 0;
  691. }
  692. wrd=write(fd, BufTmp, MtdBlockSize);
  693. close(fd);
  694. if(wrd<MtdBlockSize)
  695. {
  696. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  697. free(BufTmp);
  698. return 0;
  699. }
  700. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  701. DEBUG_INFO("Erase /dev/mtd10.\n");
  702. runShellCmd("flash_erase /dev/mtd10 0 0");
  703. DEBUG_INFO("Write /dev/mtd10.\n");
  704. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  705. DEBUG_INFO("Erase /dev/mtd11.\n");
  706. runShellCmd("flash_erase /dev/mtd11 0 0");
  707. DEBUG_INFO("Write /dev/mtd11.\n");
  708. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  709. system("rm -f /mnt/EvseConfig.bin");
  710. DEBUG_INFO("EvseConfig write to flash OK\n");
  711. }
  712. else
  713. {
  714. DEBUG_ERROR("alloc BlockSize NG\r\n");
  715. result = FAIL;
  716. }
  717. if(BufTmp!=NULL)
  718. free(BufTmp);
  719. return result;
  720. }
  721. //=========================================
  722. // Sqlite3 related function
  723. //=========================================
  724. static int selectSqlCount = 0;
  725. static int callback(void *data, int argc, char **argv, char **azColName){
  726. int i;
  727. //printf("%s: ", (const char*)data);
  728. selectSqlCount = argc;
  729. for(i = 0; i<argc; i++){
  730. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  731. }
  732. //printf("\n");
  733. return 0;
  734. }
  735. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  736. //int i;
  737. //printf("%s:\n", (const char*)data);
  738. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  739. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  740. return 0;
  741. }
  742. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  743. //printf("%s:\n", (const char*)data);
  744. //idTag
  745. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  746. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  747. //parentIdTag
  748. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  749. //expir_date
  750. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  751. //status
  752. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  753. //version
  754. if(columenCount > 5)
  755. idTagQuery.listVersionInt = atoi(columnValue[5]);
  756. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  757. return 0;
  758. }
  759. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  760. {
  761. // localversion = argv[5] ? atoi(argv[5]) : 0;
  762. // printf("localversion=%d\n", localversion);
  763. return 0;
  764. }
  765. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  766. {
  767. for (int i = 0; i < n_columns; i++)
  768. {
  769. DEBUG_INFO("%s\t", col_values[i]);
  770. }
  771. DEBUG_INFO("\n");
  772. return 0;
  773. }
  774. int OCPP_cleanLocalCache()
  775. {
  776. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  777. char *errMsg = 0;
  778. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  779. if (SQLITE_OK != rc)
  780. {
  781. DEBUG_INFO("SQL error: %s\n",errMsg);
  782. return FALSE;
  783. }
  784. return TRUE;
  785. }
  786. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  787. {
  788. int isSuccess = TRUE;
  789. int ret = 0;
  790. //const char* data = "Callback function called";
  791. char sql[300];
  792. char zErrMsg[200];
  793. memset(sql, 0, 300);
  794. memset(zErrMsg, 0, 200);
  795. 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);
  796. //* Execute SQL statement */
  797. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  798. if( ret != SQLITE_OK )
  799. {
  800. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  801. isSuccess = FALSE;
  802. }
  803. return isSuccess;
  804. }
  805. void OCPP_getIdTagFromLocalCache(char idTag[])
  806. {
  807. int rc = 0;
  808. char sql[100];
  809. char zErrMsg[100];
  810. memset(sql, 0, 100);
  811. memset(zErrMsg, 0, 100);
  812. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  813. memset(&idTagQuery, 0, sizeof(idTagQuery));
  814. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. }
  822. void OCPP_getListVerion()
  823. {
  824. int rc = 0;
  825. // const char* data = "Callback function called";
  826. char sql[100];
  827. char zErrMsg[100];
  828. memset(sql, 0, 100);
  829. memset(zErrMsg, 0, 100);
  830. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  831. /* Execute SQL statement */
  832. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  833. if( rc != SQLITE_OK )
  834. {
  835. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  836. }
  837. }
  838. void OCPP_get_TableAuthlocalAllData(void)
  839. {
  840. int rc = 0;
  841. char sql[100];
  842. char zErrMsg[100];
  843. memset(sql, 0, 100);
  844. memset(zErrMsg, 0, 100);
  845. sprintf(sql,"select * from ocpp_auth_local ");
  846. /* Execute SQL statement */
  847. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  848. if( rc != SQLITE_OK )
  849. {
  850. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  851. }
  852. //return ver;
  853. }
  854. int OCPP_cleanLocalList()
  855. {
  856. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  857. char *errMsg = 0;
  858. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  859. if (SQLITE_OK != rc)
  860. {
  861. DEBUG_INFO("%s\n",errMsg);
  862. return FALSE;
  863. }
  864. return TRUE;
  865. }
  866. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  867. {
  868. int isSuccess = FALSE;
  869. int ret = 0;
  870. //const char* data = "Callback function called";
  871. char sql[300];
  872. char zErrMsg[200];
  873. memset(sql, 0, 300);
  874. memset(zErrMsg, 0, 200);
  875. 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);
  876. //* Execute SQL statement */
  877. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  878. if( ret != SQLITE_OK )
  879. {
  880. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  881. return isSuccess;
  882. }
  883. memset(sql, 0, 300);
  884. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  885. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  886. if( ret != SQLITE_OK )
  887. {
  888. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  889. return isSuccess;
  890. }
  891. isSuccess = TRUE;
  892. return isSuccess;
  893. }
  894. void OCPP_getIdTagFromLocalList(char idTag[])
  895. {
  896. int rc = 0;
  897. // const char* data = "Callback function called";
  898. char sql[100];
  899. char zErrMsg[100];
  900. memset(sql, 0, 100);
  901. memset(zErrMsg, 0, 100);
  902. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  903. memset(&idTagQuery, 0, sizeof(idTagQuery));
  904. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  905. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  906. /* Execute SQL statement */
  907. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  908. if( rc != SQLITE_OK )
  909. {
  910. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  911. }
  912. //return ver;
  913. }
  914. void OCPP_deleteIdTagFromLocalList(char idTag[])
  915. {
  916. //int ver = 0;
  917. //int isSuccess = FALSE;
  918. int rc = 0;
  919. char sql[100];
  920. char zErrMsg[100];
  921. memset(sql, 0, 100);
  922. memset(zErrMsg, 0, 100);
  923. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  924. //* Execute SQL statement */
  925. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  926. if( rc != SQLITE_OK )
  927. {
  928. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  929. }
  930. }
  931. int getCurrentYear()
  932. {
  933. int result = 0;
  934. time_t CurrentTime;
  935. struct tm *tm;
  936. CurrentTime = time(NULL);
  937. tm=localtime(&CurrentTime);
  938. result = (tm->tm_year + 1900);
  939. return result;
  940. }
  941. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  942. {
  943. int result = PASS;
  944. char* errMsg = NULL;
  945. char sqlStr[8192];
  946. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  947. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  948. {
  949. result = FAIL;
  950. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  951. }
  952. 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));
  953. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  954. {
  955. result = FAIL;
  956. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  957. }
  958. return result;
  959. }
  960. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  961. {
  962. int isSuccess = TRUE;
  963. int tempIndex;
  964. json_object *EnergyDataTransfer = json_object_new_object();
  965. json_object *periodEnergys = json_object_new_object();
  966. char sql[1024];
  967. char zErrMsg[200];
  968. memset(sql, 0, ARRAY_SIZE(sql));
  969. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  970. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  971. {
  972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  973. {
  974. tempIndex = ((gun_index==2) ? 1: 0);
  975. }
  976. else
  977. {
  978. tempIndex = gun_index;
  979. }
  980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  981. {
  982. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  983. {
  984. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  985. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  986. {
  987. uint8_t period[3];
  988. sprintf((char*)period, "%d", idxPeriod);
  989. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  990. }
  991. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  992. } //end of the same index
  993. }//end of for CHAdeMO_QUANTITY
  994. }
  995. else if(gunType[gun_index] == GUN_TYPE_CCS)
  996. {
  997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  998. {
  999. tempIndex = ((gun_index==2) ? 1: 0);
  1000. }
  1001. else
  1002. {
  1003. tempIndex = gun_index;
  1004. }
  1005. for (int index = 0; index < CCS_QUANTITY; index++)
  1006. {
  1007. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1008. {
  1009. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1010. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1011. {
  1012. uint8_t period[3];
  1013. sprintf((char*)period, "%d", idxPeriod);
  1014. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1015. }
  1016. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1017. } //end of the same index
  1018. } // end of for CCS_QUANTITY
  1019. }
  1020. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1021. {
  1022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1023. {
  1024. tempIndex = ((gun_index==2) ? 1: 0);
  1025. }
  1026. else
  1027. {
  1028. tempIndex = gun_index;
  1029. }
  1030. for (int index = 0; index < GB_QUANTITY; index++)
  1031. {
  1032. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1033. {
  1034. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1035. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1036. {
  1037. uint8_t period[3];
  1038. sprintf((char*)period, "%d", idxPeriod);
  1039. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1040. }
  1041. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1042. } //end of the same index
  1043. } // end of for GB_QUANTITY
  1044. }
  1045. else if(gunType[gun_index] == GUN_TYPE_DO)
  1046. {
  1047. tempIndex = gun_index;
  1048. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1049. {
  1050. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1051. {
  1052. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1053. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1054. {
  1055. uint8_t period[3];
  1056. sprintf((char*)period, "%d", idxPeriod);
  1057. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1058. }
  1059. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1060. } //end of the same index
  1061. }
  1062. }
  1063. else
  1064. {
  1065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1066. {
  1067. tempIndex = 2;
  1068. }
  1069. else
  1070. {
  1071. tempIndex = gun_index;
  1072. }
  1073. for (int index = 0; index < AC_QUANTITY; index++)
  1074. {
  1075. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1076. {
  1077. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1078. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1079. {
  1080. uint8_t period[3];
  1081. sprintf((char*)period, "%d", idxPeriod);
  1082. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1083. }
  1084. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1085. }//end of the same index
  1086. }//end of for AC_QUANTITY
  1087. }
  1088. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1089. json_object_put(EnergyDataTransfer);
  1090. //* Execute SQL statement */
  1091. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1092. {
  1093. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1094. isSuccess = FALSE;
  1095. }
  1096. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1097. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1098. {
  1099. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1100. isSuccess = FALSE;
  1101. }
  1102. return isSuccess;
  1103. }
  1104. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1105. {
  1106. int isSuccess = TRUE;
  1107. char sql[512];
  1108. char zErrMsg[200];
  1109. int rows, cols;
  1110. char **resultData;
  1111. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1112. /* Execute SQL statement */
  1113. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1114. {
  1115. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1116. isSuccess = FALSE;
  1117. }
  1118. else
  1119. {
  1120. if((rows > 0) && (atoi(resultData[4]) > 0))
  1121. {
  1122. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1123. }
  1124. else
  1125. {
  1126. DEBUG_WARN("There is not match transaction data.\n");
  1127. isSuccess = FALSE;
  1128. }
  1129. }
  1130. return isSuccess;
  1131. }
  1132. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1133. {
  1134. int result = PASS;
  1135. char* errMsg = NULL;
  1136. char sqlStr[8192];
  1137. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1138. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1139. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1140. {
  1141. result = FAIL;
  1142. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1143. }
  1144. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1145. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1146. {
  1147. result = FAIL;
  1148. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1149. }
  1150. return result;
  1151. }
  1152. int OCPP_update_deduct_info(int txId, char *creditNo)
  1153. {
  1154. int result = PASS;
  1155. char* errMsg = NULL;
  1156. char sqlStr[8192];
  1157. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1158. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1159. {
  1160. result = FAIL;
  1161. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1162. }
  1163. return result;
  1164. }
  1165. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1166. {
  1167. json_object *dataBuf = json_object_new_object();
  1168. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1169. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1170. json_object_object_add(dataBuf, "txId", json_object_new_int(atoi(columnValue[1])));
  1171. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1172. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1173. json_object_object_add(dataBuf, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1174. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[5])));
  1175. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[9]));
  1176. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1177. json_object_put(dataBuf);
  1178. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1179. return 0;
  1180. }
  1181. void OCPP_query_deduct_info()
  1182. {
  1183. int rc = 0;
  1184. char sql[100];
  1185. char zErrMsg[100];
  1186. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1187. /* Execute SQL statement */
  1188. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1189. if( rc != SQLITE_OK )
  1190. {
  1191. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1192. }
  1193. }
  1194. void reportReaderStatus(int gun_index)
  1195. {
  1196. struct timeval tmnow;
  1197. struct tm *tm;
  1198. char buf[28];//, usec_buf[6];
  1199. gettimeofday(&tmnow, NULL);
  1200. time_t t;
  1201. t = time(NULL);
  1202. /*UTC time and date*/
  1203. tm = gmtime(&t);
  1204. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1205. #if 0 // remove temporally
  1206. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1207. strcat(buf,".");
  1208. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1209. strcat(buf,usec_buf);
  1210. #endif
  1211. json_object *dataBuf = json_object_new_object();
  1212. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1213. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1214. json_object_object_add(dataBuf, "connectorId", json_object_new_int((gun_index+1)));
  1215. json_object_object_add(dataBuf, "readerStatus", json_object_new_int(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus));
  1216. json_object_object_add(dataBuf, "timestamp", json_object_new_string(buf));
  1217. json_object_object_add(dataBuf, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  1218. json_object_object_add(dataBuf, "creditNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
  1219. json_object_object_add(dataBuf, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  1220. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1221. json_object_put(dataBuf);
  1222. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1223. }
  1224. //==========================================
  1225. // Check time passed since today
  1226. //==========================================
  1227. long long DiffTimebWithNow(struct timeb ST)
  1228. {
  1229. //return milli-second
  1230. struct timeb ET;
  1231. long long StartTime,StopTime;
  1232. ftime(&ET);
  1233. StartTime=(long long)ST.time;
  1234. StopTime=(long long)ET.time;
  1235. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1236. }
  1237. int getTimePassSinceToday(uint8_t gun_index)
  1238. {
  1239. int result = -1;
  1240. static time_t lastTime[4];
  1241. time_t t;
  1242. struct tm *tmStartToday;
  1243. struct timeb tbStartToday;
  1244. t=time(NULL);
  1245. if(difftime(t, lastTime[gun_index])>0)
  1246. {
  1247. tmStartToday=localtime(&t);
  1248. tmStartToday->tm_hour = 0;
  1249. tmStartToday->tm_min = 0;
  1250. tmStartToday->tm_sec = 0;
  1251. tbStartToday.time = mktime(tmStartToday);
  1252. tbStartToday.millitm = 0;
  1253. result = DiffTimebWithNow(tbStartToday)/1000;
  1254. lastTime[gun_index] = t;
  1255. }
  1256. return result;
  1257. }
  1258. void getNowDatetime(uint8_t *data)
  1259. {
  1260. time_t t = time(NULL);
  1261. struct tm tm = *localtime(&t);
  1262. 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);
  1263. }
  1264. int syncDateTimeRTC(uint8_t *data)
  1265. {
  1266. struct ParsingResult
  1267. {
  1268. int result;
  1269. int scanedElement;
  1270. int year;
  1271. int month;
  1272. int mday;
  1273. int hour;
  1274. int min;
  1275. int sec;
  1276. int tz_hour;
  1277. int tz_min;
  1278. float minSec;
  1279. }result;
  1280. struct tm tmOrg;
  1281. struct tm *tmTarget;
  1282. struct timeb tbTarget;
  1283. char buf[128];
  1284. memset(&result, 0x00, sizeof(struct ParsingResult));
  1285. result.result = PASS;
  1286. if(strstr((char*)data, ".") != NULL)
  1287. {
  1288. // Original data with mini second
  1289. if(strstr((char*)data, "Z") != NULL)
  1290. {
  1291. // Original data with Z
  1292. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1293. &result.year,
  1294. &result.month,
  1295. &result.mday,
  1296. &result.hour,
  1297. &result.min,
  1298. &result.sec,
  1299. &result.minSec);
  1300. }
  1301. else
  1302. {
  1303. // Original data without Z
  1304. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1305. &result.year,
  1306. &result.month,
  1307. &result.mday,
  1308. &result.hour,
  1309. &result.min,
  1310. &result.sec,
  1311. &result.minSec,
  1312. &result.tz_hour,
  1313. &result.tz_min);
  1314. }
  1315. }
  1316. else
  1317. {
  1318. // Original data without mini second
  1319. if(strstr((char*)data, "Z") != NULL)
  1320. {
  1321. // Original data with Z
  1322. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1323. &result.year,
  1324. &result.month,
  1325. &result.mday,
  1326. &result.hour,
  1327. &result.min,
  1328. &result.sec);
  1329. }
  1330. else
  1331. {
  1332. // Original data without Z
  1333. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1334. &result.year,
  1335. &result.month,
  1336. &result.mday,
  1337. &result.hour,
  1338. &result.min,
  1339. &result.sec,
  1340. &result.tz_hour,
  1341. &result.tz_min);
  1342. }
  1343. }
  1344. tmOrg.tm_year = result.year - 1900;
  1345. tmOrg.tm_mon = result.month - 1;
  1346. tmOrg.tm_mday = result.mday;
  1347. tmOrg.tm_hour = result.hour;
  1348. tmOrg.tm_min = result.min;
  1349. tmOrg.tm_sec = result.sec;
  1350. tmOrg.tm_gmtoff = 0;
  1351. tbTarget.time = mktime(&tmOrg);
  1352. tbTarget.timezone = 0;
  1353. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1354. tmTarget = gmtime(&tbTarget.time);
  1355. 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);
  1356. //DEBUG_INFO(" org date time: %s\n", data);
  1357. //DEBUG_INFO("parse date time: %s\n", buf);
  1358. system(buf);
  1359. system("/sbin/hwclock -w --systohc");
  1360. if(result.scanedElement < 6)
  1361. result.result = FAIL;
  1362. return result.result;
  1363. }
  1364. //==========================================
  1365. // GetCompositeSchedule logic related function
  1366. //==========================================
  1367. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1368. {
  1369. //return milli-second
  1370. unsigned int StartTime,StopTime;
  1371. StartTime=(unsigned int)ST.time;
  1372. StopTime=(unsigned int)ET.time;
  1373. return (StopTime-StartTime);
  1374. }
  1375. int DiffTimebWithNowSec(struct timeb ST)
  1376. {
  1377. //return milli-second
  1378. struct timeb ET;
  1379. unsigned int StartTime,StopTime;
  1380. ftime(&ET);
  1381. StartTime=(unsigned int)ST.time;
  1382. StopTime=(unsigned int)ET.time;
  1383. return (StopTime-StartTime);
  1384. }
  1385. int getStartStop(uint8_t *start, uint8_t *stop)
  1386. {
  1387. struct ParsingResult
  1388. {
  1389. int result;
  1390. int scanedElement;
  1391. int year;
  1392. int month;
  1393. int mday;
  1394. int hour;
  1395. int min;
  1396. int sec;
  1397. int tz_hour;
  1398. int tz_min;
  1399. float minSec;
  1400. };
  1401. struct ParsingResult parseStart;
  1402. struct ParsingResult parseStop;
  1403. int result = -1;
  1404. struct tm tmStart;
  1405. struct timeb tbStart;
  1406. struct tm tmStop;
  1407. struct timeb tbStop;
  1408. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1409. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1410. // Scan start & stop date time
  1411. if(strstr((char*)start, ".") != NULL)
  1412. {
  1413. // Original data with mini second
  1414. if(strstr((char*)start, "Z") != NULL)
  1415. {
  1416. // Original data with Z
  1417. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1418. &parseStart.year,
  1419. &parseStart.month,
  1420. &parseStart.mday,
  1421. &parseStart.hour,
  1422. &parseStart.min,
  1423. &parseStart.sec,
  1424. &parseStart.minSec);
  1425. }
  1426. else
  1427. {
  1428. // Original data without Z
  1429. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1430. &parseStart.year,
  1431. &parseStart.month,
  1432. &parseStart.mday,
  1433. &parseStart.hour,
  1434. &parseStart.min,
  1435. &parseStart.sec,
  1436. &parseStart.minSec,
  1437. &parseStart.tz_hour,
  1438. &parseStart.tz_min);
  1439. }
  1440. }
  1441. else
  1442. {
  1443. // Original data without mini second
  1444. if(strstr((char*)start, "Z") != NULL)
  1445. {
  1446. // Original data with Z
  1447. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1448. &parseStart.year,
  1449. &parseStart.month,
  1450. &parseStart.mday,
  1451. &parseStart.hour,
  1452. &parseStart.min,
  1453. &parseStart.sec);
  1454. }
  1455. else
  1456. {
  1457. // Original data without Z
  1458. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1459. &parseStart.year,
  1460. &parseStart.month,
  1461. &parseStart.mday,
  1462. &parseStart.hour,
  1463. &parseStart.min,
  1464. &parseStart.sec,
  1465. &parseStart.tz_hour,
  1466. &parseStart.tz_min);
  1467. }
  1468. }
  1469. if(strstr((char*)stop, ".") != NULL)
  1470. {
  1471. // Original data with mini second
  1472. if(strstr((char*)stop, "Z") != NULL)
  1473. {
  1474. // Original data with Z
  1475. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1476. &parseStop.year,
  1477. &parseStop.month,
  1478. &parseStop.mday,
  1479. &parseStop.hour,
  1480. &parseStop.min,
  1481. &parseStop.sec,
  1482. &parseStop.minSec);
  1483. }
  1484. else
  1485. {
  1486. // Original data without Z
  1487. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1488. &parseStop.year,
  1489. &parseStop.month,
  1490. &parseStop.mday,
  1491. &parseStop.hour,
  1492. &parseStop.min,
  1493. &parseStop.sec,
  1494. &parseStop.minSec,
  1495. &parseStop.tz_hour,
  1496. &parseStop.tz_min);
  1497. }
  1498. }
  1499. else
  1500. {
  1501. // Original data without mini second
  1502. if(strstr((char*)stop, "Z") != NULL)
  1503. {
  1504. // Original data with Z
  1505. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1506. &parseStop.year,
  1507. &parseStop.month,
  1508. &parseStop.mday,
  1509. &parseStop.hour,
  1510. &parseStop.min,
  1511. &parseStop.sec);
  1512. }
  1513. else
  1514. {
  1515. // Original data without Z
  1516. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1517. &parseStop.year,
  1518. &parseStop.month,
  1519. &parseStop.mday,
  1520. &parseStop.hour,
  1521. &parseStop.min,
  1522. &parseStop.sec,
  1523. &parseStop.tz_hour,
  1524. &parseStop.tz_min);
  1525. }
  1526. }
  1527. // Calculate date time difference
  1528. if((parseStart.scanedElement >=6) &&
  1529. (parseStop.scanedElement >=6))
  1530. {
  1531. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1532. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1533. tmStart.tm_year = parseStart.year - 1900;
  1534. tmStart.tm_mon = parseStart.month - 1;
  1535. tmStart.tm_mday = parseStart.mday;
  1536. tmStart.tm_hour = parseStart.hour;
  1537. tmStart.tm_min = parseStart.min;
  1538. tmStart.tm_sec = parseStart.sec;
  1539. tmStart.tm_gmtoff = 0;
  1540. tbStart.time = mktime(&tmStart);
  1541. tbStart.timezone = 0;
  1542. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1543. tmStop.tm_year = parseStop.year - 1900;
  1544. tmStop.tm_mon = parseStop.month - 1;
  1545. tmStop.tm_mday = parseStop.mday;
  1546. tmStop.tm_hour = parseStop.hour;
  1547. tmStop.tm_min = parseStop.min;
  1548. tmStop.tm_sec = parseStop.sec;
  1549. tmStop.tm_gmtoff = 0;
  1550. tbStop.time = mktime(&tmStop);
  1551. tbStop.timezone = 0;
  1552. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1553. result = DiffTimebSec(tbStart, tbStop);
  1554. //DEBUG_INFO("getStartStop(): %d\n", result);
  1555. }
  1556. else
  1557. {
  1558. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1559. }
  1560. return result;
  1561. }
  1562. int isOvertNow(uint8_t *start)
  1563. {
  1564. int result = NO;
  1565. struct ParsingResult
  1566. {
  1567. int result;
  1568. int scanedElement;
  1569. int year;
  1570. int month;
  1571. int mday;
  1572. int hour;
  1573. int min;
  1574. int sec;
  1575. int tz_hour;
  1576. int tz_min;
  1577. float minSec;
  1578. }parsingResult;
  1579. struct tm tmStart;
  1580. struct timeb tbStart;
  1581. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1582. if(strstr((char*)start, ".") != NULL)
  1583. {
  1584. // Original data with mini second
  1585. if(strstr((char*)start, "Z") != NULL)
  1586. {
  1587. // Original data with Z
  1588. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1589. &parsingResult.year,
  1590. &parsingResult.month,
  1591. &parsingResult.mday,
  1592. &parsingResult.hour,
  1593. &parsingResult.min,
  1594. &parsingResult.sec,
  1595. &parsingResult.minSec);
  1596. }
  1597. else
  1598. {
  1599. // Original data without Z
  1600. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1601. &parsingResult.year,
  1602. &parsingResult.month,
  1603. &parsingResult.mday,
  1604. &parsingResult.hour,
  1605. &parsingResult.min,
  1606. &parsingResult.sec,
  1607. &parsingResult.minSec,
  1608. &parsingResult.tz_hour,
  1609. &parsingResult.tz_min);
  1610. }
  1611. }
  1612. else
  1613. {
  1614. // Original data without mini second
  1615. if(strstr((char*)start, "Z") != NULL)
  1616. {
  1617. // Original data with Z
  1618. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1619. &parsingResult.year,
  1620. &parsingResult.month,
  1621. &parsingResult.mday,
  1622. &parsingResult.hour,
  1623. &parsingResult.min,
  1624. &parsingResult.sec);
  1625. }
  1626. else
  1627. {
  1628. // Original data without Z
  1629. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1630. &parsingResult.year,
  1631. &parsingResult.month,
  1632. &parsingResult.mday,
  1633. &parsingResult.hour,
  1634. &parsingResult.min,
  1635. &parsingResult.sec,
  1636. &parsingResult.tz_hour,
  1637. &parsingResult.tz_min);
  1638. }
  1639. }
  1640. if(parsingResult.scanedElement >= 6)
  1641. {
  1642. tmStart.tm_year = parsingResult.year - 1900;
  1643. tmStart.tm_mon = parsingResult.month - 1;
  1644. tmStart.tm_mday = parsingResult.mday;
  1645. tmStart.tm_hour = parsingResult.hour;
  1646. tmStart.tm_min = parsingResult.min;
  1647. tmStart.tm_sec = parsingResult.sec;
  1648. tmStart.tm_gmtoff = 0;
  1649. tbStart.time = mktime(&tmStart);
  1650. tbStart.timezone = 0;
  1651. tbStart.millitm = 0;
  1652. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1653. if(DiffTimebWithNowSec(tbStart) <= 0)
  1654. result = NO;
  1655. else
  1656. result = YES;
  1657. }
  1658. else
  1659. {
  1660. DEBUG_WARN("Start date parsing error.\n");
  1661. }
  1662. return result;
  1663. }
  1664. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1665. {
  1666. struct ParsingResult
  1667. {
  1668. int result;
  1669. int scanedElement;
  1670. int year;
  1671. int month;
  1672. int mday;
  1673. int hour;
  1674. int min;
  1675. int sec;
  1676. int tz_hour;
  1677. int tz_min;
  1678. float minSec;
  1679. };
  1680. struct ParsingResult parseStart;
  1681. struct ParsingResult parseStop;
  1682. int result = -1;
  1683. struct tm tmStart;
  1684. struct timeb tbStart;
  1685. struct tm tmStop;
  1686. struct timeb tbStop;
  1687. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1688. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1689. // Scan start & stop date time
  1690. if(strstr((char*)start, ".") != NULL)
  1691. {
  1692. // Original data with mini second
  1693. if(strstr((char*)start, "Z") != NULL)
  1694. {
  1695. // Original data with Z
  1696. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1697. &parseStart.year,
  1698. &parseStart.month,
  1699. &parseStart.mday,
  1700. &parseStart.hour,
  1701. &parseStart.min,
  1702. &parseStart.sec,
  1703. &parseStart.minSec);
  1704. }
  1705. else
  1706. {
  1707. // Original data without Z
  1708. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1709. &parseStart.year,
  1710. &parseStart.month,
  1711. &parseStart.mday,
  1712. &parseStart.hour,
  1713. &parseStart.min,
  1714. &parseStart.sec,
  1715. &parseStart.minSec,
  1716. &parseStart.tz_hour,
  1717. &parseStart.tz_min);
  1718. }
  1719. }
  1720. else
  1721. {
  1722. // Original data without mini second
  1723. if(strstr((char*)start, "Z") != NULL)
  1724. {
  1725. // Original data with Z
  1726. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1727. &parseStart.year,
  1728. &parseStart.month,
  1729. &parseStart.mday,
  1730. &parseStart.hour,
  1731. &parseStart.min,
  1732. &parseStart.sec);
  1733. }
  1734. else
  1735. {
  1736. // Original data without Z
  1737. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1738. &parseStart.year,
  1739. &parseStart.month,
  1740. &parseStart.mday,
  1741. &parseStart.hour,
  1742. &parseStart.min,
  1743. &parseStart.sec,
  1744. &parseStart.tz_hour,
  1745. &parseStart.tz_min);
  1746. }
  1747. }
  1748. if(strstr((char*)stop, ".") != NULL)
  1749. {
  1750. // Original data with mini second
  1751. if(strstr((char*)stop, "Z") != NULL)
  1752. {
  1753. // Original data with Z
  1754. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1755. &parseStop.year,
  1756. &parseStop.month,
  1757. &parseStop.mday,
  1758. &parseStop.hour,
  1759. &parseStop.min,
  1760. &parseStop.sec,
  1761. &parseStop.minSec);
  1762. }
  1763. else
  1764. {
  1765. // Original data without Z
  1766. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1767. &parseStop.year,
  1768. &parseStop.month,
  1769. &parseStop.mday,
  1770. &parseStop.hour,
  1771. &parseStop.min,
  1772. &parseStop.sec,
  1773. &parseStop.minSec,
  1774. &parseStop.tz_hour,
  1775. &parseStop.tz_min);
  1776. }
  1777. }
  1778. else
  1779. {
  1780. // Original data without mini second
  1781. if(strstr((char*)stop, "Z") != NULL)
  1782. {
  1783. // Original data with Z
  1784. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1785. &parseStop.year,
  1786. &parseStop.month,
  1787. &parseStop.mday,
  1788. &parseStop.hour,
  1789. &parseStop.min,
  1790. &parseStop.sec);
  1791. }
  1792. else
  1793. {
  1794. // Original data without Z
  1795. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1796. &parseStop.year,
  1797. &parseStop.month,
  1798. &parseStop.mday,
  1799. &parseStop.hour,
  1800. &parseStop.min,
  1801. &parseStop.sec,
  1802. &parseStop.tz_hour,
  1803. &parseStop.tz_min);
  1804. }
  1805. }
  1806. // Calculate date time difference
  1807. if((parseStart.scanedElement >=6) &&
  1808. (parseStop.scanedElement >=6))
  1809. {
  1810. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1811. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1812. tmStart.tm_year = parseStart.year - 1900;
  1813. tmStart.tm_mon = parseStart.month - 1;
  1814. tmStart.tm_mday = parseStart.mday;
  1815. tmStart.tm_hour = parseStart.hour;
  1816. tmStart.tm_min = parseStart.min;
  1817. tmStart.tm_sec = parseStart.sec;
  1818. tmStart.tm_gmtoff = 0;
  1819. tbStart.time = mktime(&tmStart);
  1820. tbStart.timezone = 0;
  1821. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1822. tmStop.tm_year = parseStop.year - 1900;
  1823. tmStop.tm_mon = parseStop.month - 1;
  1824. tmStop.tm_mday = parseStop.mday;
  1825. tmStop.tm_hour = parseStop.hour;
  1826. tmStop.tm_min = parseStop.min;
  1827. tmStop.tm_sec = parseStop.sec;
  1828. tmStop.tm_gmtoff = 0;
  1829. tbStop.time = mktime(&tmStop);
  1830. tbStop.timezone = 0;
  1831. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1832. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1833. //DEBUG_INFO("getStartStop(): %d\n", result);
  1834. }
  1835. else
  1836. {
  1837. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1838. }
  1839. return result;
  1840. }
  1841. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1842. {
  1843. FILE *fp;
  1844. char profileFileName[128];
  1845. char *line = NULL;
  1846. size_t len = 0;
  1847. time_t CurrentTime;
  1848. struct tm *tmComposite;
  1849. struct StructChargingProfile maxProfile;
  1850. struct StructChargingProfile compositeProfile;
  1851. uint8_t limitMax=0;
  1852. int compositePeriodIdx = 0;
  1853. //uint8_t isDurationNull = FALSE;
  1854. CurrentTime = time(NULL);
  1855. tmComposite=localtime(&CurrentTime);
  1856. 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);
  1857. if(isUnitA)
  1858. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1859. else
  1860. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1861. compositeProfile.ChargingSchedule.Duration = durationReq;
  1862. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1863. {
  1864. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1865. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1866. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1867. }
  1868. compositeProfile.ChargingProfileId = 0;
  1869. compositeProfile.StackLevel = 99 ;
  1870. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1871. maxProfile.ChargingProfileId = -1;
  1872. maxProfile.ChargingSchedule.Duration = -1;
  1873. system("rm -f /tmp/*.json");
  1874. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1875. // Search max profile
  1876. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1877. if((access(profileFileName, F_OK))!=-1)
  1878. {
  1879. fp = fopen(profileFileName, "r");
  1880. while(getline(&line, &len, fp) != -1)
  1881. {
  1882. json_object *obj = NULL;
  1883. obj = json_tokener_parse(line);
  1884. if(is_error(obj))
  1885. {
  1886. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1887. }
  1888. else
  1889. {
  1890. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1891. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1892. )
  1893. {
  1894. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1895. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1896. )
  1897. {
  1898. struct tm tmFrom, tmTo;
  1899. struct timeb tbFrom, tbTo;
  1900. 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) &&
  1901. (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))
  1902. {
  1903. tmFrom.tm_year -= 1900;
  1904. tmFrom.tm_mon -= 1;
  1905. tbFrom.time = mktime(&tmFrom);
  1906. tmTo.tm_year -= 1900;
  1907. tmTo.tm_mon -= 1;
  1908. tbTo.time = mktime(&tmTo);
  1909. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1910. {
  1911. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1912. {
  1913. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1914. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1915. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1916. }
  1917. if(maxProfile.ChargingProfileId == -1)
  1918. DEBUG_INFO("MaxProfile found.\n");
  1919. else
  1920. DEBUG_INFO("MaxProfile updated.\n");
  1921. // Required item
  1922. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1923. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1924. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1925. if(isUnitA)
  1926. {
  1927. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1928. 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++)
  1929. {
  1930. 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"));
  1931. 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?
  1932. 3:
  1933. 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")));
  1934. 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")));
  1935. }
  1936. }
  1937. else
  1938. {
  1939. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1940. 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++)
  1941. {
  1942. 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"));
  1943. 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?
  1944. 3:
  1945. 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")));
  1946. 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));
  1947. }
  1948. }
  1949. // Optional item
  1950. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1951. {
  1952. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1953. }
  1954. else
  1955. {
  1956. sprintf((char*)maxProfile.ValidFrom, " ");
  1957. }
  1958. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1959. {
  1960. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1961. }
  1962. else
  1963. {
  1964. sprintf((char*)maxProfile.ValidTo, " ");
  1965. }
  1966. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1967. {
  1968. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1969. }
  1970. else
  1971. {
  1972. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1973. }
  1974. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1975. {
  1976. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1977. }
  1978. else
  1979. {
  1980. maxProfile.TransactionId = -1;
  1981. }
  1982. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1983. {
  1984. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1985. }
  1986. else
  1987. {
  1988. maxProfile.ChargingSchedule.Duration = 86400;
  1989. //isDurationNull = TRUE;
  1990. }
  1991. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1992. {
  1993. 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")));
  1994. }
  1995. else
  1996. {
  1997. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1998. }
  1999. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2000. {
  2001. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2002. }
  2003. else
  2004. {
  2005. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2006. }
  2007. }
  2008. }
  2009. }
  2010. else
  2011. {
  2012. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2013. {
  2014. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2015. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2016. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2017. }
  2018. if(maxProfile.ChargingProfileId == -1)
  2019. DEBUG_INFO("MaxProfile found.\n");
  2020. else
  2021. DEBUG_INFO("MaxProfile updated.\n");
  2022. // Required item
  2023. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2024. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2025. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2026. if(isUnitA)
  2027. {
  2028. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2029. 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++)
  2030. {
  2031. 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"));
  2032. 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?
  2033. 3:
  2034. 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")));
  2035. 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")));
  2036. }
  2037. }
  2038. else
  2039. {
  2040. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2041. 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++)
  2042. {
  2043. 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"));
  2044. 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?
  2045. 3:
  2046. 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")));
  2047. 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));
  2048. }
  2049. }
  2050. // Optional item
  2051. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2052. {
  2053. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2054. }
  2055. else
  2056. {
  2057. sprintf((char*)maxProfile.ValidFrom, " ");
  2058. }
  2059. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2060. {
  2061. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2062. }
  2063. else
  2064. {
  2065. sprintf((char*)maxProfile.ValidTo, " ");
  2066. }
  2067. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2068. {
  2069. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2070. }
  2071. else
  2072. {
  2073. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2074. }
  2075. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2076. {
  2077. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2078. }
  2079. else
  2080. {
  2081. maxProfile.TransactionId = -1;
  2082. }
  2083. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2084. {
  2085. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2086. }
  2087. else
  2088. {
  2089. maxProfile.ChargingSchedule.Duration = 86400;
  2090. //isDurationNull = TRUE;
  2091. }
  2092. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2093. {
  2094. 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")));
  2095. }
  2096. else
  2097. {
  2098. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2099. }
  2100. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2101. {
  2102. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2103. }
  2104. else
  2105. {
  2106. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2107. }
  2108. }
  2109. }
  2110. }
  2111. json_object_put(obj);
  2112. }
  2113. fclose(fp);
  2114. /*
  2115. if(maxProfile.ChargingProfileId !=-1)
  2116. {
  2117. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2118. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2119. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2120. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2121. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2122. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2123. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2124. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2125. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2126. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2127. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2128. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2129. {
  2130. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2131. {
  2132. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2133. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2134. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2135. }
  2136. }
  2137. }
  2138. else
  2139. DEBUG_INFO("MaxProfile not found.\n");
  2140. DEBUG_INFO("------------------------------------\n");*/
  2141. }
  2142. if(maxProfile.ChargingProfileId != -1)
  2143. {
  2144. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2145. {
  2146. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2147. {
  2148. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2149. 0:
  2150. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2151. }
  2152. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2153. {
  2154. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2155. {
  2156. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2157. 0:
  2158. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2159. if(idxPeriod > 0)
  2160. {
  2161. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2162. {
  2163. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2164. }
  2165. }
  2166. }
  2167. }
  2168. }
  2169. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2170. {
  2171. if(maxProfile.ChargingSchedule.Duration != -1)
  2172. {
  2173. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2174. }
  2175. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2176. {
  2177. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2178. {
  2179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2180. if(idxPeriod > 0)
  2181. {
  2182. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2183. {
  2184. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2185. }
  2186. }
  2187. }
  2188. }
  2189. }
  2190. else
  2191. {
  2192. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2193. {
  2194. if(maxProfile.ChargingSchedule.Duration != -1)
  2195. {
  2196. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2197. 0:
  2198. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2199. }
  2200. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2201. {
  2202. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2203. {
  2204. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2205. 0:
  2206. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2207. if(idxPeriod > 0)
  2208. {
  2209. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2210. {
  2211. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2212. }
  2213. }
  2214. }
  2215. }
  2216. }
  2217. else
  2218. {
  2219. if(maxProfile.ChargingSchedule.Duration != -1)
  2220. {
  2221. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2222. 0:
  2223. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2224. }
  2225. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2226. {
  2227. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2228. {
  2229. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2230. 0:
  2231. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2232. if(idxPeriod > 0)
  2233. {
  2234. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2235. {
  2236. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2237. }
  2238. }
  2239. }
  2240. }
  2241. }
  2242. }
  2243. /*
  2244. DEBUG_INFO("MaxProfile after align.\n");
  2245. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2246. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2247. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2248. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2249. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2250. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2251. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2252. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2253. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2254. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2255. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2256. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2257. {
  2258. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2259. {
  2260. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2261. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2262. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2263. }
  2264. }
  2265. DEBUG_INFO("------------------------------------\n");*/
  2266. }
  2267. // Find each profile period quantity
  2268. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2269. {
  2270. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2271. limitMax = idx+1;
  2272. }
  2273. if(maxProfile.ChargingProfileId != -1)
  2274. {
  2275. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2276. {
  2277. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2278. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2279. (maxProfile.ChargingSchedule.Duration > 0))
  2280. {
  2281. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2282. {
  2283. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2284. compositePeriodIdx++;
  2285. }
  2286. else
  2287. {
  2288. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2289. }
  2290. }
  2291. }
  2292. }
  2293. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2294. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2295. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2296. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2297. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2298. {
  2299. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2300. {
  2301. compositeProfile.ChargingProfileId = 1;
  2302. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2303. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2304. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2305. }
  2306. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2307. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2308. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2309. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2310. }
  2311. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2312. if(line)
  2313. free(line);
  2314. }
  2315. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2316. {
  2317. FILE *fp;
  2318. char profileFileName[128];
  2319. char *line = NULL;
  2320. size_t len = 0;
  2321. time_t CurrentTime;
  2322. struct tm *tmComposite;
  2323. struct StructChargingProfile maxProfile;
  2324. struct StructChargingProfile defaultTxProfile;
  2325. struct StructChargingProfile txProfile;
  2326. struct StructChargingProfile compositeProfile;
  2327. struct StructChargingSchedulePeriod tmpPeriod;
  2328. uint8_t limitMax=0;
  2329. uint8_t limitDef=0;
  2330. uint8_t limitTx=0;
  2331. int compositePeriodIdx = 0;
  2332. CurrentTime = time(NULL);
  2333. tmComposite=localtime(&CurrentTime);
  2334. 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);
  2335. if(isUnitA)
  2336. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2337. else
  2338. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2339. compositeProfile.ChargingSchedule.Duration = durationReq;
  2340. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2341. {
  2342. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2343. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2344. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2345. }
  2346. compositeProfile.ChargingProfileId = 0;
  2347. compositeProfile.StackLevel = 99 ;
  2348. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2349. maxProfile.ChargingProfileId = -1;
  2350. defaultTxProfile.ChargingProfileId = -1;
  2351. txProfile.ChargingProfileId = -1;
  2352. maxProfile.ChargingSchedule.Duration = -1;
  2353. defaultTxProfile.ChargingSchedule.Duration = -1;
  2354. txProfile.ChargingSchedule.Duration = -1;
  2355. system("rm -f /tmp/*.json");
  2356. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2357. /*
  2358. * Search valid charging profile
  2359. */
  2360. //DEBUG_INFO("====================================\n");
  2361. // Search tx profile
  2362. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2363. if((access(profileFileName, F_OK))!=-1)
  2364. {
  2365. fp = fopen(profileFileName, "r");
  2366. while(getline(&line, &len, fp) != -1)
  2367. {
  2368. json_object *obj = NULL;
  2369. obj = json_tokener_parse(line);
  2370. if(is_error(obj))
  2371. {
  2372. DEBUG_ERROR("Parse txProfile from file error.\n");
  2373. }
  2374. else
  2375. {
  2376. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2377. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2378. )
  2379. {
  2380. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2381. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2382. )
  2383. {
  2384. struct tm tmFrom, tmTo;
  2385. struct timeb tbFrom, tbTo;
  2386. 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) &&
  2387. (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))
  2388. {
  2389. tmFrom.tm_year -= 1900;
  2390. tmFrom.tm_mon -= 1;
  2391. tbFrom.time = mktime(&tmFrom);
  2392. tmTo.tm_year -= 1900;
  2393. tmTo.tm_mon -= 1;
  2394. tbTo.time = mktime(&tmTo);
  2395. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2396. {
  2397. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2398. {
  2399. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2400. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2401. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2402. }
  2403. if(txProfile.ChargingProfileId == -1)
  2404. DEBUG_INFO("TxProfile found.\n");
  2405. else
  2406. DEBUG_INFO("TxProfile updated.\n");
  2407. // Required item
  2408. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2409. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2410. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2411. if(isUnitA)
  2412. {
  2413. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2414. 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++)
  2415. {
  2416. 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"));
  2417. 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?
  2418. 3:
  2419. 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")));
  2420. 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")));
  2421. }
  2422. }
  2423. else
  2424. {
  2425. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2426. 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++)
  2427. {
  2428. 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"));
  2429. 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?
  2430. 3:
  2431. 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")));
  2432. 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));
  2433. }
  2434. }
  2435. // Optional item
  2436. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2437. {
  2438. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2439. }
  2440. else
  2441. {
  2442. sprintf((char*)txProfile.ValidFrom, " ");
  2443. }
  2444. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2445. {
  2446. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2447. }
  2448. else
  2449. {
  2450. sprintf((char*)txProfile.ValidTo, " ");
  2451. }
  2452. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2453. {
  2454. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2455. }
  2456. else
  2457. {
  2458. sprintf((char*)txProfile.RecurrencyKind, " ");
  2459. }
  2460. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2461. {
  2462. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2463. }
  2464. else
  2465. {
  2466. txProfile.TransactionId = -1;
  2467. }
  2468. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2469. {
  2470. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2471. }
  2472. else
  2473. {
  2474. txProfile.ChargingSchedule.Duration = 86400;
  2475. }
  2476. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2477. {
  2478. 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")));
  2479. }
  2480. else
  2481. {
  2482. 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));
  2483. }
  2484. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2485. {
  2486. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2487. }
  2488. else
  2489. {
  2490. txProfile.ChargingSchedule.MinChargingRate = -1;
  2491. }
  2492. }
  2493. }
  2494. }
  2495. else
  2496. {
  2497. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2498. {
  2499. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2500. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2501. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2502. }
  2503. if(txProfile.ChargingProfileId == -1)
  2504. DEBUG_INFO("TxProfile found.\n");
  2505. else
  2506. DEBUG_INFO("TxProfile updated.\n");
  2507. // Required item
  2508. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2509. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2510. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2511. if(isUnitA)
  2512. {
  2513. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2514. 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++)
  2515. {
  2516. 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"));
  2517. 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?
  2518. 3:
  2519. 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")));
  2520. 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")));
  2521. }
  2522. }
  2523. else
  2524. {
  2525. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2526. 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++)
  2527. {
  2528. 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"));
  2529. 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?
  2530. 3:
  2531. 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")));
  2532. 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));
  2533. }
  2534. }
  2535. // Optional item
  2536. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2537. {
  2538. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2539. }
  2540. else
  2541. {
  2542. sprintf((char*)txProfile.ValidFrom, " ");
  2543. }
  2544. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2545. {
  2546. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2547. }
  2548. else
  2549. {
  2550. sprintf((char*)txProfile.ValidTo, " ");
  2551. }
  2552. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2553. {
  2554. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2555. }
  2556. else
  2557. {
  2558. sprintf((char*)txProfile.RecurrencyKind, " ");
  2559. }
  2560. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2561. {
  2562. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2563. }
  2564. else
  2565. {
  2566. txProfile.TransactionId = -1;
  2567. }
  2568. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2569. {
  2570. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2571. }
  2572. else
  2573. {
  2574. txProfile.ChargingSchedule.Duration = 86400;
  2575. }
  2576. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2577. {
  2578. 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")));
  2579. }
  2580. else
  2581. {
  2582. 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));
  2583. }
  2584. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2585. {
  2586. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2587. }
  2588. else
  2589. {
  2590. txProfile.ChargingSchedule.MinChargingRate = -1;
  2591. }
  2592. }
  2593. }
  2594. }
  2595. json_object_put(obj);
  2596. }
  2597. fclose(fp);
  2598. /*
  2599. if(txProfile.ChargingProfileId != -1)
  2600. {
  2601. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2602. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2603. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2604. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2605. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2606. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2607. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2608. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2609. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2610. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2611. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2612. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2613. {
  2614. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2615. {
  2616. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2617. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2618. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2619. }
  2620. }
  2621. }
  2622. else
  2623. DEBUG_INFO("TxProfile not found.\n");*/
  2624. }
  2625. // Search default tx profile
  2626. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2627. if((access(profileFileName, F_OK))==-1)
  2628. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2629. if((access(profileFileName, F_OK))!=-1)
  2630. {
  2631. fp = fopen(profileFileName, "r");
  2632. while(getline(&line, &len, fp) != -1)
  2633. {
  2634. json_object *obj = NULL;
  2635. obj = json_tokener_parse(line);
  2636. if(is_error(obj))
  2637. {
  2638. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2639. }
  2640. else
  2641. {
  2642. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2643. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2644. )
  2645. {
  2646. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2647. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2648. )
  2649. {
  2650. struct tm tmFrom, tmTo;
  2651. struct timeb tbFrom, tbTo;
  2652. 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) &&
  2653. (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))
  2654. {
  2655. tmFrom.tm_year -= 1900;
  2656. tmFrom.tm_mon -= 1;
  2657. tbFrom.time = mktime(&tmFrom);
  2658. tmTo.tm_year -= 1900;
  2659. tmTo.tm_mon -= 1;
  2660. tbTo.time = mktime(&tmTo);
  2661. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2662. {
  2663. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2664. {
  2665. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2666. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2667. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2668. }
  2669. if(defaultTxProfile.ChargingProfileId == -1)
  2670. DEBUG_INFO("TxDefaultProfile found.\n");
  2671. else
  2672. DEBUG_INFO("TxDefaultProfile updated.\n");
  2673. // Required item
  2674. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2675. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2676. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2677. if(isUnitA)
  2678. {
  2679. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2680. 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++)
  2681. {
  2682. 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"));
  2683. 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?
  2684. 3:
  2685. 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")));
  2686. 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")));
  2687. }
  2688. }
  2689. else
  2690. {
  2691. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2692. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2693. {
  2694. 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"));
  2695. 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?
  2696. 3:
  2697. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2698. 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));
  2699. }
  2700. }
  2701. // Optional item
  2702. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2703. {
  2704. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2705. }
  2706. else
  2707. {
  2708. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2709. }
  2710. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2711. {
  2712. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2713. }
  2714. else
  2715. {
  2716. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2717. }
  2718. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2719. {
  2720. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2721. }
  2722. else
  2723. {
  2724. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2725. }
  2726. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2727. {
  2728. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2729. }
  2730. else
  2731. {
  2732. defaultTxProfile.TransactionId = -1;
  2733. }
  2734. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2735. {
  2736. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2737. }
  2738. else
  2739. {
  2740. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2741. }
  2742. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2743. {
  2744. 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")));
  2745. }
  2746. else
  2747. {
  2748. 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));
  2749. }
  2750. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2751. {
  2752. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2753. }
  2754. else
  2755. {
  2756. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2757. }
  2758. }
  2759. }
  2760. }
  2761. else
  2762. {
  2763. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2764. {
  2765. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2766. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2767. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2768. }
  2769. if(defaultTxProfile.ChargingProfileId == -1)
  2770. DEBUG_INFO("TxDefaultProfile found.\n");
  2771. else
  2772. DEBUG_INFO("TxDefaultProfile updated.\n");
  2773. // Required item
  2774. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2775. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2776. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2777. if(isUnitA)
  2778. {
  2779. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2780. 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++)
  2781. {
  2782. 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"));
  2783. 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?
  2784. 3:
  2785. 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")));
  2786. 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")));
  2787. }
  2788. }
  2789. else
  2790. {
  2791. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2792. 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++)
  2793. {
  2794. 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"));
  2795. 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?
  2796. 3:
  2797. 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")));
  2798. 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));
  2799. }
  2800. }
  2801. // Optional item
  2802. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2803. {
  2804. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2805. }
  2806. else
  2807. {
  2808. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2809. }
  2810. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2811. {
  2812. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2813. }
  2814. else
  2815. {
  2816. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2817. }
  2818. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2819. {
  2820. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2821. }
  2822. else
  2823. {
  2824. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2825. }
  2826. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2827. {
  2828. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2829. }
  2830. else
  2831. {
  2832. defaultTxProfile.TransactionId = -1;
  2833. }
  2834. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2835. {
  2836. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2837. }
  2838. else
  2839. {
  2840. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2841. }
  2842. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2843. {
  2844. 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")));
  2845. }
  2846. else
  2847. {
  2848. 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));
  2849. }
  2850. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2851. {
  2852. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2853. }
  2854. else
  2855. {
  2856. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2857. }
  2858. }
  2859. }
  2860. }
  2861. json_object_put(obj);
  2862. }
  2863. fclose(fp);
  2864. /*
  2865. if(defaultTxProfile.ChargingProfileId != -1)
  2866. {
  2867. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2868. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2869. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2870. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2871. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2872. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2873. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2874. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2875. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2876. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2877. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2878. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2879. {
  2880. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2881. {
  2882. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2883. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2884. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2885. }
  2886. }
  2887. }
  2888. else
  2889. DEBUG_INFO("TxDefaultProfile not found.\n");
  2890. DEBUG_INFO("------------------------------------\n");*/
  2891. }
  2892. // Search max profile
  2893. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2894. if((access(profileFileName, F_OK))!=-1)
  2895. {
  2896. fp = fopen(profileFileName, "r");
  2897. while(getline(&line, &len, fp) != -1)
  2898. {
  2899. json_object *obj = NULL;
  2900. obj = json_tokener_parse(line);
  2901. if(is_error(obj))
  2902. {
  2903. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2904. }
  2905. else
  2906. {
  2907. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2908. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2909. )
  2910. {
  2911. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2912. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2913. )
  2914. {
  2915. struct tm tmFrom, tmTo;
  2916. struct timeb tbFrom, tbTo;
  2917. 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) &&
  2918. (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))
  2919. {
  2920. tmFrom.tm_year -= 1900;
  2921. tmFrom.tm_mon -= 1;
  2922. tbFrom.time = mktime(&tmFrom);
  2923. tmTo.tm_year -= 1900;
  2924. tmTo.tm_mon -= 1;
  2925. tbTo.time = mktime(&tmTo);
  2926. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2927. {
  2928. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2929. {
  2930. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2931. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2932. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2933. }
  2934. if(maxProfile.ChargingProfileId == -1)
  2935. DEBUG_INFO("MaxProfile found.\n");
  2936. else
  2937. DEBUG_INFO("MaxProfile updated.\n");
  2938. // Required item
  2939. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2940. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2941. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2942. if(isUnitA)
  2943. {
  2944. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2945. 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++)
  2946. {
  2947. 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"));
  2948. 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?
  2949. 3:
  2950. 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")));
  2951. 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")));
  2952. }
  2953. }
  2954. else
  2955. {
  2956. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2957. 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++)
  2958. {
  2959. 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"));
  2960. 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?
  2961. 3:
  2962. 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")));
  2963. 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));
  2964. }
  2965. }
  2966. // Optional item
  2967. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2968. {
  2969. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2970. }
  2971. else
  2972. {
  2973. sprintf((char*)maxProfile.ValidFrom, " ");
  2974. }
  2975. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2976. {
  2977. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2978. }
  2979. else
  2980. {
  2981. sprintf((char*)maxProfile.ValidTo, " ");
  2982. }
  2983. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2984. {
  2985. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2986. }
  2987. else
  2988. {
  2989. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2990. }
  2991. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2992. {
  2993. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2994. }
  2995. else
  2996. {
  2997. maxProfile.TransactionId = -1;
  2998. }
  2999. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3000. {
  3001. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3002. }
  3003. else
  3004. {
  3005. maxProfile.ChargingSchedule.Duration = 86400;
  3006. }
  3007. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3008. {
  3009. 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")));
  3010. }
  3011. else
  3012. {
  3013. 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));
  3014. }
  3015. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3016. {
  3017. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3018. }
  3019. else
  3020. {
  3021. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3022. }
  3023. }
  3024. }
  3025. }
  3026. else
  3027. {
  3028. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3029. {
  3030. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3031. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3032. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3033. }
  3034. if(maxProfile.ChargingProfileId == -1)
  3035. DEBUG_INFO("MaxProfile found.\n");
  3036. else
  3037. DEBUG_INFO("MaxProfile updated.\n");
  3038. // Required item
  3039. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3040. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3041. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3042. if(isUnitA)
  3043. {
  3044. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3045. 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++)
  3046. {
  3047. 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"));
  3048. 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?
  3049. 3:
  3050. 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")));
  3051. 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")));
  3052. }
  3053. }
  3054. else
  3055. {
  3056. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3057. 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++)
  3058. {
  3059. 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"));
  3060. 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?
  3061. 3:
  3062. 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")));
  3063. 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));
  3064. }
  3065. }
  3066. // Optional item
  3067. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3068. {
  3069. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3070. }
  3071. else
  3072. {
  3073. sprintf((char*)maxProfile.ValidFrom, " ");
  3074. }
  3075. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3076. {
  3077. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3078. }
  3079. else
  3080. {
  3081. sprintf((char*)maxProfile.ValidTo, " ");
  3082. }
  3083. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3084. {
  3085. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3086. }
  3087. else
  3088. {
  3089. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3090. }
  3091. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3092. {
  3093. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3094. }
  3095. else
  3096. {
  3097. maxProfile.TransactionId = -1;
  3098. }
  3099. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3100. {
  3101. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3102. }
  3103. else
  3104. {
  3105. maxProfile.ChargingSchedule.Duration = 86400;
  3106. }
  3107. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3108. {
  3109. 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")));
  3110. }
  3111. else
  3112. {
  3113. 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));
  3114. }
  3115. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3116. {
  3117. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3118. }
  3119. else
  3120. {
  3121. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3122. }
  3123. }
  3124. }
  3125. }
  3126. json_object_put(obj);
  3127. }
  3128. fclose(fp);
  3129. /*
  3130. if(maxProfile.ChargingProfileId !=-1)
  3131. {
  3132. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3133. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3134. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3135. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3136. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3137. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3138. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3139. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3140. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3141. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3142. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3143. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3144. {
  3145. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3146. {
  3147. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3148. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3149. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3150. }
  3151. }
  3152. }
  3153. else
  3154. DEBUG_INFO("MaxProfile not found.\n");
  3155. DEBUG_INFO("------------------------------------\n");*/
  3156. }
  3157. /*
  3158. * Align found profile start schedule & periods
  3159. */
  3160. //DEBUG_INFO("====================================\n");
  3161. /*
  3162. // For local test usage, force modify found profile start schedule info
  3163. 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);
  3164. 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);
  3165. 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);
  3166. */
  3167. if(txProfile.ChargingProfileId != -1)
  3168. {
  3169. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3170. {
  3171. if(txProfile.ChargingSchedule.Duration != -1)
  3172. {
  3173. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3174. 0:
  3175. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3176. }
  3177. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3178. {
  3179. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3180. {
  3181. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3182. 0:
  3183. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3184. if(idxPeriod > 0)
  3185. {
  3186. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3187. {
  3188. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3189. }
  3190. }
  3191. }
  3192. }
  3193. }
  3194. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3195. {
  3196. if(txProfile.ChargingSchedule.Duration != -1)
  3197. {
  3198. 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?
  3199. 0:
  3200. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3201. }
  3202. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3203. {
  3204. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3205. {
  3206. 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?
  3207. 0:
  3208. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3209. if(idxPeriod > 0)
  3210. {
  3211. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3212. {
  3213. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3214. }
  3215. }
  3216. }
  3217. }
  3218. }
  3219. else
  3220. {
  3221. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3222. {
  3223. if(txProfile.ChargingSchedule.Duration != -1)
  3224. {
  3225. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3226. 0:
  3227. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3228. }
  3229. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3230. {
  3231. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3232. {
  3233. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3234. 0:
  3235. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3236. if(idxPeriod > 0)
  3237. {
  3238. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3239. {
  3240. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3241. }
  3242. }
  3243. }
  3244. }
  3245. }
  3246. else
  3247. {
  3248. if(txProfile.ChargingSchedule.Duration != -1)
  3249. {
  3250. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3251. 0:
  3252. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3253. }
  3254. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3255. {
  3256. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3257. {
  3258. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3259. 0:
  3260. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3261. if(idxPeriod > 0)
  3262. {
  3263. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3264. {
  3265. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3266. }
  3267. }
  3268. }
  3269. }
  3270. }
  3271. }
  3272. /*
  3273. DEBUG_INFO("txProfile after align.\n");
  3274. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3275. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3276. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3277. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3278. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3279. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3280. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3281. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3282. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3283. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3284. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3285. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3286. {
  3287. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3288. {
  3289. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3290. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3291. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3292. }
  3293. }*/
  3294. }
  3295. if(defaultTxProfile.ChargingProfileId != -1)
  3296. {
  3297. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3298. {
  3299. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3300. {
  3301. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3302. 0:
  3303. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3304. }
  3305. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3306. {
  3307. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3308. {
  3309. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3310. 0:
  3311. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3312. if(idxPeriod > 0)
  3313. {
  3314. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3315. {
  3316. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3317. }
  3318. }
  3319. }
  3320. }
  3321. }
  3322. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3323. {
  3324. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3325. {
  3326. 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?
  3327. 0:
  3328. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3329. }
  3330. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3331. {
  3332. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3333. {
  3334. 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?
  3335. 0:
  3336. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3337. if(idxPeriod > 0)
  3338. {
  3339. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3340. {
  3341. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3342. }
  3343. }
  3344. }
  3345. }
  3346. }
  3347. else
  3348. {
  3349. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3350. {
  3351. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3352. {
  3353. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3354. 0:
  3355. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3356. }
  3357. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3358. {
  3359. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3360. {
  3361. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3362. 0:
  3363. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3364. if(idxPeriod > 0)
  3365. {
  3366. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3367. {
  3368. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3369. }
  3370. }
  3371. }
  3372. }
  3373. }
  3374. else
  3375. {
  3376. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3377. {
  3378. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3379. 0:
  3380. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3381. }
  3382. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3383. {
  3384. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3385. {
  3386. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3387. 0:
  3388. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3389. if(idxPeriod > 0)
  3390. {
  3391. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3392. {
  3393. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3394. }
  3395. }
  3396. }
  3397. }
  3398. }
  3399. }
  3400. /*
  3401. DEBUG_INFO("defaultTxProfile after align.\n");
  3402. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3403. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3404. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3405. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3406. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3407. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3408. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3409. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3410. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3411. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3412. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3413. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3414. {
  3415. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3416. {
  3417. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3418. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3419. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3420. }
  3421. }
  3422. DEBUG_INFO("------------------------------------\n");*/
  3423. }
  3424. if(maxProfile.ChargingProfileId != -1)
  3425. {
  3426. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3427. {
  3428. if(maxProfile.ChargingSchedule.Duration != -1)
  3429. {
  3430. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3431. 0:
  3432. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3433. }
  3434. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3435. {
  3436. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3437. {
  3438. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3439. 0:
  3440. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3441. if(idxPeriod > 0)
  3442. {
  3443. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3444. {
  3445. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3446. }
  3447. }
  3448. }
  3449. }
  3450. }
  3451. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3452. {
  3453. if(maxProfile.ChargingSchedule.Duration != -1)
  3454. {
  3455. 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?
  3456. 0:
  3457. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3458. }
  3459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3460. {
  3461. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3462. {
  3463. 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?
  3464. 0:
  3465. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3466. if(idxPeriod > 0)
  3467. {
  3468. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3469. {
  3470. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3471. }
  3472. }
  3473. }
  3474. }
  3475. }
  3476. else
  3477. {
  3478. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3479. {
  3480. if(maxProfile.ChargingSchedule.Duration != -1)
  3481. {
  3482. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3483. 0:
  3484. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3485. }
  3486. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3487. {
  3488. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3489. {
  3490. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3491. 0:
  3492. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3493. if(idxPeriod > 0)
  3494. {
  3495. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3496. {
  3497. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3498. }
  3499. }
  3500. }
  3501. }
  3502. }
  3503. else
  3504. {
  3505. if(maxProfile.ChargingSchedule.Duration != -1)
  3506. {
  3507. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3508. 0:
  3509. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3510. }
  3511. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3512. {
  3513. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3514. {
  3515. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3516. 0:
  3517. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3518. if(idxPeriod > 0)
  3519. {
  3520. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3521. {
  3522. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3523. }
  3524. }
  3525. }
  3526. }
  3527. }
  3528. }
  3529. /*
  3530. DEBUG_INFO("MaxProfile after align.\n");
  3531. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3532. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3533. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3534. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3535. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3536. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3537. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3538. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3539. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3540. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3541. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3542. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3543. {
  3544. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3545. {
  3546. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3547. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3548. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3549. }
  3550. }
  3551. DEBUG_INFO("------------------------------------\n");*/
  3552. }
  3553. /*
  3554. * Merge to conposite schedule
  3555. */
  3556. //DEBUG_INFO("====================================\n");
  3557. // Find each profile period quantity
  3558. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3559. {
  3560. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3561. limitMax = idx+1;
  3562. }
  3563. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3564. {
  3565. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3566. limitDef = idx+1;
  3567. }
  3568. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3569. {
  3570. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3571. limitTx = idx+1;
  3572. }
  3573. // TxProfile found, composite schedule based on it
  3574. if(txProfile.ChargingProfileId != -1)
  3575. {
  3576. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3577. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3578. {
  3579. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3580. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3581. (txProfile.ChargingSchedule.Duration > 0))
  3582. {
  3583. if(maxProfile.ChargingProfileId != -1)
  3584. {
  3585. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3586. {
  3587. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3588. {
  3589. if((maxProfile.ChargingSchedule.Duration > 0))
  3590. {
  3591. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3592. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3593. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3594. }
  3595. else
  3596. {
  3597. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3598. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3599. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3600. }
  3601. }
  3602. if(idxMaxPeriod == (limitMax-1))
  3603. {
  3604. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3605. {
  3606. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3607. {
  3608. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3609. compositePeriodIdx++;
  3610. }
  3611. else
  3612. {
  3613. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3614. }
  3615. }
  3616. }
  3617. }
  3618. }
  3619. else
  3620. {
  3621. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3622. {
  3623. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3624. compositePeriodIdx++;
  3625. }
  3626. else
  3627. {
  3628. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3629. }
  3630. }
  3631. }
  3632. if(idxTxPeriod == (limitTx-1))
  3633. {
  3634. if(defaultTxProfile.ChargingProfileId != -1)
  3635. {
  3636. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3637. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3638. {
  3639. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3640. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3641. (defaultTxProfile.ChargingSchedule.Duration>0))
  3642. {
  3643. if(maxProfile.ChargingProfileId != -1)
  3644. {
  3645. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3646. {
  3647. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3648. {
  3649. if((maxProfile.ChargingSchedule.Duration > 0))
  3650. {
  3651. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3652. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3653. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3654. }
  3655. else
  3656. {
  3657. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3658. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3659. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3660. }
  3661. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3662. {
  3663. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3664. {
  3665. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3666. compositePeriodIdx++;
  3667. }
  3668. else
  3669. {
  3670. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3671. }
  3672. }
  3673. // Delete duplicate period
  3674. if(compositePeriodIdx > 1)
  3675. {
  3676. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3677. {
  3678. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3679. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3680. compositePeriodIdx -= 1;
  3681. }
  3682. }
  3683. }
  3684. else
  3685. {
  3686. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3687. {
  3688. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3689. compositePeriodIdx++;
  3690. }
  3691. else
  3692. {
  3693. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3694. }
  3695. break;
  3696. }
  3697. }
  3698. }
  3699. else
  3700. {
  3701. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3702. {
  3703. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3704. compositePeriodIdx++;
  3705. }
  3706. else
  3707. {
  3708. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3709. }
  3710. }
  3711. }
  3712. }
  3713. }
  3714. }
  3715. }
  3716. }
  3717. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3718. else if(defaultTxProfile.ChargingProfileId != -1)
  3719. {
  3720. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3721. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3722. {
  3723. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3724. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3725. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3726. {
  3727. if(maxProfile.ChargingProfileId != -1)
  3728. {
  3729. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3730. {
  3731. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3732. {
  3733. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3734. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3735. if((maxProfile.ChargingSchedule.Duration > 0))
  3736. {
  3737. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3738. }
  3739. else
  3740. {
  3741. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3742. }
  3743. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3744. {
  3745. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3746. {
  3747. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3748. compositePeriodIdx++;
  3749. }
  3750. else
  3751. {
  3752. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3753. }
  3754. }
  3755. // Delete duplicate period
  3756. if(compositePeriodIdx > 1)
  3757. {
  3758. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3759. {
  3760. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3761. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3762. compositePeriodIdx -= 1;
  3763. }
  3764. }
  3765. }
  3766. else
  3767. {
  3768. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3769. {
  3770. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3771. compositePeriodIdx++;
  3772. }
  3773. else
  3774. {
  3775. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3776. }
  3777. break;
  3778. }
  3779. }
  3780. }
  3781. else
  3782. {
  3783. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3784. {
  3785. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3786. compositePeriodIdx++;
  3787. }
  3788. else
  3789. {
  3790. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3791. }
  3792. }
  3793. }
  3794. }
  3795. }
  3796. // Fill other period by MaxProfile
  3797. if(maxProfile.ChargingProfileId != -1)
  3798. {
  3799. if(compositePeriodIdx==0)
  3800. {
  3801. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3802. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3803. {
  3804. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3805. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3806. (maxProfile.ChargingSchedule.Duration > 0))
  3807. {
  3808. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3809. {
  3810. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3811. compositePeriodIdx++;
  3812. }
  3813. else
  3814. {
  3815. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3816. }
  3817. }
  3818. }
  3819. }
  3820. else
  3821. {
  3822. int lastCompositePeriodIdx = compositePeriodIdx;
  3823. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3824. {
  3825. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3826. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3827. (maxProfile.ChargingSchedule.Duration > 0))
  3828. {
  3829. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3830. {
  3831. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3832. {
  3833. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3834. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3835. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3836. }
  3837. else
  3838. {
  3839. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3840. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3841. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3842. }
  3843. }
  3844. if(tmpPeriod.Limit != -1)
  3845. {
  3846. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3847. {
  3848. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3849. {
  3850. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3851. compositePeriodIdx++;
  3852. }
  3853. else
  3854. {
  3855. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3856. }
  3857. }
  3858. // Delete duplicate period
  3859. if(compositePeriodIdx > 1)
  3860. {
  3861. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3862. {
  3863. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3864. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3865. compositePeriodIdx -= 1;
  3866. }
  3867. }
  3868. }
  3869. }
  3870. }
  3871. }
  3872. }
  3873. compositeProfile.ChargingSchedule.Duration = durationReq;
  3874. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3875. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3876. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3877. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3878. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3879. {
  3880. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3881. {
  3882. compositeProfile.ChargingProfileId = 1;
  3883. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3884. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3885. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3886. }
  3887. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3888. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3889. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3890. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3891. }
  3892. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3893. if(line)
  3894. free(line);
  3895. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3896. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3897. }
  3898. //==========================================
  3899. // Init all share memory
  3900. //==========================================
  3901. int InitShareMemory()
  3902. {
  3903. int result = PASS;
  3904. int MeterSMId;
  3905. //creat ShmSysConfigAndInfo
  3906. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3907. {
  3908. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3909. result = FAIL;
  3910. }
  3911. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3912. {
  3913. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3914. result = FAIL;
  3915. }
  3916. else
  3917. {}
  3918. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3919. {
  3920. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3921. result = FAIL;
  3922. }
  3923. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3924. {
  3925. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3926. result = FAIL;
  3927. }
  3928. else
  3929. {}
  3930. //creat ShmPsuData
  3931. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3932. {
  3933. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3934. result = FAIL;
  3935. }
  3936. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3937. {
  3938. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3939. result = FAIL;
  3940. }
  3941. else
  3942. {}
  3943. //creat ShmOCPP16Data
  3944. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3945. {
  3946. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3947. result = FAIL;
  3948. }
  3949. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3950. {
  3951. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3952. result = FAIL;
  3953. }
  3954. else
  3955. {}
  3956. /****************************** For Initial Settings************************************************/
  3957. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3958. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3959. // allocate Configuration memory address
  3960. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3961. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3962. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3963. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3964. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3965. //offline MeterValue Interval
  3966. TempMeterValueInterval = 0;
  3967. return result;
  3968. }
  3969. int ProcessShareMemory()
  3970. {
  3971. int result = PASS;
  3972. if(InitShareMemory() == FAIL)
  3973. {
  3974. DEBUG_ERROR("InitShareMemory NG\n");
  3975. if(ShmStatusCodeData!=NULL)
  3976. {
  3977. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3978. }
  3979. result = FAIL;
  3980. }
  3981. // Model name parsing
  3982. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3983. {
  3984. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3985. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3986. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3987. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3988. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3989. ) // 'D' means DC
  3990. {
  3991. // DO series
  3992. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3993. {
  3994. gunTotalNumber += 1;
  3995. gunType[gun_index] = GUN_TYPE_DO;
  3996. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3997. {
  3998. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3999. {
  4000. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4001. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4002. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4003. }
  4004. }
  4005. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4006. {
  4007. case Gun_Type_Chademo:
  4008. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4009. break;
  4010. case Gun_Type_CCS_2:
  4011. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4012. break;
  4013. case Gun_Type_GB:
  4014. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4015. break;
  4016. case Gun_Type_AC:
  4017. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4018. break;
  4019. default:
  4020. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4021. break;
  4022. }
  4023. }
  4024. }
  4025. else
  4026. {
  4027. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4028. {
  4029. gunTotalNumber += 1;
  4030. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4031. {
  4032. case Gun_Type_Chademo:
  4033. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4034. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4035. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4036. {
  4037. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4038. {
  4039. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4040. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4041. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4042. }
  4043. }
  4044. break;
  4045. case Gun_Type_CCS_2:
  4046. gunType[gun_index] = GUN_TYPE_CCS;
  4047. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4048. for (int index = 0; index < CCS_QUANTITY; index++)
  4049. {
  4050. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4051. {
  4052. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4053. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4054. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4055. }
  4056. }
  4057. break;
  4058. case Gun_Type_GB:
  4059. gunType[gun_index] = GUN_TYPE_GBT;
  4060. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4061. for (int index = 0; index < GB_QUANTITY; index++)
  4062. {
  4063. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4064. {
  4065. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4066. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4067. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4068. }
  4069. }
  4070. break;
  4071. case Gun_Type_AC:
  4072. gunType[gun_index] = GUN_TYPE_AC;
  4073. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4074. for (int index = 0; index < AC_QUANTITY; index++)
  4075. {
  4076. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4077. {
  4078. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4079. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4080. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4081. }
  4082. }
  4083. break;
  4084. default:
  4085. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4086. break;
  4087. }
  4088. }
  4089. }
  4090. }
  4091. else
  4092. {
  4093. DEBUG_ERROR("Model name parsing fail.\n");
  4094. result = FAIL;
  4095. }
  4096. if(result != PASS)sleep(5);
  4097. return result;
  4098. }
  4099. void checkRemoteStart(uint8_t connectorIdInt)
  4100. {
  4101. uint8_t tempIndex;
  4102. int result = PASS;
  4103. char cmdBuf[512];
  4104. //check Transaction active
  4105. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4106. {
  4107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4108. {
  4109. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4110. }
  4111. else
  4112. {
  4113. tempIndex = connectorIdInt -1;
  4114. }
  4115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4116. {
  4117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4118. {
  4119. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4120. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4121. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4122. {
  4123. //Reserved
  4124. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4125. }
  4126. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4127. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4128. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4129. {
  4130. //Reserved
  4131. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4132. result = FAIL;
  4133. goto end;
  4134. }
  4135. else
  4136. {
  4137. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4138. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4139. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4140. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4141. {
  4142. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4143. result = FAIL;
  4144. goto end;
  4145. }
  4146. }//END FOR ELSE
  4147. }
  4148. }// END FOR CHAdeMO_QUANTITY
  4149. }
  4150. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4151. {
  4152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4153. {
  4154. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4155. }
  4156. else
  4157. {
  4158. tempIndex = connectorIdInt -1;
  4159. }
  4160. for (int index = 0; index < CCS_QUANTITY; index++)
  4161. {
  4162. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4163. {
  4164. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4165. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4166. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4167. {
  4168. //Reserved
  4169. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4170. }
  4171. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4172. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4173. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4174. {
  4175. //Reserved
  4176. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4177. result = FAIL;
  4178. goto end;
  4179. }
  4180. else
  4181. {
  4182. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4183. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4184. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4185. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4186. {
  4187. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4188. result = FAIL;
  4189. goto end;
  4190. }
  4191. }// END FOR ELSE
  4192. }
  4193. }// END FOR CCS_QUANTITY
  4194. }
  4195. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4196. {
  4197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4198. {
  4199. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4200. }
  4201. else
  4202. {
  4203. tempIndex = connectorIdInt -1;
  4204. }
  4205. for (int index = 0; index < GB_QUANTITY; index++)
  4206. {
  4207. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4208. {
  4209. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4210. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4211. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4212. {
  4213. //Reserved
  4214. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4215. }
  4216. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4217. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4218. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4219. {
  4220. //Reserved
  4221. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4222. result = FAIL;
  4223. goto end;
  4224. }
  4225. else
  4226. {
  4227. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4228. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4229. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4230. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4231. {
  4232. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4233. result = FAIL;
  4234. goto end;
  4235. }
  4236. }// END FOR ELSE
  4237. }
  4238. } // END FOR GB_QUANTITY
  4239. }
  4240. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4241. {
  4242. tempIndex = connectorIdInt -1;
  4243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4244. {
  4245. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4246. {
  4247. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4248. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4249. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4250. {
  4251. //Reserved
  4252. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4253. }
  4254. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4255. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4256. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4257. {
  4258. //Reserved
  4259. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4260. result = FAIL;
  4261. goto end;
  4262. }
  4263. else
  4264. {
  4265. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4266. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4267. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4268. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4269. {
  4270. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4271. result = FAIL;
  4272. goto end;
  4273. }
  4274. }// END FOR ELSE
  4275. }
  4276. } // END FOR GB_QUANTITY
  4277. }
  4278. else
  4279. {
  4280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4281. {
  4282. tempIndex = 2;
  4283. }
  4284. else
  4285. {
  4286. tempIndex = connectorIdInt -1;
  4287. }
  4288. for (int index = 0; index < AC_QUANTITY; index++)
  4289. {
  4290. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4291. {
  4292. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4293. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4294. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4295. {
  4296. //Reserved
  4297. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4298. }
  4299. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4300. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4301. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4302. {
  4303. //Reserved
  4304. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4305. result = FAIL;
  4306. goto end;
  4307. }
  4308. else
  4309. {
  4310. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4311. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4312. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4313. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4314. {
  4315. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4316. result = FAIL;
  4317. goto end;
  4318. }
  4319. }//END FOR ELSE
  4320. }
  4321. }// END FOR AC_QUANTITY
  4322. }
  4323. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4324. {
  4325. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4326. {
  4327. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4328. {
  4329. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4330. system(cmdBuf);
  4331. }
  4332. }
  4333. else
  4334. {
  4335. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4336. result = FAIL;
  4337. }
  4338. }
  4339. end:
  4340. if(result == PASS)
  4341. {
  4342. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4343. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4344. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4345. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4346. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4347. }
  4348. }
  4349. void CheckSystemValue(void)
  4350. {
  4351. char filenmae[100]={0};
  4352. char str[100]={0};
  4353. int tempIndex = 0;
  4354. //===============================
  4355. // send Heartbeat
  4356. //===============================
  4357. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4358. {
  4359. //parameter for test
  4360. sendHeartbeatRequest(0);
  4361. //===========================
  4362. // Reset Waiting Time
  4363. //===========================
  4364. HeartBeatWithNOResponse += 1;
  4365. }
  4366. //===============================
  4367. // Credit deduct report
  4368. //===============================
  4369. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4370. {
  4371. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4372. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4373. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4374. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4375. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4376. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4377. }
  4378. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4379. {
  4380. OCPP_query_deduct_info();
  4381. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4382. }
  4383. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4384. {
  4385. // ClockAlign MeterValue
  4386. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4387. {
  4388. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4389. {
  4390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4391. {
  4392. tempIndex = ((gun_index==2) ? 1: 0);
  4393. }
  4394. else
  4395. {
  4396. tempIndex = gun_index;
  4397. }
  4398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4399. {
  4400. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4401. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4402. {
  4403. reqClockAlignMeter[gun_index] = 1;
  4404. }
  4405. }// End for CHAdeMO
  4406. }
  4407. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4408. {
  4409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4410. {
  4411. tempIndex = ((gun_index==2) ? 1: 0);
  4412. }
  4413. else
  4414. {
  4415. tempIndex = gun_index;
  4416. }
  4417. for (int index = 0; index < CCS_QUANTITY; index++)
  4418. {
  4419. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4420. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4421. {
  4422. reqClockAlignMeter[gun_index] = 1;
  4423. }
  4424. } // End for CCS
  4425. }
  4426. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4427. {
  4428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4429. {
  4430. tempIndex = ((gun_index==2) ? 1: 0);
  4431. }
  4432. else
  4433. {
  4434. tempIndex = gun_index;
  4435. }
  4436. for (int index = 0; index < GB_QUANTITY; index++)
  4437. {
  4438. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4439. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4440. {
  4441. reqClockAlignMeter[gun_index] = 1;
  4442. }
  4443. }// End for GB
  4444. }
  4445. else if(gunType[gun_index] == GUN_TYPE_DO)
  4446. {
  4447. tempIndex = gun_index;
  4448. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4449. {
  4450. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4451. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4452. {
  4453. reqClockAlignMeter[gun_index] = 1;
  4454. }
  4455. }
  4456. }
  4457. else
  4458. {
  4459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4460. {
  4461. tempIndex = 2;
  4462. }
  4463. else
  4464. {
  4465. tempIndex = gun_index;
  4466. }
  4467. for (int index = 0; index < AC_QUANTITY; index++)
  4468. {
  4469. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4470. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4471. {
  4472. reqClockAlignMeter[gun_index] = 1;
  4473. }
  4474. }//End for AC
  4475. }
  4476. }
  4477. }
  4478. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4479. {
  4480. //==========================================
  4481. // Check remote start without connector id
  4482. //==========================================
  4483. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4484. {
  4485. int connectorIdInt = -1;
  4486. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4487. {
  4488. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4489. {
  4490. connectorIdInt = (gun_index+1);
  4491. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4492. checkRemoteStart(connectorIdInt);
  4493. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4494. break;
  4495. }
  4496. }
  4497. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4498. {
  4499. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4500. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4501. }
  4502. }
  4503. //==========================================
  4504. // csu trigger DataTransferReq
  4505. //==========================================
  4506. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4507. {
  4508. sendDataTransferRequest(gun_index);
  4509. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4510. }
  4511. //==========================================
  4512. // CSU Trigger Authorize Request
  4513. //==========================================
  4514. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4515. {
  4516. sendAuthorizeRequest(0);
  4517. authorizeRetryTimes = authorizeRetryTimes + 1;
  4518. if(authorizeRetryTimes < 3)
  4519. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4520. }
  4521. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4522. {
  4523. authorizeRetryTimes = 0;
  4524. SetOcppConnStatus(FALSE);
  4525. server_sign = FALSE;
  4526. }
  4527. 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))
  4528. {
  4529. sendAuthorizeRequest(0);
  4530. }
  4531. //==========================================
  4532. // Charger start transaction
  4533. //==========================================
  4534. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4535. {
  4536. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4537. sendStartTransactionRequest(gun_index);
  4538. refreshStartTimer(&clientTime.StartTransaction);
  4539. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4540. storeTempStopTransaction(gun_index);
  4541. }
  4542. //==========================================
  4543. // Charger stop transaction
  4544. //==========================================
  4545. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4546. {
  4547. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4548. sendStopTransactionRequest(gun_index);
  4549. OCPP_updatePeriodEnergy(gun_index);
  4550. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4551. refreshStartTimer(&clientTime.StopTransaction);
  4552. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4553. }
  4554. //==========================================
  4555. // Charger OCMF message
  4556. //==========================================
  4557. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  4558. {
  4559. sendOcmfByDataTransferRequest(gun_index);
  4560. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  4561. }
  4562. //==========================================
  4563. // Charger status report
  4564. //==========================================
  4565. //--- Check Mode Change ---//
  4566. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4567. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4568. {
  4569. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4570. {
  4571. tempIndex = ((gun_index==2) ? 1: 0);
  4572. }
  4573. else
  4574. {
  4575. tempIndex = gun_index;
  4576. }
  4577. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4578. {
  4579. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4580. {
  4581. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4582. {
  4583. // Sent unplug message for California pricing logic
  4584. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4585. {
  4586. uint8_t ts[36];
  4587. getNowDatetime(ts);
  4588. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4589. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4590. if(strcmp((char*)dmsVersion, "2.0")==0)
  4591. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4592. else
  4593. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4594. sendUnplugByDataTransferRequest(gun_index);
  4595. interLock.isSentUnplug[gun_index] = 1;
  4596. }
  4597. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4598. {
  4599. interLock.isSentUnplug[gun_index] = 0;
  4600. }
  4601. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4602. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4603. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4604. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4605. {
  4606. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4607. if((access(filenmae,F_OK))!=-1)
  4608. {
  4609. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4610. sprintf(str,"rm -f %s",filenmae);
  4611. system(str);
  4612. }
  4613. }
  4614. }
  4615. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4616. #if 1 // for TempStopTransaction
  4617. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4618. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4619. {
  4620. checkTempStopTransaction(gun_index);
  4621. }
  4622. #endif
  4623. }
  4624. }
  4625. }
  4626. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4627. {
  4628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4629. {
  4630. tempIndex = ((gun_index==2) ? 1: 0);
  4631. }
  4632. else
  4633. {
  4634. tempIndex = gun_index;
  4635. }
  4636. for (int index = 0; index < CCS_QUANTITY; index++)
  4637. {
  4638. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4639. {
  4640. if((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]*/ )
  4641. {
  4642. // Sent unplug message for California pricing logic
  4643. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4644. {
  4645. uint8_t ts[36];
  4646. getNowDatetime(ts);
  4647. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4648. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4649. if(strcmp((char*)dmsVersion, "2.0")==0)
  4650. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4651. else
  4652. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4653. sendUnplugByDataTransferRequest(gun_index);
  4654. interLock.isSentUnplug[gun_index] = 1;
  4655. }
  4656. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4657. {
  4658. interLock.isSentUnplug[gun_index] = 0;
  4659. }
  4660. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4661. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4662. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4663. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4664. {
  4665. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4666. if((access(filenmae,F_OK))!=-1)
  4667. {
  4668. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4669. sprintf(str,"rm -f %s",filenmae);
  4670. system(str);
  4671. }
  4672. }
  4673. }
  4674. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4675. #if 1 // for TempStopTransaction
  4676. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4677. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4678. {
  4679. checkTempStopTransaction(gun_index);
  4680. }
  4681. #endif
  4682. }
  4683. }
  4684. }
  4685. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4686. {
  4687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4688. {
  4689. tempIndex = ((gun_index==2) ? 1: 0);
  4690. }
  4691. else
  4692. {
  4693. tempIndex = gun_index;
  4694. }
  4695. for (int index = 0; index < GB_QUANTITY; index++)
  4696. {
  4697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4698. {
  4699. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4700. {
  4701. // Sent unplug message for California pricing logic
  4702. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4703. {
  4704. uint8_t ts[36];
  4705. getNowDatetime(ts);
  4706. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4707. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4708. if(strcmp((char*)dmsVersion, "2.0")==0)
  4709. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4710. else
  4711. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4712. sendUnplugByDataTransferRequest(gun_index);
  4713. interLock.isSentUnplug[gun_index] = 1;
  4714. }
  4715. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4716. {
  4717. interLock.isSentUnplug[gun_index] = 0;
  4718. }
  4719. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4720. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4721. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4722. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4723. {
  4724. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4725. if((access(filenmae,F_OK))!=-1)
  4726. {
  4727. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4728. sprintf(str,"rm -f %s",filenmae);
  4729. system(str);
  4730. }
  4731. }
  4732. }
  4733. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4734. #if 1 // for TempStopTransaction
  4735. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4736. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4737. {
  4738. checkTempStopTransaction(gun_index);
  4739. }
  4740. #endif
  4741. }
  4742. }
  4743. }
  4744. else if(gunType[gun_index] == GUN_TYPE_DO)
  4745. {
  4746. tempIndex = gun_index;
  4747. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4748. {
  4749. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4750. {
  4751. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4752. {
  4753. // Sent unplug message for California pricing logic
  4754. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4755. {
  4756. uint8_t ts[36];
  4757. getNowDatetime(ts);
  4758. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4759. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4760. if(strcmp((char*)dmsVersion, "2.0")==0)
  4761. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4762. else
  4763. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4764. sendUnplugByDataTransferRequest(gun_index);
  4765. interLock.isSentUnplug[gun_index] = 1;
  4766. }
  4767. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4768. {
  4769. interLock.isSentUnplug[gun_index] = 0;
  4770. }
  4771. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4772. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4773. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4774. 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
  4775. {
  4776. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4777. if((access(filenmae,F_OK))!=-1)
  4778. {
  4779. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4780. sprintf(str,"rm -f %s",filenmae);
  4781. system(str);
  4782. }
  4783. }
  4784. }
  4785. 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);
  4786. #if 1 // for TempStopTransaction
  4787. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4788. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4789. {
  4790. checkTempStopTransaction(gun_index);
  4791. }
  4792. #endif
  4793. }
  4794. }
  4795. }
  4796. else
  4797. {
  4798. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4799. {
  4800. tempIndex = 2;
  4801. }
  4802. else
  4803. {
  4804. tempIndex = gun_index;
  4805. }
  4806. for (int index = 0; index < AC_QUANTITY; index++)
  4807. {
  4808. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4809. {
  4810. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4811. {
  4812. // Sent unplug message for California pricing logic
  4813. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4814. {
  4815. uint8_t ts[36];
  4816. getNowDatetime(ts);
  4817. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4818. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4819. if(strcmp((char*)dmsVersion, "2.0")==0)
  4820. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4821. else
  4822. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4823. sendUnplugByDataTransferRequest(gun_index);
  4824. interLock.isSentUnplug[gun_index] = 1;
  4825. }
  4826. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4827. {
  4828. interLock.isSentUnplug[gun_index] = 0;
  4829. }
  4830. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4831. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4832. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4833. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4834. {
  4835. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4836. if((access(filenmae,F_OK))!=-1)
  4837. {
  4838. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4839. sprintf(str,"rm -f %s",filenmae);
  4840. system(str);
  4841. }
  4842. }
  4843. }
  4844. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4845. #if 1 // for TempStopTransaction
  4846. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4847. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4848. {
  4849. checkTempStopTransaction(gun_index);
  4850. }
  4851. #endif
  4852. }
  4853. }// END
  4854. }
  4855. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  4856. (
  4857. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4858. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4859. )
  4860. )
  4861. {
  4862. sendStatusNotificationRequest(gun_index);
  4863. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4864. }
  4865. //==============================================
  4866. // TCCI reader status report
  4867. //==============================================
  4868. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4869. {
  4870. reportReaderStatus(gun_index);
  4871. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4872. }
  4873. //==============================================
  4874. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4875. //==============================================
  4876. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  4877. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData))))
  4878. {
  4879. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4880. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4881. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  4882. }
  4883. //==============================================
  4884. // Meter report
  4885. //==============================================
  4886. // Trigger MeterValue
  4887. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4888. {
  4889. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4890. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4891. }
  4892. // Clock-aligned Meter value
  4893. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4894. {
  4895. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4896. reqClockAlignMeter[gun_index] = 0;
  4897. }
  4898. // Sample period MeterValue
  4899. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4900. {
  4901. //check Transaction active
  4902. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4903. {
  4904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4905. {
  4906. tempIndex = ((gun_index==2) ? 1: 0);
  4907. }
  4908. else
  4909. {
  4910. tempIndex = gun_index;
  4911. }
  4912. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4913. {
  4914. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4915. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4916. {
  4917. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4918. {
  4919. reqSampleMeter[gun_index] = 1;
  4920. }
  4921. }
  4922. }// End for CHAdeMO
  4923. }
  4924. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4925. {
  4926. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4927. {
  4928. tempIndex = ((gun_index==2) ? 1: 0);
  4929. }
  4930. else
  4931. {
  4932. tempIndex = gun_index;
  4933. }
  4934. for (int index = 0; index < CCS_QUANTITY; index++)
  4935. {
  4936. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4937. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4938. {
  4939. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4940. {
  4941. reqSampleMeter[gun_index] = 1;
  4942. }
  4943. }
  4944. } // End for CCS
  4945. }
  4946. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4947. {
  4948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4949. {
  4950. tempIndex = ((gun_index==2) ? 1: 0);
  4951. }
  4952. else
  4953. {
  4954. tempIndex = gun_index;
  4955. }
  4956. for (int index = 0; index < GB_QUANTITY; index++)
  4957. {
  4958. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4959. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4960. {
  4961. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4962. {
  4963. reqSampleMeter[gun_index] = 1;
  4964. }
  4965. }
  4966. }// End for GB
  4967. }
  4968. else if(gunType[gun_index] == GUN_TYPE_DO)
  4969. {
  4970. tempIndex = gun_index;
  4971. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4972. {
  4973. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4974. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4975. {
  4976. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4977. {
  4978. reqSampleMeter[gun_index] = 1;
  4979. }
  4980. }
  4981. }
  4982. }
  4983. else
  4984. {
  4985. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4986. {
  4987. tempIndex = 2;
  4988. }
  4989. else
  4990. {
  4991. tempIndex = gun_index;
  4992. }
  4993. for (int index = 0; index < AC_QUANTITY; index++)
  4994. {
  4995. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4996. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4997. {
  4998. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4999. {
  5000. reqSampleMeter[gun_index] = 1;
  5001. }
  5002. }
  5003. }//End for AC
  5004. }
  5005. if(reqSampleMeter[gun_index] == 1)
  5006. {
  5007. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5008. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5009. storeTempStopTransaction(gun_index);
  5010. reqSampleMeter[gun_index] = 0;
  5011. }
  5012. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5013. }
  5014. //==============================================
  5015. // Check Connector reserved
  5016. //==============================================
  5017. //===============================
  5018. // Check if Reserve is expired
  5019. //===============================
  5020. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5021. {
  5022. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5023. {
  5024. DEBUG_INFO("reserve expired.\n");
  5025. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5026. }
  5027. }//END OF Check if Reserve is expired
  5028. //==========================================
  5029. // csu trigger FirmwareStatusNotificationReq
  5030. //==========================================
  5031. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5032. {
  5033. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5034. }
  5035. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5036. {
  5037. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5038. }
  5039. //==========================================
  5040. // csu trigger DiagnosticsStatusNotificationReq
  5041. //==========================================
  5042. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5043. {
  5044. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5045. }
  5046. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5047. {
  5048. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5049. }
  5050. //==========================================
  5051. // csu trigger CancelReservationConf
  5052. //==========================================
  5053. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5054. {
  5055. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5056. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5057. }
  5058. //==========================================
  5059. // csu trigger ChangeAvailabilityConf
  5060. //==========================================
  5061. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5062. {
  5063. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5064. }
  5065. //==========================================
  5066. // csu trigger UnlockConnectorConf
  5067. //==========================================
  5068. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5069. {
  5070. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5071. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5072. }
  5073. //==========================================
  5074. // csu trigger ReserveNowConf
  5075. //==========================================
  5076. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5077. {
  5078. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5079. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5080. }
  5081. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5082. {
  5083. sendSignCertificateRequest();
  5084. }
  5085. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5086. {
  5087. sendSecurityEventNotificationRequest();
  5088. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5089. }
  5090. // Support 15118
  5091. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5092. {
  5093. json_object *data = json_object_new_object();
  5094. // Read csr file content
  5095. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5096. FILE *fp=fopen(CSR_V2G,"r");
  5097. char *line = NULL;
  5098. size_t len = 0;
  5099. while(getline(&line, &len, fp) != -1)
  5100. {
  5101. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5102. {
  5103. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5104. }
  5105. }
  5106. fclose(fp);
  5107. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5108. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5109. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5110. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5111. json_object_put(data);
  5112. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5113. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5114. }
  5115. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5116. {
  5117. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5118. json_object *data = json_object_new_object();
  5119. json_object *idToken = json_object_new_object();
  5120. json_object *iso15118CertificateHashData = json_object_new_array();
  5121. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5122. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5123. strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5124. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5125. json_object_object_add(data, "idToken", idToken);
  5126. for(int idx=0; idx < 4; idx++)
  5127. {
  5128. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL) >= 7)
  5129. {
  5130. json_object *OCSPRequestDataType = json_object_new_object();
  5131. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5132. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5133. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5134. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5135. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5136. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5137. }
  5138. }
  5139. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5140. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5141. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5142. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5143. json_object_put(data);
  5144. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5145. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5146. }
  5147. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5148. {
  5149. json_object *data = json_object_new_object();
  5150. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5151. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5152. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5153. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5154. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5155. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5156. json_object_put(data);
  5157. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5158. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5159. }
  5160. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5161. {
  5162. json_object *data = json_object_new_object();
  5163. json_object *OCSPRequestDataType = json_object_new_object();
  5164. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5165. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5166. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5167. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5168. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5169. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5170. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5171. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5172. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5173. json_object_put(data);
  5174. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5175. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5176. }
  5177. }
  5178. }
  5179. //==========================================
  5180. // send request routine
  5181. //==========================================
  5182. int sendAuthorizeRequest(int gun_index)
  5183. {
  5184. mtrace();
  5185. int result = FAIL;
  5186. char message[100]={0};
  5187. char guid[37];
  5188. char tempdata[65]={0};
  5189. DEBUG_INFO("sendAuthorizeRequest...\n");
  5190. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5191. //Local Authorize
  5192. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5193. {
  5194. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5195. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5196. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5197. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5198. result = PASS;
  5199. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5200. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5201. authorizeRetryTimes = 0;
  5202. return result;
  5203. }
  5204. 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))||
  5205. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5206. {
  5207. // Query from cache
  5208. DEBUG_INFO("Authorize from cache.\n");
  5209. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5210. // Query from list
  5211. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5212. {
  5213. DEBUG_INFO("Authorize from list.\n");
  5214. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5215. }
  5216. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5217. {
  5218. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5219. {
  5220. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5221. }
  5222. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5223. {
  5224. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5225. }
  5226. if(!GetOcppConnStatus())
  5227. {
  5228. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5229. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5230. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5231. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5232. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5233. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5234. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5235. authorizeRetryTimes = 0;
  5236. return result;
  5237. }
  5238. }
  5239. else
  5240. {
  5241. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5242. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5243. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5244. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5245. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5246. else
  5247. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5248. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5249. result = PASS;
  5250. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5251. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5252. authorizeRetryTimes = 0;
  5253. return result;
  5254. }
  5255. }
  5256. //initialize struct Authorize
  5257. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5258. //get data from shared memory
  5259. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5260. random_uuid(guid);
  5261. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5262. LWS_Send(message);
  5263. sprintf(tempdata, "Authorize,%d", gun_index);
  5264. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5265. {
  5266. result = PASS;
  5267. DEBUG_INFO("Authorize mapItem pass\n");
  5268. }
  5269. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5270. return result;
  5271. }
  5272. int sendBootNotificationRequest(void)
  5273. {
  5274. mtrace();
  5275. int result = FAIL;
  5276. char message[500]={0}, payload[700]={0};
  5277. char guid[37]={0};
  5278. char tempdata[65]={0};
  5279. // Fill BootNotification fields
  5280. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5281. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5282. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5283. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5284. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5285. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5286. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5287. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5288. ShmOCPP16Data->ChargeBoxId
  5289. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5290. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5291. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5292. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5293. ,ShmOCPP16Data->BootNotification.CpIccid
  5294. ,ShmOCPP16Data->BootNotification.CpImsi);
  5295. random_uuid(guid);
  5296. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5297. LWS_Send(message);
  5298. sprintf(tempdata, "BootNotification,0");
  5299. 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*/)
  5300. {
  5301. result = PASS;
  5302. }
  5303. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5304. strcpy(queuedata,message);
  5305. return result;
  5306. }
  5307. int sendDataTransferRequest(int gun_index)
  5308. {
  5309. mtrace();
  5310. char message[10240]={0};
  5311. char guid[37]={0};
  5312. char tempdata[65]={0};
  5313. int result = FAIL;
  5314. json_object *DataTransfer = json_object_new_object();
  5315. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5316. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5317. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5318. random_uuid(guid);
  5319. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5320. guid,
  5321. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5322. json_object_put(DataTransfer);
  5323. LWS_Send(message);
  5324. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5325. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5326. {
  5327. result = PASS;
  5328. DEBUG_INFO("DataTransfer mapItem pass\n");
  5329. }
  5330. return result;
  5331. }
  5332. int sendUnplugByDataTransferRequest(int gun_index)
  5333. {
  5334. mtrace();
  5335. char message[10752]={0};
  5336. char guid[37]={0};
  5337. char tempdata[65]={0};
  5338. int result = FAIL;
  5339. random_uuid(guid);
  5340. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5341. (gun_index+1),
  5342. MESSAGE_TYPE_CALL,
  5343. guid,
  5344. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5345. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5346. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5347. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5348. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5349. {
  5350. result = PASS;
  5351. DEBUG_INFO("DataTransfer mapItem pass\n");
  5352. }
  5353. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5354. return result;
  5355. }
  5356. int sendOcmfByDataTransferRequest(int gun_index)
  5357. {
  5358. mtrace();
  5359. json_object *DataTransfer = json_object_new_object();
  5360. json_object *data = json_object_new_object();
  5361. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5362. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5363. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5364. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5365. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5366. json_object_object_add(DataTransfer, "data", data);
  5367. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5368. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5369. char message[3000]={0};
  5370. char guid[37]={0};
  5371. char tempdata[65]={0};
  5372. int result = FAIL;
  5373. random_uuid(guid);
  5374. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5375. (gun_index+1),
  5376. MESSAGE_TYPE_CALL,
  5377. guid,
  5378. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5379. json_object_put(DataTransfer);
  5380. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5381. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5382. {
  5383. result = PASS;
  5384. DEBUG_INFO("DataTransfer mapItem pass\n");
  5385. }
  5386. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5387. return result;
  5388. }
  5389. int sendDiagnosticsStatusNotificationRequest(char *status)
  5390. {
  5391. mtrace();
  5392. int result = FAIL;
  5393. char message[110]={0};
  5394. char guid[37]={0};
  5395. char tempdata[65]={0};
  5396. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5397. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5398. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5399. random_uuid(guid);
  5400. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5401. LWS_SendNow(message);
  5402. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5403. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5404. {
  5405. result = PASS;
  5406. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5407. }
  5408. //#ifdef SystemLogMessage
  5409. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5410. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5411. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5412. //#endif
  5413. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5414. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5415. //record status
  5416. if(strcmp(status,"Idle")==0)
  5417. {
  5418. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5419. }
  5420. else if(strcmp(status,"Uploaded")==0)
  5421. {
  5422. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5423. }
  5424. else if(strcmp(status,"UploadFailed")==0)
  5425. {
  5426. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5427. }
  5428. else if(strcmp(status,"Uploading")==0)
  5429. {
  5430. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5431. }
  5432. return result;
  5433. }
  5434. int sendFirmwareStatusNotificationRequest(char *status)
  5435. {
  5436. mtrace();
  5437. int result = FAIL;
  5438. char message[110]={0};
  5439. char guid[37]={0};
  5440. char tempdata[65]={0};
  5441. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5442. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5443. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5444. random_uuid(guid);
  5445. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5446. LWS_SendNow(message);
  5447. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5448. 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*/)
  5449. {
  5450. result = PASS;
  5451. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5452. }
  5453. //#ifdef SystemLogMessage
  5454. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5455. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5456. //#endif
  5457. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5458. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5459. //record status
  5460. if(strcmp(status,"Downloaded")==0)
  5461. {
  5462. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5463. }
  5464. else if(strcmp(status,"DownloadFailed")==0)
  5465. {
  5466. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5467. }
  5468. else if(strcmp(status,"Downloading")==0)
  5469. {
  5470. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5471. }
  5472. else if(strcmp(status,"Idle")==0)
  5473. {
  5474. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5475. }
  5476. else if(strcmp(status,"InstallationFailed")==0)
  5477. {
  5478. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5479. }
  5480. else if(strcmp(status,"Installing")==0)
  5481. {
  5482. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5483. }
  5484. else if(strcmp(status,"Installed")==0)
  5485. {
  5486. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5487. }
  5488. return result;
  5489. }
  5490. int sendHeartbeatRequest(int gun_index)
  5491. {
  5492. mtrace();
  5493. int result = FAIL;
  5494. char message[80]={0};
  5495. char guid[37]={0};
  5496. char tempdata[65]={0};
  5497. random_uuid(guid);
  5498. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5499. , MESSAGE_TYPE_CALL
  5500. , guid );
  5501. LWS_Send(message);
  5502. sprintf(tempdata, "Heartbeat,%d", 0);
  5503. 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*/)
  5504. {
  5505. result = PASS;
  5506. }
  5507. return result;
  5508. }
  5509. int sendStartTransactionRequest(int gun_index)
  5510. {
  5511. mtrace();
  5512. int result = FAIL;
  5513. char message[250]={0};
  5514. char guid[37]={0};
  5515. struct timeval tmnow;
  5516. struct tm *tm;
  5517. char buf[28];//, usec_buf[6];
  5518. char tempdata[65]={0};
  5519. int tempIndex = 0;
  5520. DEBUG_INFO("sendStartTransactionRequest...\n");
  5521. gettimeofday(&tmnow, NULL);
  5522. time_t t;
  5523. t = time(NULL);
  5524. /*UTC time and date*/
  5525. tm = gmtime(&t);
  5526. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5527. #if 0 // remove temporally
  5528. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5529. strcat(buf,".");
  5530. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5531. strcat(buf,usec_buf);
  5532. #endif
  5533. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5534. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5535. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5536. // clear StartTransaction Response
  5537. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5538. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5539. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5540. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5541. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5542. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5543. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5544. {
  5545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5546. {
  5547. tempIndex = ((gun_index==2) ? 1: 0);
  5548. }
  5549. else
  5550. {
  5551. tempIndex = gun_index;
  5552. }
  5553. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5554. {
  5555. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5556. {
  5557. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5558. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5559. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5560. }
  5561. }
  5562. }
  5563. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5564. {
  5565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5566. {
  5567. tempIndex = ((gun_index==2) ? 1: 0);
  5568. }
  5569. else
  5570. {
  5571. tempIndex = gun_index;
  5572. }
  5573. for (int index = 0; index < CCS_QUANTITY; index++)
  5574. {
  5575. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5576. {
  5577. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5578. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5579. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5580. }
  5581. }
  5582. }
  5583. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5584. {
  5585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5586. {
  5587. tempIndex = ((gun_index==2) ? 1: 0);
  5588. }
  5589. else
  5590. {
  5591. tempIndex = gun_index;
  5592. }
  5593. for (int index = 0; index < GB_QUANTITY; index++)
  5594. {
  5595. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5596. {
  5597. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5598. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5599. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5600. }
  5601. }
  5602. }
  5603. else if(gunType[gun_index] == GUN_TYPE_DO)
  5604. {
  5605. tempIndex = gun_index;
  5606. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5607. {
  5608. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5609. {
  5610. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5611. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5612. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5613. }
  5614. }
  5615. }
  5616. else
  5617. {
  5618. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5619. {
  5620. tempIndex = 2;
  5621. }
  5622. else
  5623. {
  5624. tempIndex = gun_index;
  5625. }
  5626. for (int index = 0; index < AC_QUANTITY; index++)
  5627. {
  5628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5629. {
  5630. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5631. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5632. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5633. }
  5634. }
  5635. }
  5636. random_uuid(guid);
  5637. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5638. {
  5639. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5640. , gun_index +1
  5641. , MESSAGE_TYPE_CALL
  5642. , guid
  5643. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5644. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5645. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5646. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5647. }
  5648. else
  5649. {
  5650. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5651. , gun_index +1
  5652. , MESSAGE_TYPE_CALL
  5653. , guid
  5654. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5655. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5656. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5657. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5658. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5659. }
  5660. #if 1
  5661. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5662. 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*/)
  5663. {
  5664. result = PASS;
  5665. }
  5666. #endif
  5667. strcpy(queuedata, message);
  5668. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5669. OCPP_insert_transaction_msg(YES, queuedata);
  5670. return result;
  5671. }
  5672. int sendStatusNotificationRequest(int gun_index)
  5673. {
  5674. mtrace();
  5675. int result = FAIL;
  5676. char message[600]={0};
  5677. char guid[37];
  5678. int currentStatus = 0;
  5679. struct timeval tmnow;
  5680. struct tm *tm;
  5681. char buf[28];//, usec_buf[6];
  5682. char tempdata[65]={0};
  5683. int tempIndex = 0;
  5684. uint8_t isStateChanged = TRUE;
  5685. uint8_t isContentIllegal = TRUE;
  5686. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5687. gettimeofday(&tmnow, NULL);
  5688. time_t t;
  5689. t = time(NULL);
  5690. /*UTC time and date*/
  5691. tm = gmtime(&t);
  5692. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5693. #if 0 // remove temporally
  5694. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5695. strcat(buf,".");
  5696. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5697. strcat(buf,usec_buf);
  5698. #endif
  5699. //printf("%s",buf);
  5700. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5701. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5702. // it's option
  5703. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5704. /*
  5705. enum _SYSTEM_STATUS
  5706. {
  5707. S_BOOTING = 0,
  5708. S_IDLE, = 1
  5709. S_AUTHORIZING, =2
  5710. S_REASSIGN_CHECK, =3
  5711. S_REASSIGN, =4
  5712. S_PRECHARGE, =5
  5713. S_PREPARING_FOR_EV, =6
  5714. S_PREPARING_FOR_EVSE, =7
  5715. S_CHARGING, =8
  5716. S_TERMINATING, =9
  5717. S_COMPLETE, =10
  5718. S_ALARM, =11
  5719. S_FAULT =12
  5720. }
  5721. */
  5722. //check Transaction active
  5723. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5724. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5725. {
  5726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5727. {
  5728. tempIndex = ((gun_index==2) ? 1: 0);
  5729. }
  5730. else
  5731. {
  5732. tempIndex = gun_index;
  5733. }
  5734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5735. {
  5736. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5737. {
  5738. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5739. {
  5740. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5741. {
  5742. currentStatus = Preparing; //OCPP Status: Preparing
  5743. }
  5744. else
  5745. {
  5746. currentStatus = Available; //OCPP Status: Available
  5747. }
  5748. }
  5749. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5750. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5751. ) //S_PRECHARGE
  5752. {
  5753. currentStatus = Preparing; //OCPP Status: Preparing
  5754. }
  5755. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5756. {
  5757. currentStatus = Charging; //OCPP Status: Charging
  5758. }
  5759. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5760. {
  5761. currentStatus = Finishing; //OCPP Status: Finishing
  5762. }
  5763. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5764. {
  5765. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5766. }
  5767. 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
  5768. {
  5769. currentStatus = Unavailable; //OCPP Status: Unavailable
  5770. }
  5771. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5772. {
  5773. currentStatus = Faulted; //OCPP Status: Faulted
  5774. }
  5775. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5776. {
  5777. currentStatus = Reserved; //OCPP Status: Reserved
  5778. }
  5779. } //end of the same index
  5780. }//end of for CHAdeMO_QUANTITY
  5781. }
  5782. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5783. {
  5784. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5785. {
  5786. tempIndex = ((gun_index==2) ? 1: 0);
  5787. }
  5788. else
  5789. {
  5790. tempIndex = gun_index;
  5791. }
  5792. for (int index = 0; index < CCS_QUANTITY; index++)
  5793. {
  5794. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5795. {
  5796. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5797. {
  5798. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5799. {
  5800. currentStatus = Preparing; //OCPP Status: Preparing
  5801. }
  5802. else
  5803. {
  5804. currentStatus = Available; //OCPP Status: Available
  5805. }
  5806. }
  5807. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5808. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5809. ) //S_PRECHARGE
  5810. {
  5811. currentStatus = Preparing; //OCPP Status: Preparing
  5812. }
  5813. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5814. {
  5815. currentStatus = Charging; //OCPP Status: Charging
  5816. }
  5817. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5818. {
  5819. currentStatus = Finishing; //OCPP Status: Finishing
  5820. }
  5821. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5822. {
  5823. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5824. }
  5825. 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
  5826. {
  5827. currentStatus = Unavailable; //OCPP Status : Unavailable
  5828. }
  5829. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5830. {
  5831. currentStatus = Faulted; //OCPP Status: Faulted
  5832. }
  5833. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5834. {
  5835. currentStatus = Reserved; //OCPP Status: Reserved
  5836. }
  5837. } //end of the same index
  5838. } // end of for CCS_QUANTITY
  5839. }
  5840. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5841. {
  5842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5843. {
  5844. tempIndex = ((gun_index==2) ? 1: 0);
  5845. }
  5846. else
  5847. {
  5848. tempIndex = gun_index;
  5849. }
  5850. for (int index = 0; index < GB_QUANTITY; index++)
  5851. {
  5852. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5853. {
  5854. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5855. {
  5856. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5857. {
  5858. currentStatus = Preparing; //OCPP Status: Preparing
  5859. }
  5860. else
  5861. {
  5862. currentStatus = Available; //OCPP Status: Available
  5863. }
  5864. }
  5865. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5866. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5867. ) //S_PRECHARGE
  5868. {
  5869. currentStatus = Preparing; //OCPP Status: Preparing
  5870. }
  5871. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5872. {
  5873. currentStatus = Charging; //OCPP Status: Charging
  5874. }
  5875. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5876. {
  5877. currentStatus = Finishing; //OCPP Status: Finishing
  5878. }
  5879. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5880. {
  5881. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5882. }
  5883. 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
  5884. {
  5885. currentStatus = Unavailable; //OCPP Status: Unavailable
  5886. }
  5887. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5888. {
  5889. currentStatus = Faulted; //OCPP Status: Faulted
  5890. }
  5891. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5892. {
  5893. currentStatus = Reserved; //OCPP Status: Reserved
  5894. }
  5895. } //end of the same index
  5896. } // end of for GB_QUANTITY
  5897. }
  5898. else if(gunType[gun_index] == GUN_TYPE_DO)
  5899. {
  5900. tempIndex = gun_index;
  5901. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5902. {
  5903. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5904. {
  5905. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5906. {
  5907. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5908. {
  5909. currentStatus = Preparing; //OCPP Status: Preparing
  5910. }
  5911. else
  5912. {
  5913. currentStatus = Available; //OCPP Status: Available
  5914. }
  5915. }
  5916. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5917. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5918. ) //S_PRECHARGE
  5919. {
  5920. currentStatus = Preparing; //OCPP Status: Preparing
  5921. }
  5922. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5923. {
  5924. currentStatus = Charging; //OCPP Status: Charging
  5925. }
  5926. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5927. {
  5928. currentStatus = Finishing; //OCPP Status: Finishing
  5929. }
  5930. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5931. {
  5932. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5933. }
  5934. 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
  5935. {
  5936. currentStatus = Unavailable; //OCPP Status: Unavailable
  5937. }
  5938. 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
  5939. {
  5940. currentStatus = Faulted; //OCPP Status: Faulted
  5941. }
  5942. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5943. {
  5944. currentStatus = Reserved; //OCPP Status: Reserved
  5945. }
  5946. } //end of the same index
  5947. }
  5948. }
  5949. else
  5950. {
  5951. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5952. {
  5953. tempIndex = 2;
  5954. }
  5955. else
  5956. {
  5957. tempIndex = gun_index;
  5958. }
  5959. for (int index = 0; index < AC_QUANTITY; index++)
  5960. {
  5961. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5962. {
  5963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5964. {
  5965. 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))
  5966. {
  5967. currentStatus = Preparing; //OCPP Status: Preparing
  5968. }
  5969. else
  5970. {
  5971. currentStatus = Available; //OCPP Status: Available
  5972. }
  5973. }
  5974. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5975. {
  5976. currentStatus = Preparing; //OCPP Status: Preparing
  5977. }
  5978. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5979. {
  5980. currentStatus = Charging; //OCPP Status: Charging
  5981. }
  5982. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5983. {
  5984. currentStatus = Finishing; //OCPP Status: Finishing
  5985. }
  5986. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5987. {
  5988. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5989. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5990. else
  5991. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5992. }
  5993. 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
  5994. {
  5995. currentStatus = Unavailable; //OCPP Status: Unavailable
  5996. }
  5997. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5998. {
  5999. currentStatus = Faulted; //OCPP Status: Faulted
  6000. }
  6001. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6002. {
  6003. currentStatus = Reserved; //OCPP Status: Reserved
  6004. }
  6005. }//end of the same index
  6006. }//end of for AC_QUANTITY
  6007. }
  6008. //it's option
  6009. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6010. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6011. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6012. {
  6013. isStateChanged = FALSE;
  6014. }
  6015. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6016. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6017. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6018. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6019. isContentIllegal = TRUE;
  6020. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6021. {
  6022. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6023. {
  6024. isContentIllegal = FALSE;
  6025. break;
  6026. }
  6027. }
  6028. if(isContentIllegal)
  6029. {
  6030. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6031. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6032. }
  6033. random_uuid(guid);
  6034. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6035. , MESSAGE_TYPE_CALL
  6036. , guid
  6037. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6038. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6039. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6040. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6041. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6042. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6043. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6044. if((server_sign == TRUE) && isStateChanged)
  6045. {
  6046. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6047. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6048. LWS_Send(message);
  6049. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6050. 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*/)
  6051. {
  6052. //DEBUG_ERROR("statusNotification mapitem pass");
  6053. result = PASS;
  6054. }
  6055. }
  6056. else
  6057. {
  6058. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6059. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6060. result = PASS;
  6061. }
  6062. return result;
  6063. }
  6064. int sendStopTransactionRequest(int gun_index)
  6065. {
  6066. mtrace();
  6067. int result = FAIL;
  6068. //char message[1500]={0};
  6069. char guid[37]={0};
  6070. char tempdata[65]={0};
  6071. int tempIndex = 0;
  6072. char TempStopTransaction[256];
  6073. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6074. //int idx_sample=0;
  6075. DEBUG_INFO("sendStopTransactionRequest \n");
  6076. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6077. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6078. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6079. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6080. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6081. {
  6082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6083. {
  6084. tempIndex = ((gun_index==2) ? 1: 0);
  6085. }
  6086. else
  6087. {
  6088. tempIndex = gun_index;
  6089. }
  6090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6093. {
  6094. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6095. }
  6096. }// END OF CHAdeMO_QUANTITY
  6097. }
  6098. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6099. {
  6100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6101. {
  6102. tempIndex = ((gun_index==2) ? 1: 0);
  6103. }
  6104. else
  6105. {
  6106. tempIndex = gun_index;
  6107. }
  6108. for (int index = 0; index < CCS_QUANTITY; index++)
  6109. {
  6110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6111. {
  6112. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6113. }
  6114. }// END OF CCS_QUANTITY
  6115. }
  6116. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6117. {
  6118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6119. {
  6120. tempIndex = ((gun_index==2) ? 1: 0);
  6121. }
  6122. else
  6123. {
  6124. tempIndex = gun_index;
  6125. }
  6126. for (int index = 0; index < GB_QUANTITY; index++)
  6127. {
  6128. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6129. {
  6130. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6131. }
  6132. }// END OF GB_QUANTITY
  6133. }
  6134. else if(gunType[gun_index] == GUN_TYPE_DO)
  6135. {
  6136. tempIndex = gun_index;
  6137. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6138. {
  6139. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6140. {
  6141. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6142. }
  6143. }// END OF GB_QUANTITY
  6144. }
  6145. else
  6146. {
  6147. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6148. {
  6149. tempIndex = 2;
  6150. }
  6151. else
  6152. {
  6153. tempIndex = gun_index;
  6154. }
  6155. for (int index = 0; index < AC_QUANTITY; index++)
  6156. {
  6157. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6158. {
  6159. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6160. }
  6161. }// END OF AC_QUANTITY
  6162. }
  6163. //====================================== Stop Transaction Time =====================================================
  6164. struct timeval tmnow;
  6165. struct tm *tm;
  6166. char buf[28];//, usec_buf[6];
  6167. gettimeofday(&tmnow, NULL);
  6168. time_t t;
  6169. t = time(NULL);
  6170. /*UTC time and date*/
  6171. tm = gmtime(&t);
  6172. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  6174. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6175. random_uuid(guid);
  6176. /***********************************transactionData******************************************************/
  6177. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  6178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  6179. //=================================
  6180. // Transaction_Begin
  6181. //=================================
  6182. //=================================
  6183. // Transaction_End
  6184. //=================================
  6185. // ================================= Current.Import L1 ===============================================
  6186. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6187. {
  6188. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6189. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6190. {
  6191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6192. {
  6193. tempIndex = ((gun_index==2) ? 1: 0);
  6194. }
  6195. else
  6196. {
  6197. tempIndex = gun_index;
  6198. }
  6199. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6200. {
  6201. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6202. {
  6203. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6204. }
  6205. }// End of for CHAdeMO_QUANTITY
  6206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6207. }
  6208. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6209. {
  6210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6211. {
  6212. tempIndex = ((gun_index==2) ? 1: 0);
  6213. }
  6214. else
  6215. {
  6216. tempIndex = gun_index;
  6217. }
  6218. for (int index = 0; index < CCS_QUANTITY; index++)
  6219. {
  6220. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6221. {
  6222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6223. }
  6224. }// End of for CCS_QUANTITY
  6225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6226. }
  6227. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6228. {
  6229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6230. {
  6231. tempIndex = ((gun_index==2) ? 1: 0);
  6232. }
  6233. else
  6234. {
  6235. tempIndex = gun_index;
  6236. }
  6237. for (int index = 0; index < GB_QUANTITY; index++)
  6238. {
  6239. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6240. {
  6241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6242. }
  6243. }// End of for GB_QUANTITY
  6244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6245. }
  6246. else if(gunType[gun_index] == GUN_TYPE_DO)
  6247. {
  6248. tempIndex = gun_index;
  6249. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6250. {
  6251. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6252. {
  6253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6254. }
  6255. }
  6256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6257. }
  6258. else
  6259. {
  6260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6261. {
  6262. tempIndex = 2;
  6263. }
  6264. else
  6265. {
  6266. tempIndex = gun_index;
  6267. }
  6268. for (int index = 0; index < AC_QUANTITY; index++)
  6269. {
  6270. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6271. {
  6272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6273. }
  6274. }// End of for AC_QUANTITY
  6275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6276. }
  6277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6282. }
  6283. // ================================= Energy.Active.Import.Interval ==============================================
  6284. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6285. {
  6286. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6287. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6288. {
  6289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6290. {
  6291. tempIndex = ((gun_index==2) ? 1: 0);
  6292. }
  6293. else
  6294. {
  6295. tempIndex = gun_index;
  6296. }
  6297. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6298. {
  6299. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6300. {
  6301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6302. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6303. }
  6304. }// END OF CHAdeMO_QUANTITY
  6305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6306. }
  6307. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6308. {
  6309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6310. {
  6311. tempIndex = ((gun_index==2) ? 1: 0);
  6312. }
  6313. else
  6314. {
  6315. tempIndex = gun_index;
  6316. }
  6317. for (int index = 0; index < CCS_QUANTITY; index++)
  6318. {
  6319. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6320. {
  6321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6322. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6323. }
  6324. }// END OF CCS_QUANTITY
  6325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6326. }
  6327. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6328. {
  6329. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6330. {
  6331. tempIndex = ((gun_index==2) ? 1: 0);
  6332. }
  6333. else
  6334. {
  6335. tempIndex = gun_index;
  6336. }
  6337. for (int index = 0; index < GB_QUANTITY; index++)
  6338. {
  6339. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6340. {
  6341. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6342. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6343. }
  6344. }// END OF GB_QUANTITY
  6345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6346. }
  6347. else if(gunType[gun_index] == GUN_TYPE_DO)
  6348. {
  6349. tempIndex = gun_index;
  6350. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6351. {
  6352. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6353. {
  6354. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6355. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6356. }
  6357. }
  6358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6359. }
  6360. else
  6361. {
  6362. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6363. {
  6364. tempIndex = 2;
  6365. }
  6366. else
  6367. {
  6368. tempIndex = gun_index;
  6369. }
  6370. for (int index = 0; index < AC_QUANTITY; index++)
  6371. {
  6372. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6373. {
  6374. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6375. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6376. }
  6377. }// END OF AC_QUANTITY
  6378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6379. }
  6380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6385. }
  6386. //=================================== Power.Active.Import ==================================================
  6387. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6388. {
  6389. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6390. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6391. {
  6392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6393. {
  6394. tempIndex = ((gun_index==2) ? 1: 0);
  6395. }
  6396. else
  6397. {
  6398. tempIndex = gun_index;
  6399. }
  6400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6401. {
  6402. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6403. {
  6404. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6405. }
  6406. } // End for CHAdeMO_QUANTITY
  6407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6408. }
  6409. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6410. {
  6411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6412. {
  6413. tempIndex = ((gun_index==2) ? 1: 0);
  6414. }
  6415. else
  6416. {
  6417. tempIndex = gun_index;
  6418. }
  6419. for (int index = 0; index < CCS_QUANTITY; index++)
  6420. {
  6421. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6422. {
  6423. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6424. }
  6425. } // END for CCS_QUANTITY
  6426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6427. }
  6428. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6429. {
  6430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6431. {
  6432. tempIndex = ((gun_index==2) ? 1: 0);
  6433. }
  6434. else
  6435. {
  6436. tempIndex = gun_index;
  6437. }
  6438. for (int index = 0; index < GB_QUANTITY; index++)
  6439. {
  6440. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6441. {
  6442. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6443. }
  6444. }// END for GB_QUANTITY
  6445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6446. }
  6447. else if(gunType[gun_index] == GUN_TYPE_DO)
  6448. {
  6449. tempIndex = gun_index;
  6450. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6451. {
  6452. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6453. {
  6454. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6455. }
  6456. }
  6457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6458. }
  6459. else
  6460. {
  6461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6462. {
  6463. tempIndex = 2;
  6464. }
  6465. else
  6466. {
  6467. tempIndex = gun_index;
  6468. }
  6469. for (int index = 0; index < AC_QUANTITY; index++)
  6470. {
  6471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6472. {
  6473. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6474. }
  6475. } // END for AC_QUANTITY
  6476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6477. }
  6478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6483. }
  6484. //============================ Voltage L1 ====================================
  6485. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  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->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6503. }
  6504. } // END OF FOR CHAdeMO_QUANTITY
  6505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6506. }
  6507. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6508. {
  6509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6510. {
  6511. tempIndex = ((gun_index==2) ? 1: 0);
  6512. }
  6513. else
  6514. {
  6515. tempIndex = gun_index;
  6516. }
  6517. for (int index = 0; index < CCS_QUANTITY; index++)
  6518. {
  6519. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6520. {
  6521. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6522. }
  6523. } // END OF FOR CCS_QUANTITY
  6524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6525. }
  6526. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6527. {
  6528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6529. {
  6530. tempIndex = ((gun_index==2) ? 1: 0);
  6531. }
  6532. else
  6533. {
  6534. tempIndex = gun_index;
  6535. }
  6536. for (int index = 0; index < GB_QUANTITY; index++)
  6537. {
  6538. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6539. {
  6540. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6541. }
  6542. } // END OF FOR GB_QUANTITY
  6543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6544. }
  6545. else if(gunType[gun_index] == GUN_TYPE_DO)
  6546. {
  6547. tempIndex = gun_index;
  6548. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6549. {
  6550. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6551. {
  6552. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6553. }
  6554. }
  6555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6556. }
  6557. else
  6558. {
  6559. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6560. {
  6561. tempIndex = 2;
  6562. }
  6563. else
  6564. {
  6565. tempIndex = gun_index;
  6566. }
  6567. for (int index = 0; index < AC_QUANTITY; index++)
  6568. {
  6569. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6570. {
  6571. 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
  6572. }
  6573. } // END OF FOR AC_QUANTITY
  6574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6575. }
  6576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6581. }
  6582. //====================== End SoC ================================
  6583. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6584. {
  6585. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6586. 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))
  6587. {
  6588. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6589. {
  6590. tempIndex = ((gun_index==2) ? 1: 0);
  6591. }
  6592. else
  6593. {
  6594. tempIndex = gun_index;
  6595. }
  6596. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6597. {
  6598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6599. {
  6600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6601. {
  6602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6603. }
  6604. }
  6605. }
  6606. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6607. {
  6608. for (int index = 0; index < CCS_QUANTITY; index++)
  6609. {
  6610. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6611. {
  6612. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6613. }
  6614. }
  6615. }
  6616. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6617. {
  6618. for (int index = 0; index < GB_QUANTITY; index++)
  6619. {
  6620. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6621. {
  6622. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6623. }
  6624. }
  6625. }
  6626. else if(gunType[gun_index] == GUN_TYPE_DO)
  6627. {
  6628. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6629. {
  6630. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6631. {
  6632. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6633. }
  6634. }
  6635. }
  6636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6642. } // END FOR DC CASE
  6643. }
  6644. // ================================= Current.Import L2 ===============================================
  6645. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6646. {
  6647. // AC 3 phse L2 current
  6648. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6649. {
  6650. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6651. {
  6652. tempIndex = 2;
  6653. }
  6654. else
  6655. {
  6656. tempIndex = gun_index;
  6657. }
  6658. for (int index = 0; index < AC_QUANTITY; index++)
  6659. {
  6660. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6661. {
  6662. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6663. }
  6664. }// End of for AC_QUANTITY
  6665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6666. }
  6667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6672. }
  6673. // ================================= Current.Import L3 ===============================================
  6674. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6675. {
  6676. // AC 3 phse L3 current
  6677. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6678. {
  6679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6680. {
  6681. tempIndex = 2;
  6682. }
  6683. else
  6684. {
  6685. tempIndex = gun_index;
  6686. }
  6687. for (int index = 0; index < AC_QUANTITY; index++)
  6688. {
  6689. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6690. {
  6691. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6692. }
  6693. }// End of for AC_QUANTITY
  6694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6695. }
  6696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6701. }
  6702. //============================ Voltage L2 ====================================
  6703. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6704. {
  6705. // AC 3 phse L2 voltage
  6706. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6707. {
  6708. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6709. {
  6710. tempIndex = 2;
  6711. }
  6712. else
  6713. {
  6714. tempIndex = gun_index;
  6715. }
  6716. for (int index = 0; index < AC_QUANTITY; index++)
  6717. {
  6718. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6719. {
  6720. 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
  6721. }
  6722. } // END OF FOR AC_QUANTITY
  6723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6724. }
  6725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6730. }
  6731. //============================ Voltage L3 ====================================
  6732. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6733. {
  6734. // AC 3 phse L3 voltage
  6735. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6736. {
  6737. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6738. {
  6739. tempIndex = 2;
  6740. }
  6741. else
  6742. {
  6743. tempIndex = gun_index;
  6744. }
  6745. for (int index = 0; index < AC_QUANTITY; index++)
  6746. {
  6747. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6748. {
  6749. 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
  6750. }
  6751. } // END OF FOR AC_QUANTITY
  6752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6753. }
  6754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6758. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6759. }
  6760. //====================== Start SoC ================================
  6761. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6762. {
  6763. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6764. 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))
  6765. {
  6766. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6767. {
  6768. tempIndex = ((gun_index==2) ? 1: 0);
  6769. }
  6770. else
  6771. {
  6772. tempIndex = gun_index;
  6773. }
  6774. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6775. {
  6776. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6777. {
  6778. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6779. {
  6780. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6781. }
  6782. }
  6783. }
  6784. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6785. {
  6786. for (int index = 0; index < CCS_QUANTITY; index++)
  6787. {
  6788. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6789. {
  6790. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6791. }
  6792. }
  6793. }
  6794. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6795. {
  6796. for (int index = 0; index < GB_QUANTITY; index++)
  6797. {
  6798. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6799. {
  6800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6801. }
  6802. }
  6803. }
  6804. else if(gunType[gun_index] == GUN_TYPE_DO)
  6805. {
  6806. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6807. {
  6808. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6809. {
  6810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6811. }
  6812. }
  6813. }
  6814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6820. } // END FOR DC CASE
  6821. }
  6822. //================================================ Message create ====================================================
  6823. json_object *StopTransaction = json_object_new_object();
  6824. json_object *transactionDatas = json_object_new_array();
  6825. json_object *sampledValues = json_object_new_array();
  6826. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6827. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6828. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6829. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6830. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6831. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6832. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6833. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6834. {
  6835. json_object *transactionData = json_object_new_object();
  6836. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6837. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6838. {
  6839. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6840. {
  6841. json_object *sampledValue = json_object_new_object();
  6842. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6843. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6844. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6845. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6846. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6847. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6848. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6849. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6850. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6851. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6852. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6853. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6854. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6855. json_object_array_add(sampledValues, sampledValue);
  6856. }
  6857. }
  6858. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6859. json_object_array_add(transactionDatas, transactionData);
  6860. }
  6861. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6862. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6863. ,MESSAGE_TYPE_CALL
  6864. ,guid
  6865. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6866. json_object_put(StopTransaction);
  6867. #if 1 // for TempStopTransaction
  6868. //Delete TempStopTransaction
  6869. if((access(TempStopTransaction,F_OK))!=-1)
  6870. {
  6871. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6872. }
  6873. #endif
  6874. #if 1
  6875. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6876. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6877. {
  6878. result = PASS;
  6879. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6880. }
  6881. #endif
  6882. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6883. OCPP_insert_transaction_msg(NO, queuedata);
  6884. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6885. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6886. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6887. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6888. {
  6889. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6890. }
  6891. //for test
  6892. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6893. return result;
  6894. }
  6895. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6896. {
  6897. mtrace();
  6898. int result = FAIL;
  6899. char guid[37]={0};
  6900. char tempdata[65]={0};
  6901. int tempIndex = 0;
  6902. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6903. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6904. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6905. //set value
  6906. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6907. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6908. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6909. -1);
  6910. random_uuid(guid);
  6911. //UTC Date time
  6912. struct timeval tmnow;
  6913. struct tm *tm;
  6914. char buf[28];//, usec_buf[6];
  6915. gettimeofday(&tmnow, NULL);
  6916. time_t t;
  6917. t = time(NULL);
  6918. /*UTC time and date*/
  6919. tm = gmtime(&t);
  6920. if(dataType == ReadingContext_Sample_Clock)
  6921. {
  6922. struct tm *tmTarget;
  6923. struct timeb tbTarget;
  6924. tbTarget.time = mktime(tm);
  6925. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6926. tmTarget = gmtime(&tbTarget.time);
  6927. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6928. }
  6929. else
  6930. {
  6931. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6932. }
  6933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6934. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6935. //********************************(1)Current.Import L1************************************************/
  6936. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6937. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6938. (dataType == ReadingContext_Trigger))
  6939. {
  6940. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6941. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6942. {
  6943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6944. {
  6945. tempIndex = ((gun_index==2) ? 1: 0);
  6946. }
  6947. else
  6948. {
  6949. tempIndex = gun_index;
  6950. }
  6951. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6952. {
  6953. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6954. {
  6955. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6956. }
  6957. }
  6958. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6959. }
  6960. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6961. {
  6962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6963. {
  6964. tempIndex = ((gun_index==2) ? 1: 0);
  6965. }
  6966. else
  6967. {
  6968. tempIndex = gun_index;
  6969. }
  6970. for (int index = 0; index < CCS_QUANTITY; index++)
  6971. {
  6972. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6973. {
  6974. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6975. }
  6976. }
  6977. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6978. }
  6979. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6980. {
  6981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6982. {
  6983. tempIndex = ((gun_index==2) ? 1: 0);
  6984. }
  6985. else
  6986. {
  6987. tempIndex = gun_index;
  6988. }
  6989. for (int index = 0; index < GB_QUANTITY; index++)
  6990. {
  6991. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6992. {
  6993. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6994. }
  6995. }
  6996. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6997. }
  6998. else if(gunType[gun_index] == GUN_TYPE_DO)
  6999. {
  7000. tempIndex = gun_index;
  7001. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7002. {
  7003. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7004. {
  7005. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  7006. }
  7007. }
  7008. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7009. }
  7010. else
  7011. {
  7012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7013. {
  7014. tempIndex = 2;
  7015. }
  7016. else
  7017. {
  7018. tempIndex = gun_index;
  7019. }
  7020. for (int index = 0; index < AC_QUANTITY; index++)
  7021. {
  7022. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7023. {
  7024. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  7025. }
  7026. }
  7027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  7028. }
  7029. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  7030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  7031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  7032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  7033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7034. }
  7035. //********************************(2)Energy.Active.Import.Register ************************************************/
  7036. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  7037. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  7038. (dataType == ReadingContext_Trigger))
  7039. {
  7040. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7041. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7042. {
  7043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7044. {
  7045. tempIndex = ((gun_index==2) ? 1: 0);
  7046. }
  7047. else
  7048. {
  7049. tempIndex = gun_index;
  7050. }
  7051. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7052. {
  7053. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7054. {
  7055. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  7056. }
  7057. }
  7058. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7059. }
  7060. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7061. {
  7062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7063. {
  7064. tempIndex = ((gun_index==2) ? 1: 0);
  7065. }
  7066. else
  7067. {
  7068. tempIndex = gun_index;
  7069. }
  7070. for (int index = 0; index < CCS_QUANTITY; index++)
  7071. {
  7072. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7073. {
  7074. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  7075. }
  7076. }
  7077. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7078. }
  7079. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7080. {
  7081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7082. {
  7083. tempIndex = ((gun_index==2) ? 1: 0);
  7084. }
  7085. else
  7086. {
  7087. tempIndex = gun_index;
  7088. }
  7089. for (int index = 0; index < GB_QUANTITY; index++)
  7090. {
  7091. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7092. {
  7093. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  7094. }
  7095. }
  7096. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7097. }
  7098. else if(gunType[gun_index] == GUN_TYPE_DO)
  7099. {
  7100. tempIndex = gun_index;
  7101. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7102. {
  7103. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7104. {
  7105. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7106. }
  7107. }
  7108. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7109. }
  7110. else
  7111. {
  7112. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7113. {
  7114. tempIndex = 2;
  7115. }
  7116. else
  7117. {
  7118. tempIndex = gun_index;
  7119. }
  7120. for (int index = 0; index < AC_QUANTITY; index++)
  7121. {
  7122. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7123. {
  7124. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7125. }
  7126. }
  7127. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7128. }
  7129. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7134. }
  7135. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7136. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7137. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7138. (dataType == ReadingContext_Trigger))
  7139. {
  7140. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7141. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7142. {
  7143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7144. {
  7145. tempIndex = ((gun_index==2) ? 1: 0);
  7146. }
  7147. else
  7148. {
  7149. tempIndex = gun_index;
  7150. }
  7151. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7152. {
  7153. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7154. {
  7155. if(dataType == ReadingContext_Sample_Clock)
  7156. {
  7157. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7158. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7159. }
  7160. else if(dataType == ReadingContext_Sample_Periodic)
  7161. {
  7162. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7163. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7164. }
  7165. else
  7166. {
  7167. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7168. }
  7169. }
  7170. } // END OF FOR CHAdeMO_QUANTITY
  7171. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7172. }
  7173. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7174. {
  7175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7176. {
  7177. tempIndex = ((gun_index==2) ? 1: 0);
  7178. }
  7179. else
  7180. {
  7181. tempIndex = gun_index;
  7182. }
  7183. for (int index = 0; index < CCS_QUANTITY; index++)
  7184. {
  7185. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7186. {
  7187. if(dataType == ReadingContext_Sample_Clock)
  7188. {
  7189. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7190. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7191. }
  7192. else if(dataType == ReadingContext_Sample_Periodic)
  7193. {
  7194. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7195. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7196. }
  7197. else
  7198. {
  7199. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7200. }
  7201. }
  7202. } // END OF CCS_QUANTITY
  7203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7204. }
  7205. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7206. {
  7207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7208. {
  7209. tempIndex = ((gun_index==2) ? 1: 0);
  7210. }
  7211. else
  7212. {
  7213. tempIndex = gun_index;
  7214. }
  7215. for (int index = 0; index < GB_QUANTITY; index++)
  7216. {
  7217. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7218. {
  7219. if(dataType == ReadingContext_Sample_Clock)
  7220. {
  7221. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7222. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7223. }
  7224. else if(dataType == ReadingContext_Sample_Periodic)
  7225. {
  7226. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7227. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7228. }
  7229. else
  7230. {
  7231. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7232. }
  7233. }
  7234. } // END OF GB_QUANTITY
  7235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7236. }
  7237. else if(gunType[gun_index] == GUN_TYPE_DO)
  7238. {
  7239. tempIndex = gun_index;
  7240. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7241. {
  7242. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7243. {
  7244. if(dataType == ReadingContext_Sample_Clock)
  7245. {
  7246. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7247. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7248. }
  7249. else if(dataType == ReadingContext_Sample_Periodic)
  7250. {
  7251. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7252. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7253. }
  7254. else
  7255. {
  7256. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7257. }
  7258. }
  7259. }
  7260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7261. }
  7262. else
  7263. {
  7264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7265. {
  7266. tempIndex = 2;
  7267. }
  7268. else
  7269. {
  7270. tempIndex = gun_index;
  7271. }
  7272. for (int index = 0; index < AC_QUANTITY; index++)
  7273. {
  7274. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7275. {
  7276. if(dataType == ReadingContext_Sample_Clock)
  7277. {
  7278. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7279. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7280. }
  7281. else if(dataType == ReadingContext_Sample_Periodic)
  7282. {
  7283. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7284. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7285. }
  7286. else
  7287. {
  7288. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7289. }
  7290. }
  7291. }
  7292. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7293. }
  7294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7298. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7299. }
  7300. //********************************(4)Power.Active.Import************************************************/
  7301. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7302. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7303. (dataType == ReadingContext_Trigger))
  7304. {
  7305. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7306. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7307. {
  7308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7309. {
  7310. tempIndex = ((gun_index==2) ? 1: 0);
  7311. }
  7312. else
  7313. {
  7314. tempIndex = gun_index;
  7315. }
  7316. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7317. {
  7318. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7319. {
  7320. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7321. }
  7322. } // END OF FOR
  7323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7324. }
  7325. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7326. {
  7327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7328. {
  7329. tempIndex = ((gun_index==2) ? 1: 0);
  7330. }
  7331. else
  7332. {
  7333. tempIndex = gun_index;
  7334. }
  7335. for (int index = 0; index < CCS_QUANTITY; index++)
  7336. {
  7337. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7338. {
  7339. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7340. }
  7341. }
  7342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7343. }
  7344. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7345. {
  7346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7347. {
  7348. tempIndex = ((gun_index==2) ? 1: 0);
  7349. }
  7350. else
  7351. {
  7352. tempIndex = gun_index;
  7353. }
  7354. for (int index = 0; index < GB_QUANTITY; index++)
  7355. {
  7356. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7357. {
  7358. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7359. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7360. }
  7361. }
  7362. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7363. }
  7364. else if(gunType[gun_index] == GUN_TYPE_DO)
  7365. {
  7366. tempIndex = gun_index;
  7367. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7368. {
  7369. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7370. {
  7371. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7372. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7373. }
  7374. }
  7375. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7376. }
  7377. else
  7378. {
  7379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7380. {
  7381. tempIndex = 2;
  7382. }
  7383. else
  7384. {
  7385. tempIndex = gun_index;
  7386. }
  7387. for (int index = 0; index < AC_QUANTITY; index++)
  7388. {
  7389. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7390. {
  7391. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7392. }
  7393. }
  7394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7395. }
  7396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7401. }
  7402. //***********************************************(5)VOLTAGE L1******************************************************/
  7403. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7404. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7405. (dataType == ReadingContext_Trigger))
  7406. {
  7407. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7408. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7409. {
  7410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7411. {
  7412. tempIndex = ((gun_index==2) ? 1: 0);
  7413. }
  7414. else
  7415. {
  7416. tempIndex = gun_index;
  7417. }
  7418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7419. {
  7420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7421. {
  7422. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7423. }
  7424. }
  7425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7426. }
  7427. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7428. {
  7429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7430. {
  7431. tempIndex = ((gun_index==2) ? 1: 0);
  7432. }
  7433. else
  7434. {
  7435. tempIndex = gun_index;
  7436. }
  7437. for (int index = 0; index < CCS_QUANTITY; index++)
  7438. {
  7439. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7440. {
  7441. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7442. }
  7443. }
  7444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7445. }
  7446. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7447. {
  7448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7449. {
  7450. tempIndex = ((gun_index==2) ? 1: 0);
  7451. }
  7452. else
  7453. {
  7454. tempIndex = gun_index;
  7455. }
  7456. for (int index = 0; index < GB_QUANTITY; index++)
  7457. {
  7458. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7459. {
  7460. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7461. }
  7462. }
  7463. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7464. }
  7465. else if(gunType[gun_index] == GUN_TYPE_DO)
  7466. {
  7467. tempIndex = gun_index;
  7468. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7469. {
  7470. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7471. {
  7472. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7473. }
  7474. }
  7475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7476. }
  7477. else
  7478. {
  7479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7480. {
  7481. tempIndex = 2;
  7482. }
  7483. else
  7484. {
  7485. tempIndex = gun_index;
  7486. }
  7487. for (int index = 0; index < AC_QUANTITY; index++)
  7488. {
  7489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7490. {
  7491. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7492. }
  7493. }
  7494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7495. }
  7496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7501. }
  7502. //***********************************************(6)SOC******************************************************/
  7503. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7504. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7505. (dataType == ReadingContext_Trigger))
  7506. {
  7507. 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))
  7508. {
  7509. //idx_sample=5;
  7510. //sampledValue = NULL;
  7511. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7512. {
  7513. tempIndex = ((gun_index==2) ? 1: 0);
  7514. }
  7515. else
  7516. {
  7517. tempIndex = gun_index;
  7518. }
  7519. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7520. {
  7521. //tempIndex = ((gun_index==2) ? 1: 0);
  7522. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7523. {
  7524. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7525. {
  7526. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7527. }
  7528. }
  7529. }
  7530. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7531. {
  7532. //tempIndex = ((gun_index==2) ? 1: 0);
  7533. for (int index = 0; index < CCS_QUANTITY; index++)
  7534. {
  7535. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7536. {
  7537. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7538. }
  7539. }
  7540. }
  7541. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7542. {
  7543. //tempIndex = ((gun_index==2) ? 1: 0);
  7544. for (int index = 0; index < GB_QUANTITY; index++)
  7545. {
  7546. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7547. {
  7548. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7549. }
  7550. }
  7551. }
  7552. else if(gunType[gun_index] == GUN_TYPE_DO)
  7553. {
  7554. //tempIndex = ((gun_index==2) ? 1: 0);
  7555. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7556. {
  7557. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7558. {
  7559. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7560. }
  7561. }
  7562. }
  7563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7568. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7569. }
  7570. }
  7571. //********************************(7)Current.Import L2************************************************/
  7572. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7573. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7574. (dataType == ReadingContext_Trigger))
  7575. {
  7576. // Only for AC 3 phase
  7577. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7578. {
  7579. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7580. {
  7581. tempIndex = 2;
  7582. }
  7583. else
  7584. {
  7585. tempIndex = gun_index;
  7586. }
  7587. for (int index = 0; index < AC_QUANTITY; index++)
  7588. {
  7589. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7590. {
  7591. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7592. }
  7593. }
  7594. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7595. }
  7596. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7598. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7600. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7601. }
  7602. //********************************(8)Current.Import L3************************************************/
  7603. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7604. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7605. (dataType == ReadingContext_Trigger))
  7606. {
  7607. // Only for AC 3 phase
  7608. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7609. {
  7610. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7611. {
  7612. tempIndex = 2;
  7613. }
  7614. else
  7615. {
  7616. tempIndex = gun_index;
  7617. }
  7618. for (int index = 0; index < AC_QUANTITY; index++)
  7619. {
  7620. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7621. {
  7622. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7623. }
  7624. }
  7625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7626. }
  7627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7632. }
  7633. //***********************************************(9)VOLTAGE L2******************************************************/
  7634. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7635. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7636. (dataType == ReadingContext_Trigger))
  7637. {
  7638. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7639. {
  7640. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7641. {
  7642. tempIndex = 2;
  7643. }
  7644. else
  7645. {
  7646. tempIndex = gun_index;
  7647. }
  7648. for (int index = 0; index < AC_QUANTITY; index++)
  7649. {
  7650. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7651. {
  7652. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7653. }
  7654. }
  7655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7656. }
  7657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7658. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7659. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7662. }
  7663. //***********************************************(10)VOLTAGE L3******************************************************/
  7664. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7665. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7666. (dataType == ReadingContext_Trigger))
  7667. {
  7668. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7669. {
  7670. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7671. {
  7672. tempIndex = 2;
  7673. }
  7674. else
  7675. {
  7676. tempIndex = gun_index;
  7677. }
  7678. for (int index = 0; index < AC_QUANTITY; index++)
  7679. {
  7680. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7681. {
  7682. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7683. }
  7684. }
  7685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7686. }
  7687. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7688. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7689. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7691. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7692. }
  7693. //***********************************************(11)Current.Offered******************************************************/
  7694. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7695. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7696. (dataType == ReadingContext_Trigger))
  7697. {
  7698. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7699. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7700. {
  7701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7702. {
  7703. tempIndex = ((gun_index==2) ? 1: 0);
  7704. }
  7705. else
  7706. {
  7707. tempIndex = gun_index;
  7708. }
  7709. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7710. {
  7711. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7712. {
  7713. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7714. }
  7715. } // END OF FOR CHAdeMO_QUANTITY
  7716. }
  7717. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7718. {
  7719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7720. {
  7721. tempIndex = ((gun_index==2) ? 1: 0);
  7722. }
  7723. else
  7724. {
  7725. tempIndex = gun_index;
  7726. }
  7727. for (int index = 0; index < CCS_QUANTITY; index++)
  7728. {
  7729. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7730. {
  7731. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7732. }
  7733. } // END OF CCS_QUANTITY
  7734. }
  7735. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7736. {
  7737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7738. {
  7739. tempIndex = ((gun_index==2) ? 1: 0);
  7740. }
  7741. else
  7742. {
  7743. tempIndex = gun_index;
  7744. }
  7745. for (int index = 0; index < GB_QUANTITY; index++)
  7746. {
  7747. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7748. {
  7749. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7750. }
  7751. } // END OF GB_QUANTITY
  7752. }
  7753. else if(gunType[gun_index] == GUN_TYPE_DO)
  7754. {
  7755. tempIndex = gun_index;
  7756. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7757. {
  7758. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7759. {
  7760. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7761. }
  7762. }
  7763. }
  7764. else
  7765. {
  7766. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7767. {
  7768. tempIndex = 2;
  7769. }
  7770. else
  7771. {
  7772. tempIndex = gun_index;
  7773. }
  7774. for (int index = 0; index < AC_QUANTITY; index++)
  7775. {
  7776. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7777. {
  7778. uint16_t currentOffer;
  7779. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7780. {
  7781. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7782. }
  7783. else
  7784. {
  7785. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7786. }
  7787. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7788. }
  7789. }
  7790. }
  7791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7796. }
  7797. //***********************************************(12)Power.Offered******************************************************/
  7798. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7799. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7800. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7801. {
  7802. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7803. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7804. {
  7805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7806. {
  7807. tempIndex = ((gun_index==2) ? 1: 0);
  7808. }
  7809. else
  7810. {
  7811. tempIndex = gun_index;
  7812. }
  7813. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7814. {
  7815. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7816. {
  7817. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7818. }
  7819. } // END OF FOR CHAdeMO_QUANTITY
  7820. }
  7821. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7822. {
  7823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7824. {
  7825. tempIndex = ((gun_index==2) ? 1: 0);
  7826. }
  7827. else
  7828. {
  7829. tempIndex = gun_index;
  7830. }
  7831. for (int index = 0; index < CCS_QUANTITY; index++)
  7832. {
  7833. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7834. {
  7835. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7836. }
  7837. } // END OF CCS_QUANTITY
  7838. }
  7839. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7840. {
  7841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7842. {
  7843. tempIndex = ((gun_index==2) ? 1: 0);
  7844. }
  7845. else
  7846. {
  7847. tempIndex = gun_index;
  7848. }
  7849. for (int index = 0; index < GB_QUANTITY; index++)
  7850. {
  7851. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7852. {
  7853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7854. }
  7855. } // END OF GB_QUANTITY
  7856. }
  7857. else if(gunType[gun_index] == GUN_TYPE_DO)
  7858. {
  7859. tempIndex = gun_index;
  7860. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7861. {
  7862. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7863. {
  7864. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7865. }
  7866. }
  7867. }
  7868. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7869. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7870. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7871. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7872. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7873. }
  7874. // Message create ====================================================================================================
  7875. if(TRUE)
  7876. {
  7877. json_object *MeterValueReq = json_object_new_object();
  7878. json_object *MeterValues = json_object_new_array();
  7879. json_object *sampledValues = json_object_new_array();
  7880. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7881. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7882. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7883. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7884. {
  7885. json_object *MeterValue = json_object_new_object();
  7886. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7887. {
  7888. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7889. {
  7890. json_object *sampledValue = json_object_new_object();
  7891. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7892. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7893. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7894. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7895. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7896. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7897. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7898. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7899. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7900. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7901. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7902. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7903. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7904. json_object_array_add(sampledValues, sampledValue);
  7905. }
  7906. }
  7907. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7908. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7909. json_object_array_add(MeterValues, MeterValue);
  7910. }
  7911. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7912. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7913. ,gun_index + 1
  7914. ,MESSAGE_TYPE_CALL
  7915. ,guid
  7916. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7917. json_object_put(MeterValueReq);
  7918. }
  7919. // Put request guid to hash map
  7920. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7921. 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*/)
  7922. {
  7923. result = PASS;
  7924. //DEBUG_INFO("MeterValues mapitem pass\n");
  7925. }
  7926. if((dataType != ReadingContext_Trigger) &&
  7927. (dataType != ReadingContext_Sample_Clock) &&
  7928. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7929. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7930. else
  7931. {
  7932. if(FirstHeartBeat)
  7933. LWS_Send(queuedata +2);
  7934. }
  7935. return result;
  7936. }
  7937. int sendLogStatusNotificationRequest(char *status)
  7938. {
  7939. mtrace();
  7940. int result = PASS;
  7941. char message[4096]={0};
  7942. char guid[37]={0};
  7943. char tempdata[128]={0};
  7944. json_object *LogStatusNotification = json_object_new_object();
  7945. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7946. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7947. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7948. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7949. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7950. random_uuid(guid);
  7951. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7952. json_object_put(LogStatusNotification);
  7953. LWS_Send(message);
  7954. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7955. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7956. {
  7957. result = PASS;
  7958. }
  7959. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7960. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7961. return result;
  7962. }
  7963. int sendSecurityEventNotificationRequest()
  7964. {
  7965. mtrace();
  7966. int result = PASS;
  7967. char message[4096]={0};
  7968. char guid[37]={0};
  7969. char tempdata[128]={0};
  7970. json_object *SecurityEventNotification = json_object_new_object();
  7971. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7972. //Stop Transaction Time
  7973. struct timeval tmnow;
  7974. struct tm *tm;
  7975. gettimeofday(&tmnow, NULL);
  7976. time_t t;
  7977. t = time(NULL);
  7978. /*UTC time and date*/
  7979. tm = gmtime(&t);
  7980. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7981. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7982. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7983. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7984. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7985. random_uuid(guid);
  7986. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7987. json_object_put(SecurityEventNotification);
  7988. LWS_Send(message);
  7989. sprintf(tempdata, "SecurityEventNotification,0");
  7990. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7991. {
  7992. result = PASS;
  7993. }
  7994. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7995. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7996. return result;
  7997. }
  7998. int sendSignCertificateRequest()
  7999. {
  8000. mtrace();
  8001. int result = PASS;
  8002. char message[4096]={0};
  8003. char guid[37]={0};
  8004. char tempdata[128]={0};
  8005. json_object *SignCertificate = json_object_new_object();
  8006. DEBUG_INFO("sendSignCertificateRequest...\n");
  8007. // Read csr file content
  8008. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  8009. FILE *fp=fopen(CSR_CP,"r");
  8010. char *line = NULL;
  8011. size_t len = 0;
  8012. while(getline(&line, &len, fp) != -1)
  8013. {
  8014. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  8015. {
  8016. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  8017. }
  8018. }
  8019. fclose(fp);
  8020. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  8021. random_uuid(guid);
  8022. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  8023. json_object_put(SignCertificate);
  8024. LWS_Send(message);
  8025. sprintf(tempdata, "SignCertificate,0");
  8026. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8027. {
  8028. result = PASS;
  8029. }
  8030. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  8031. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  8032. return result;
  8033. }
  8034. int sendSignedFirmwareStatusNotificationRequest(char *status)
  8035. {
  8036. mtrace();
  8037. int result = PASS;
  8038. char message[4096]={0};
  8039. char guid[37]={0};
  8040. char tempdata[128]={0};
  8041. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  8042. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  8043. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  8044. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  8045. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  8046. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  8047. random_uuid(guid);
  8048. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8049. json_object_put(SignedFirmwareStatusNotification);
  8050. LWS_Send(message);
  8051. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  8052. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8053. {
  8054. result = PASS;
  8055. }
  8056. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  8057. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  8058. return result;
  8059. }
  8060. //==========================================
  8061. // send confirm routine
  8062. //==========================================
  8063. int sendCancelReservationConfirmation(char *uuid,char *payload)
  8064. {
  8065. mtrace();
  8066. int result = FAIL;
  8067. char message[100]={0};
  8068. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8069. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8070. LWS_Send(message);
  8071. result = TRUE;
  8072. return result;
  8073. }
  8074. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8075. {
  8076. mtrace();
  8077. int result = FAIL;
  8078. char message[100]={0};
  8079. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8080. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8081. LWS_Send(message);
  8082. result = TRUE;
  8083. return result;
  8084. }
  8085. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8086. {
  8087. mtrace();
  8088. int result = FAIL;
  8089. char message[100]={0};
  8090. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8091. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8092. LWS_Send(message);
  8093. result = TRUE;
  8094. return result;
  8095. }
  8096. int sendClearCacheConfirmation(char *uuid,char *payload)
  8097. {
  8098. mtrace();
  8099. int result = FAIL;
  8100. char message[500]={0};
  8101. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8102. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8103. LWS_Send(message);
  8104. return result;
  8105. }
  8106. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8107. {
  8108. mtrace();
  8109. int result = FAIL;
  8110. char message[500]={0};
  8111. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8112. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8113. LWS_Send(message);
  8114. return result;
  8115. }
  8116. int sendDataTransferConfirmation(char *uuid,char *payload)
  8117. {
  8118. mtrace();
  8119. char statusStr[20]={0};
  8120. char dataStr[10]={0};
  8121. char sstr[20]={0};
  8122. int c = 0;
  8123. char *loc;
  8124. int result = FAIL;
  8125. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8126. /**********************status**************************/
  8127. loc = strstr(payload, "status");
  8128. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8129. c = 0;
  8130. while (loc[3+strlen("status")+c] != '\"')
  8131. {
  8132. sstr[c] = loc[3+strlen("status")+c];
  8133. c++;
  8134. }
  8135. sstr[c] = '\0';
  8136. strcpy(statusStr, sstr);
  8137. /**********************data**************************/
  8138. loc = strstr(payload, "data");
  8139. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8140. c = 0;
  8141. while (loc[3+strlen("data")+c] != '\"')
  8142. {
  8143. sstr[c] = loc[3+strlen("data")+c];
  8144. c++;
  8145. }
  8146. sstr[c] = '\0';
  8147. strcpy(dataStr, sstr);
  8148. return result;
  8149. }
  8150. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8151. {
  8152. mtrace();
  8153. int result = FAIL;
  8154. char message[1000]={0};
  8155. int CompositeScheduleIndex = 0;
  8156. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8157. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8158. if(nPeriod == 0)
  8159. {
  8160. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8161. {
  8162. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8163. ,MESSAGE_TYPE_CALLRESULT
  8164. ,uuid
  8165. ,payload
  8166. ,connectorIdInt);
  8167. }
  8168. else
  8169. {
  8170. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8171. ,MESSAGE_TYPE_CALLRESULT
  8172. ,uuid
  8173. ,payload
  8174. ,connectorIdInt
  8175. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8176. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8177. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8178. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8179. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8180. }
  8181. }
  8182. else
  8183. {
  8184. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8185. ,MESSAGE_TYPE_CALLRESULT
  8186. ,uuid
  8187. ,payload
  8188. ,connectorIdInt
  8189. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8190. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8191. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8192. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8193. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8194. {
  8195. if (idx_sample == 0)
  8196. {
  8197. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8198. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8199. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8200. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8201. }
  8202. else
  8203. {
  8204. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8205. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8206. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8207. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8208. }
  8209. }
  8210. sprintf(message + strlen(message), "]}}]");
  8211. }
  8212. LWS_Send(message);
  8213. result = TRUE;
  8214. return result;
  8215. }
  8216. int sendGetConfigurationConfirmation(char *uuid)
  8217. {
  8218. mtrace();
  8219. int result = FAIL;
  8220. int MaxKeySupported = 0;
  8221. int sentConfigurationNumber= 0;
  8222. int sentunConfigurationNumber= 0;
  8223. char message[1024*10]={0};
  8224. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8225. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8226. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8227. ,MESSAGE_TYPE_CALLRESULT
  8228. ,uuid );
  8229. //configuration key
  8230. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8231. {
  8232. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8233. {
  8234. if (sentConfigurationNumber == 0)
  8235. {
  8236. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8237. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8238. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8239. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8240. }
  8241. else
  8242. {
  8243. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8244. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8245. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8246. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8247. }
  8248. sentConfigurationNumber = sentConfigurationNumber + 1;
  8249. }
  8250. }
  8251. sprintf(message + strlen(message), "]");
  8252. if(UnknownKeynum != 0)
  8253. {
  8254. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8255. //unkown key
  8256. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8257. {
  8258. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8259. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8260. if(sentunConfigurationNumber == 0)
  8261. {
  8262. sprintf(message + strlen(message), "\"%s\""
  8263. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8264. }
  8265. else
  8266. {
  8267. sprintf(message + strlen(message), ",\"%s\""
  8268. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8269. }
  8270. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8271. }
  8272. sprintf(message + strlen(message), "]");
  8273. }
  8274. sprintf(message + strlen(message), "}]");
  8275. LWS_Send(message);
  8276. return result;
  8277. }
  8278. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8279. {
  8280. mtrace();
  8281. int result = FAIL;
  8282. char message[400]={0};
  8283. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8284. if(strcmp(payload,"")==0)
  8285. {
  8286. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8287. }
  8288. else
  8289. {
  8290. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8291. }
  8292. LWS_Send(message);
  8293. result = TRUE;
  8294. return result;
  8295. }
  8296. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8297. {
  8298. mtrace();
  8299. int result = FAIL;
  8300. char message[80]={0};
  8301. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8302. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8303. LWS_Send(message);
  8304. result = TRUE;
  8305. return result;
  8306. }
  8307. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8308. {
  8309. mtrace();
  8310. int result = FAIL;
  8311. char message[80]={0};
  8312. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8313. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8314. LWS_Send(message);
  8315. result = TRUE;
  8316. return result;
  8317. }
  8318. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8319. {
  8320. mtrace();
  8321. int result = FAIL;
  8322. char message[80]={0};
  8323. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8324. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8325. LWS_Send(message);
  8326. result = TRUE;
  8327. return result;
  8328. }
  8329. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8330. {
  8331. mtrace();
  8332. int result = FAIL;
  8333. char message[80]={0};
  8334. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8335. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8336. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8337. LWS_Send(message);
  8338. result = TRUE;
  8339. return result;
  8340. }
  8341. int sendResetConfirmation(char *uuid,char *payload)
  8342. {
  8343. mtrace();
  8344. int result = FAIL;
  8345. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8346. char message[80]={0};
  8347. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8348. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8349. LWS_Send(message);
  8350. result = TRUE;
  8351. return result;
  8352. }
  8353. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8354. {
  8355. mtrace();
  8356. int result = FAIL;
  8357. char message[500]={0};
  8358. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8359. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8360. LWS_Send(message);
  8361. result = TRUE;
  8362. return result;
  8363. }
  8364. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8365. {
  8366. mtrace();
  8367. int result = FAIL;
  8368. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8369. char message[80]={0};
  8370. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8371. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8372. LWS_Send(message);
  8373. result = TRUE;
  8374. return result;
  8375. }
  8376. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8377. {
  8378. mtrace();
  8379. int result = FAIL;
  8380. char message[80]={0};
  8381. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8382. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8383. LWS_Send(message);
  8384. result = TRUE;
  8385. return result;
  8386. }
  8387. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8388. {
  8389. mtrace();
  8390. int result = FAIL;
  8391. char message[80]={0};
  8392. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8393. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8394. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8395. LWS_Send(message);
  8396. result = TRUE;
  8397. return result;
  8398. }
  8399. int sendUpdateFirmwareConfirmation(char *uuid)
  8400. {
  8401. mtrace();
  8402. int result = FAIL;
  8403. char message[60]={0};
  8404. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8405. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8406. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8407. LWS_Send(message);
  8408. result = TRUE;
  8409. return result;
  8410. }
  8411. int sendCertificateSignedConfirmation(char *uuid)
  8412. {
  8413. mtrace();
  8414. int result = PASS;
  8415. char message[4096]={0};
  8416. json_object *CertificateSigned = json_object_new_object();
  8417. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8418. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8419. sprintf(message,"[%d,\"%s\",%s]"
  8420. ,MESSAGE_TYPE_CALLRESULT
  8421. ,uuid
  8422. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8423. json_object_put(CertificateSigned);
  8424. LWS_Send(message);
  8425. return result;
  8426. }
  8427. int sendDeleteCertificateConfirmation(char *uuid)
  8428. {
  8429. mtrace();
  8430. int result = PASS;
  8431. char message[4096]={0};
  8432. json_object *DeleteCertificate = json_object_new_object();
  8433. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8434. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8435. sprintf(message,"[%d,\"%s\",%s]"
  8436. ,MESSAGE_TYPE_CALLRESULT
  8437. ,uuid
  8438. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8439. json_object_put(DeleteCertificate);
  8440. LWS_Send(message);
  8441. return result;
  8442. }
  8443. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8444. {
  8445. mtrace();
  8446. int result = PASS;
  8447. char message[4096]={0};
  8448. json_object *ExtendedTriggerMessage = json_object_new_object();
  8449. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8450. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8451. sprintf(message,"[%d,\"%s\",%s]"
  8452. ,MESSAGE_TYPE_CALLRESULT
  8453. ,uuid
  8454. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8455. json_object_put(ExtendedTriggerMessage);
  8456. LWS_Send(message);
  8457. return result;
  8458. }
  8459. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8460. {
  8461. mtrace();
  8462. int result = PASS;
  8463. char message[4096]={0};
  8464. json_object *GetInstalledCertificateIds = json_object_new_object();
  8465. json_object *certificateHashDataDatas = json_object_new_array();
  8466. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8467. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8468. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8469. {
  8470. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8471. {
  8472. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8473. {
  8474. json_object *certificateHashData = json_object_new_object();
  8475. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8476. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8477. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8478. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8479. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8480. }
  8481. }
  8482. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8483. }
  8484. else
  8485. {
  8486. json_object_put(certificateHashDataDatas);
  8487. }
  8488. sprintf(message,"[%d,\"%s\",%s]"
  8489. ,MESSAGE_TYPE_CALLRESULT
  8490. ,uuid
  8491. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8492. json_object_put(GetInstalledCertificateIds);
  8493. LWS_Send(message);
  8494. return result;
  8495. }
  8496. int sendGetLogConfirmation(char *uuid)
  8497. {
  8498. mtrace();
  8499. int result = PASS;
  8500. char message[4096]={0};
  8501. json_object *GetLog = json_object_new_object();
  8502. DEBUG_INFO("sendGetLogConfirmation...\n");
  8503. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8504. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8505. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8506. sprintf(message,"[%d,\"%s\",%s]"
  8507. ,MESSAGE_TYPE_CALLRESULT
  8508. ,uuid
  8509. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8510. json_object_put(GetLog);
  8511. LWS_Send(message);
  8512. return result;
  8513. }
  8514. int sendInstallCertificateConfirmation(char *uuid)
  8515. {
  8516. mtrace();
  8517. int result = PASS;
  8518. char message[4096]={0};
  8519. json_object *InstallCertificate = json_object_new_object();
  8520. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8521. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8522. sprintf(message,"[%d,\"%s\",%s]"
  8523. ,MESSAGE_TYPE_CALLRESULT
  8524. ,uuid
  8525. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8526. json_object_put(InstallCertificate);
  8527. LWS_Send(message);
  8528. return result;
  8529. }
  8530. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8531. {
  8532. mtrace();
  8533. int result = PASS;
  8534. char message[4096]={0};
  8535. json_object *SignedUpdateFirmware = json_object_new_object();
  8536. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8537. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8538. sprintf(message,"[%d,\"%s\",%s]"
  8539. ,MESSAGE_TYPE_CALLRESULT
  8540. ,uuid
  8541. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8542. json_object_put(SignedUpdateFirmware);
  8543. LWS_Send(message);
  8544. return result;
  8545. }
  8546. int sendUnknownConfirmation(char *uuid)
  8547. {
  8548. mtrace();
  8549. int result = PASS;
  8550. char message[256]={0};
  8551. DEBUG_INFO("sendUnknownConfirmation...\n");
  8552. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8553. LWS_Send(message);
  8554. return result;
  8555. }
  8556. //==========================================
  8557. // Handle server request routine Start
  8558. //==========================================
  8559. int handleCancelReservationRequest(char *uuid, char *payload)
  8560. {
  8561. mtrace();
  8562. int result = FAIL;
  8563. int gunNO = 0;
  8564. int reservationIdInt = -1;
  8565. char comfirmstr[20];
  8566. DEBUG_INFO("handleCancelReservationRequest...\n");
  8567. json_object *CancelReservation;
  8568. CancelReservation = json_tokener_parse(payload);
  8569. if(!is_error(CancelReservation))
  8570. {
  8571. // Required data
  8572. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8573. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8574. }
  8575. json_object_put(CancelReservation);
  8576. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8577. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8578. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8579. if(reservationIdInt != -1)
  8580. {
  8581. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8582. //check Transaction active
  8583. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8584. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8585. {
  8586. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8587. {
  8588. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8589. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8590. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8591. {
  8592. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8593. }
  8594. else
  8595. {
  8596. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8597. }
  8598. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8599. goto end;
  8600. }
  8601. }
  8602. for (int index = 0; index < CCS_QUANTITY; index++)
  8603. {
  8604. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8605. {
  8606. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8607. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8608. if(gunType[2] == GUN_TYPE_CCS)
  8609. {
  8610. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8611. }
  8612. else
  8613. {
  8614. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8615. }
  8616. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8617. goto end;
  8618. }
  8619. }
  8620. for (int index = 0; index < GB_QUANTITY; index++)
  8621. {
  8622. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8623. {
  8624. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8625. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8626. if(gunType[2] == GUN_TYPE_GBT)
  8627. {
  8628. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8629. }
  8630. else
  8631. {
  8632. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8633. }
  8634. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8635. goto end;
  8636. }
  8637. }
  8638. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8639. {
  8640. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8641. {
  8642. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8643. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8644. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8645. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8646. goto end;
  8647. }
  8648. }
  8649. for (int index = 0; index < AC_QUANTITY; index++)
  8650. {
  8651. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8652. {
  8653. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8654. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8656. {
  8657. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8658. }
  8659. else
  8660. {
  8661. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8662. }
  8663. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8664. goto end;
  8665. }
  8666. }
  8667. }
  8668. //The reservationId does NOT match the reservationId
  8669. sendCancelReservationConfirmation(uuid, comfirmstr);
  8670. end:
  8671. // Fill in ocpp packet uuid
  8672. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8673. return result;
  8674. }
  8675. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8676. {
  8677. mtrace();
  8678. int result = FAIL;
  8679. int gunIndex = -1;
  8680. char typeStr[16]={0};
  8681. char comfirmstr[20];
  8682. int specificId = FALSE;
  8683. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8684. json_object *ChangeAvailability;
  8685. ChangeAvailability = json_tokener_parse(payload);
  8686. if(!is_error(ChangeAvailability))
  8687. {
  8688. // Required data
  8689. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8690. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8691. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8692. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8693. }
  8694. json_object_put(ChangeAvailability);
  8695. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8696. {
  8697. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8698. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8699. }
  8700. else if(gunIndex == 0)
  8701. {
  8702. for(int i=0; i < gunTotalNumber; i++)
  8703. {
  8704. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8705. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8706. }
  8707. }
  8708. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8710. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8711. {
  8712. specificId = TRUE;
  8713. }
  8714. if(specificId == FALSE)
  8715. goto end;
  8716. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8717. {
  8718. //----------------------gunIndex is 0 ------------------------------------------------//
  8719. if(gunIndex == 0)
  8720. {
  8721. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8722. {
  8723. for(int i=0; i < gunTotalNumber; i++)
  8724. {
  8725. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8726. {
  8727. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8728. {
  8729. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8730. {
  8731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8732. goto end;
  8733. }
  8734. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8735. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8736. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8737. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8738. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8739. {
  8740. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8741. goto end;
  8742. }
  8743. }
  8744. }//END FOR CHAdeMO_QUANTITY
  8745. for (int index = 0; index < CCS_QUANTITY; index++)
  8746. {
  8747. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8748. {
  8749. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8750. {
  8751. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8752. goto end;
  8753. }
  8754. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8755. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8756. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8757. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8758. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8759. {
  8760. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8761. goto end;
  8762. }
  8763. }
  8764. }//END FOR CCS_QUANTITY
  8765. for (int index = 0; index < GB_QUANTITY; index++)
  8766. {
  8767. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8768. {
  8769. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8770. {
  8771. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8772. goto end;
  8773. }
  8774. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8775. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8776. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8777. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8778. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8779. {
  8780. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8781. goto end;
  8782. }
  8783. }
  8784. }// END FOR GB_QUANTITY
  8785. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8786. {
  8787. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8788. {
  8789. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8790. {
  8791. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8792. goto end;
  8793. }
  8794. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8795. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8796. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8797. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8798. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8799. {
  8800. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8801. goto end;
  8802. }
  8803. }
  8804. }// END FOR GENERAL_GUN_QUANTITY
  8805. for (int index = 0; index < AC_QUANTITY; index++)
  8806. {
  8807. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8808. {
  8809. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8810. {
  8811. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8812. goto end;
  8813. }
  8814. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8815. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8816. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8817. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8818. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8819. {
  8820. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8821. goto end;
  8822. }
  8823. }
  8824. }//END FOR AC_QUANTITY
  8825. }// END FOR gunTotalNumber
  8826. }
  8827. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8828. {
  8829. for(int i=0; i < gunTotalNumber; i++)
  8830. {
  8831. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8832. {
  8833. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8834. goto end;
  8835. }
  8836. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8837. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8838. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8839. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8840. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8841. {
  8842. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8843. goto end;
  8844. }
  8845. }
  8846. }
  8847. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8848. goto end;
  8849. }
  8850. //----------------------gunIndex is not 0 ------------------------------------------------//
  8851. //check Transaction active
  8852. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8853. {
  8854. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8855. {
  8856. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8857. {
  8858. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8859. goto end;
  8860. }
  8861. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8862. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8863. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8864. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8865. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8866. {
  8867. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8868. goto end;
  8869. }
  8870. else
  8871. {
  8872. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8873. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8874. goto end;
  8875. }
  8876. }
  8877. }//END FOR CHAdeMO_QUANTITY
  8878. for (int index = 0; index < CCS_QUANTITY; index++)
  8879. {
  8880. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8881. {
  8882. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8883. {
  8884. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8885. goto end;
  8886. }
  8887. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8888. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8889. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8890. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8891. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8892. {
  8893. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8894. goto end;
  8895. }
  8896. else
  8897. {
  8898. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8899. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8900. goto end;
  8901. }
  8902. }
  8903. }//END FOR CCS_QUANTITY
  8904. for (int index = 0; index < GB_QUANTITY; index++)
  8905. {
  8906. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8907. {
  8908. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8909. {
  8910. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8911. goto end;
  8912. }
  8913. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8914. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8915. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8916. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8917. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8918. {
  8919. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8920. goto end;
  8921. }
  8922. else
  8923. {
  8924. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8925. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8926. goto end;
  8927. }
  8928. }
  8929. }// END FOR GB_QUANTITY
  8930. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8931. {
  8932. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8933. {
  8934. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8935. {
  8936. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8937. goto end;
  8938. }
  8939. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8940. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8941. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8942. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8943. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8944. {
  8945. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8946. goto end;
  8947. }
  8948. else
  8949. {
  8950. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8951. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8952. goto end;
  8953. }
  8954. }
  8955. }// END FOR GENERAL_GUN_QUANTITY
  8956. for (int index = 0; index < AC_QUANTITY; index++)
  8957. {
  8958. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8959. {
  8960. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8961. {
  8962. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8963. goto end;
  8964. }
  8965. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8966. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8967. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8968. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8969. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8970. {
  8971. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8972. goto end;
  8973. }
  8974. else
  8975. {
  8976. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8977. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8978. goto end;
  8979. }
  8980. }
  8981. }//END FOR AC_QUANTITY
  8982. }//END FOR AvailabilityTypeStr[Inoperative]
  8983. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8984. {
  8985. //----------------------gunIndex is 0 ------------------------------------------------//
  8986. if(gunIndex == 0)
  8987. {
  8988. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8989. {
  8990. for(int i=0; i < gunTotalNumber; i++)
  8991. {
  8992. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8993. {
  8994. 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
  8995. {
  8996. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8997. goto end;
  8998. }
  8999. }//END FOR CHAdeMO_QUANTITY
  9000. for (int index = 0; index < CCS_QUANTITY; index++)
  9001. {
  9002. 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
  9003. {
  9004. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9005. goto end;
  9006. }
  9007. }//END FOR CCS_QUANTITY
  9008. for (int index = 0; index < GB_QUANTITY; index++)
  9009. {
  9010. 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
  9011. {
  9012. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9013. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9014. goto end;
  9015. }
  9016. }// END FOR GB_QUANTITY
  9017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9018. {
  9019. 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
  9020. {
  9021. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9022. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9023. goto end;
  9024. }
  9025. }// END FOR GENERAL_GUN_QUANTITY
  9026. for (int index = 0; index < AC_QUANTITY; index++)
  9027. {
  9028. 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
  9029. {
  9030. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9031. goto end;
  9032. }
  9033. }//END FOR CHAdeMO_QUANTITY
  9034. }// END FOR gunTotalNumber
  9035. }
  9036. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9037. {
  9038. for(int i=0; i < gunTotalNumber; i++)
  9039. {
  9040. for (int index = 0; index < AC_QUANTITY; index++)
  9041. {
  9042. 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
  9043. {
  9044. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9045. goto end;
  9046. }
  9047. }//END FOR CHAdeMO_QUANTITY
  9048. } // END FOR gunTotalNumber
  9049. }
  9050. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9051. goto end;
  9052. }
  9053. //----------------------gunIndex is not 0 ------------------------------------------------//
  9054. //check Transaction active
  9055. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9056. {
  9057. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9058. {
  9059. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9060. goto end;
  9061. }
  9062. }//END FOR CHAdeMO_QUANTITY
  9063. for (int index = 0; index < CCS_QUANTITY; index++)
  9064. {
  9065. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9066. {
  9067. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9068. goto end;
  9069. }
  9070. }//END FOR CCS_QUANTITY
  9071. for (int index = 0; index < GB_QUANTITY; index++)
  9072. {
  9073. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9074. {
  9075. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9076. goto end;
  9077. }
  9078. }// END FOR GB_QUANTITY
  9079. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9080. {
  9081. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9082. {
  9083. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9084. goto end;
  9085. }
  9086. }// END FOR GENERAL_GUN_QUANTITY
  9087. for (int index = 0; index < AC_QUANTITY; index++)
  9088. {
  9089. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9090. {
  9091. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9092. goto end;
  9093. }
  9094. }//END FOR AC_QUANTITY
  9095. }//END FOR AvailabilityTypeStr[Operative]
  9096. end:
  9097. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9098. {
  9099. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9100. }
  9101. else
  9102. {
  9103. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9104. }
  9105. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9106. {
  9107. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9108. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9109. }
  9110. else if(gunIndex == 0)
  9111. {
  9112. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9113. {
  9114. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9115. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9116. }
  9117. }
  9118. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9119. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9120. return result;
  9121. }
  9122. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9123. {
  9124. mtrace();
  9125. int valueInvalid = NO;
  9126. int result = FAIL;
  9127. char keystr[40]={0};
  9128. char valuestr[501]={0}; //value should be limited in 500 bytes
  9129. char comfirmstr[20]={0};
  9130. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9131. json_object *ChangeConfiguration;
  9132. ChangeConfiguration = json_tokener_parse(payload);
  9133. if(!is_error(ChangeConfiguration))
  9134. {
  9135. // Required data
  9136. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9137. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9138. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9139. {
  9140. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9141. }
  9142. else
  9143. {
  9144. valueInvalid = YES;
  9145. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9146. }
  9147. }
  9148. json_object_put(ChangeConfiguration);
  9149. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9150. {
  9151. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9152. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9153. }
  9154. else
  9155. {
  9156. int status = setKeyValue(keystr, valuestr);
  9157. switch(status)
  9158. {
  9159. case ConfigurationStatus_Accepted:
  9160. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9161. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9162. StoreConfigurationTable();
  9163. break;
  9164. case RebootRequired:
  9165. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9166. StoreConfigurationTable();
  9167. break;
  9168. case NotSupported:
  9169. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9170. break;
  9171. case ConfigurationStatus_Rejected:
  9172. default:
  9173. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9174. break;
  9175. }
  9176. }
  9177. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9178. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9179. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9180. {
  9181. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9182. SetOcppConnStatus(FALSE);
  9183. }
  9184. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9185. {
  9186. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9187. }
  9188. return result;
  9189. }
  9190. int handleClearCacheRequest(char *uuid, char *payload)
  9191. {
  9192. mtrace();
  9193. int result = FAIL;
  9194. char comfirmstr[20];
  9195. char rmFileCmd[100]={0};
  9196. struct stat stats;
  9197. DEBUG_INFO("handleClearCacheRequest...\n");
  9198. stat("/Storage/OCPP", &stats);
  9199. // Check for directory existence
  9200. if (S_ISDIR(stats.st_mode) == 1)
  9201. {}
  9202. else
  9203. {
  9204. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9205. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9206. system(rmFileCmd);
  9207. }
  9208. if(OCPP_cleanLocalCache())
  9209. {
  9210. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9211. }
  9212. else
  9213. {
  9214. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9215. }
  9216. sendClearCacheConfirmation(uuid, comfirmstr);
  9217. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9218. return result;
  9219. }
  9220. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9221. {
  9222. mtrace();
  9223. int result = FAIL;
  9224. int resultRename;
  9225. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9226. char chargingProfilePurposeStr[26]={0};
  9227. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9228. char tempchargingProfilePurposeStr[26]={0};
  9229. char str[100]={0};
  9230. char fname[200]={0};
  9231. char comfirmstr[20]={0};
  9232. char word[1600]={0};
  9233. int clearflag = FALSE;
  9234. int chargingProfileIdIsNULL = FALSE;
  9235. int connectorIsNULL = FALSE;
  9236. int chargingProfilePurposeIsNULL = FALSE;
  9237. int stackLevelIsNULL = FALSE;
  9238. //int GotoEnd = FALSE;
  9239. FILE *fptr1, *fptr2;
  9240. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9241. int n_chargingProfile=0;
  9242. int isEmptyFile = FALSE;
  9243. char sLineWord[1600]={0};
  9244. char chargingProfiles[10][100]={0};
  9245. int ChargeProfileCount = 0;
  9246. int ch;
  9247. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9248. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9249. json_object *ClearChargingProfile;
  9250. ClearChargingProfile = json_tokener_parse(payload);
  9251. if(!is_error(ClearChargingProfile))
  9252. {
  9253. // Optional data
  9254. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9255. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9256. else
  9257. chargingProfileIdIsNULL = TRUE;
  9258. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9259. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9260. else
  9261. connectorIsNULL = TRUE;
  9262. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9263. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9264. else
  9265. chargingProfilePurposeIsNULL = TRUE;
  9266. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9267. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9268. else
  9269. stackLevelIsNULL = TRUE;
  9270. }
  9271. json_object_put(ClearChargingProfile);
  9272. if(connectorIsNULL == FALSE)
  9273. {
  9274. switch(connectorIdInt)
  9275. {
  9276. case 0:
  9277. if(chargingProfilePurposeIsNULL == TRUE)
  9278. {
  9279. int l = 0;
  9280. strcpy(fname, ChargePointMaxProfile_JSON);
  9281. if((access(fname,F_OK))!=-1)
  9282. {
  9283. strcpy(chargingProfiles[l], fname);
  9284. l = l + 1;
  9285. }
  9286. strcpy(fname, TxDefaultProfile_0_JSON);
  9287. if((access(fname,F_OK))!=-1)
  9288. {
  9289. strcpy(chargingProfiles[l], fname);
  9290. l = l + 1;
  9291. }
  9292. ChargeProfileCount = l;
  9293. }
  9294. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9295. {
  9296. strcpy(fname, ChargePointMaxProfile_JSON);
  9297. if((access(fname,F_OK))!=-1)
  9298. {
  9299. strcpy(chargingProfiles[0], fname);
  9300. ChargeProfileCount = 1;
  9301. }
  9302. }
  9303. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9304. {
  9305. strcpy(fname, TxDefaultProfile_0_JSON);
  9306. if((access(fname,F_OK))!=-1)
  9307. {
  9308. strcpy(chargingProfiles[0], fname);
  9309. ChargeProfileCount = 1;
  9310. }
  9311. }
  9312. break;
  9313. default:
  9314. if(chargingProfilePurposeIsNULL == TRUE)
  9315. {
  9316. int m = 0;
  9317. memset(fname, 0, ARRAY_SIZE(fname));
  9318. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9319. if((access(fname,F_OK))!=-1)
  9320. {
  9321. strcpy(chargingProfiles[m], fname);
  9322. m = m + 1;
  9323. }
  9324. memset(fname, 0, ARRAY_SIZE(fname));
  9325. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9326. if((access(fname,F_OK))!=-1)
  9327. {
  9328. strcpy(chargingProfiles[m], fname);
  9329. m = m + 1;
  9330. }
  9331. ChargeProfileCount = m;
  9332. }
  9333. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9334. {
  9335. //strcpy(fname, TxDefaultProfile_1_JSON);
  9336. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9337. if((access(fname,F_OK))!=-1)
  9338. {
  9339. strcpy(chargingProfiles[0], fname);
  9340. ChargeProfileCount = 1;
  9341. }
  9342. }
  9343. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9344. {
  9345. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9346. if((access(fname,F_OK))!=-1)
  9347. {
  9348. strcpy(chargingProfiles[0], fname);
  9349. ChargeProfileCount = 1;
  9350. }
  9351. //strcpy(fname, TxProfile_1_JSON);
  9352. }
  9353. //strcpy(fname, ChargePointMaxProfile_JSON );
  9354. break;
  9355. }
  9356. }
  9357. else // Check all Charging Profiles
  9358. {
  9359. int i = 0;
  9360. char fnametemp[200]={0};
  9361. ChargeProfileCount = 0;
  9362. //Check ChargePointMaxProfile.json exit
  9363. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9364. {
  9365. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9366. i = i + 1;
  9367. }
  9368. //Check TxDefaultProfile_0.json exit
  9369. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9370. {
  9371. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9372. i = i + 1;
  9373. }
  9374. //Check TxDefaultProfile_%d.json
  9375. for(int j=1; j <= gunTotalNumber; j++)
  9376. {
  9377. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9378. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9379. if((access(fnametemp,F_OK))!=-1)
  9380. {
  9381. strcpy(chargingProfiles[i], fnametemp);
  9382. i = i + 1;
  9383. }
  9384. }
  9385. //Check TxProfile_%d.json
  9386. for(int j=1; j <= gunTotalNumber; j++)
  9387. {
  9388. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9389. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9390. if((access(fnametemp,F_OK))!=-1)
  9391. {
  9392. strcpy(chargingProfiles[i], fnametemp);
  9393. i = i + 1;
  9394. }
  9395. }
  9396. ChargeProfileCount = i;
  9397. }// End connectorIsNULL is TRUE
  9398. if(ChargeProfileCount == 0)
  9399. {
  9400. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9401. goto end;
  9402. }
  9403. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9404. {
  9405. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9406. goto end;
  9407. }
  9408. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9409. {
  9410. memset(str, 0, ARRAY_SIZE(str));
  9411. // clear temp file
  9412. sprintf(str,"rm -f %s",temp);
  9413. system(str);
  9414. for(int k=0; k < ChargeProfileCount; k++)
  9415. {
  9416. memset(str, 0, ARRAY_SIZE(str));
  9417. //clear file in C
  9418. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9419. system(str);
  9420. }
  9421. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9422. goto end;
  9423. }
  9424. else if(connectorIsNULL == TRUE)
  9425. {
  9426. for(int k=0; k < ChargeProfileCount; k++)
  9427. {
  9428. fptr1 = fopen(chargingProfiles[k], "r");
  9429. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9430. //Check Charging Profile Count
  9431. while(fscanf(fptr1, "%s", word) != EOF)
  9432. {
  9433. //DEBUG_INFO("word=%s\n",word);
  9434. if(strstr(word, "chargingProfileId")!= NULL)
  9435. {
  9436. //DEBUG_INFO("test chargingProfileId \n");
  9437. n_chargingProfile = n_chargingProfile + 1;
  9438. //DEBUG_INFO("chargingProfileId Found\n");
  9439. }
  9440. }
  9441. rewind(fptr1);
  9442. //search Charging Profile Element
  9443. //int i= 0;
  9444. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9445. {
  9446. json_object *tmpProfilee;
  9447. tmpProfilee = json_tokener_parse(sLineWord);
  9448. if(!is_error(tmpProfilee))
  9449. {
  9450. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9451. {
  9452. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9453. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9454. }
  9455. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9456. {
  9457. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9458. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9459. }
  9460. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9461. {
  9462. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9463. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9464. }
  9465. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9466. {
  9467. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9468. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9469. }
  9470. }
  9471. json_object_put(tmpProfilee);
  9472. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9473. {
  9474. //------- not write to fptr2-------//
  9475. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9476. //clearflag = TRUE;
  9477. }
  9478. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9479. {
  9480. //------- not write to fptr2-------//
  9481. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9482. }
  9483. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9484. {
  9485. //------- not write to fptr2-------//
  9486. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9487. }
  9488. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9489. {
  9490. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9491. }
  9492. else
  9493. {
  9494. fprintf(fptr2, sLineWord);//writing data into file
  9495. }
  9496. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9497. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9498. if(clearflag == TRUE)
  9499. {
  9500. fclose(fptr1);
  9501. fclose(fptr2);
  9502. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9503. system(str);
  9504. // clear temp file
  9505. sprintf(str,"rm -f %s",temp);
  9506. system(str);
  9507. }
  9508. else
  9509. {
  9510. fclose(fptr1);
  9511. fclose(fptr2);
  9512. memset(str, 0, ARRAY_SIZE(str));
  9513. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9514. system(str);
  9515. resultRename = rename(temp, chargingProfiles[k]);
  9516. if(resultRename == 0)
  9517. {
  9518. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9519. }
  9520. else
  9521. {
  9522. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9523. }
  9524. if(comfirmstr[0]== 0)
  9525. {
  9526. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9527. }
  9528. //Check chargingProfile is empty file
  9529. /*------ Read the file ----------------*/
  9530. fptr1=fopen(chargingProfiles[k],"r");
  9531. ch=fgetc(fptr1);
  9532. rewind(fptr1);
  9533. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9534. if(ch!=EOF)
  9535. {
  9536. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9537. {
  9538. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9539. if(sLineWord[0]=='\0')
  9540. {
  9541. isEmptyFile = TRUE;
  9542. break;
  9543. }
  9544. else
  9545. {
  9546. isEmptyFile = FALSE;
  9547. break;
  9548. }
  9549. }
  9550. }
  9551. else
  9552. isEmptyFile = TRUE;
  9553. fclose(fptr1);
  9554. if(isEmptyFile == TRUE)
  9555. {
  9556. memset(str, 0, ARRAY_SIZE(str));
  9557. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9558. system(str);
  9559. }
  9560. }
  9561. }// End of while(int k=0; k < ChargePointCount; k++)
  9562. }
  9563. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9564. {
  9565. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9566. for(int k=0; k < ChargeProfileCount; k++)
  9567. {
  9568. fptr1 = fopen(chargingProfiles[k], "r");
  9569. fptr2 = fopen(temp, "w+");
  9570. //Check Charging Profile Count
  9571. while(fscanf(fptr1, "%s", word) != EOF)
  9572. {
  9573. //DEBUG_INFO("word=%s\n",word);
  9574. if(strstr(word, "chargingProfileId")!= NULL)
  9575. {
  9576. n_chargingProfile = n_chargingProfile + 1;
  9577. }
  9578. }
  9579. rewind(fptr1);
  9580. //search Charging Profile Element
  9581. //int i= 0;
  9582. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9583. {
  9584. json_object *tmpProfilee;
  9585. tmpProfilee = json_tokener_parse(sLineWord);
  9586. if(!is_error(tmpProfilee))
  9587. {
  9588. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9589. {
  9590. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9591. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9592. }
  9593. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9594. {
  9595. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9596. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9597. }
  9598. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9599. {
  9600. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9601. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9602. }
  9603. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9604. {
  9605. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9606. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9607. }
  9608. }
  9609. json_object_put(tmpProfilee);
  9610. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9611. {
  9612. //------- not write to fptr2-------//
  9613. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9614. //clearflag = TRUE;
  9615. }
  9616. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9617. {
  9618. //------- not write to fptr2-------//
  9619. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9620. }
  9621. else if(stackLevelIsNULL == TRUE)
  9622. {
  9623. //Clear Whole File
  9624. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9625. clearflag = TRUE;
  9626. break;
  9627. }
  9628. else
  9629. {
  9630. fprintf(fptr2, sLineWord);//writing data into file
  9631. }
  9632. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9633. }
  9634. if(clearflag == TRUE)
  9635. {
  9636. fclose(fptr1);
  9637. fclose(fptr2);
  9638. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9639. system(str);
  9640. // clear temp file
  9641. sprintf(str,"rm -f %s",temp);
  9642. system(str);
  9643. }
  9644. else
  9645. {
  9646. fclose(fptr1);
  9647. fclose(fptr2);
  9648. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9649. system(str);
  9650. resultRename = rename(temp, chargingProfiles[k]);
  9651. if(resultRename == 0)
  9652. {
  9653. DEBUG_INFO("File ChargingProfile renamed successfully");
  9654. }
  9655. else
  9656. {
  9657. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9658. }
  9659. if(comfirmstr[0]== 0)
  9660. {
  9661. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9662. }
  9663. //Check chargingProfile is empty file
  9664. /*------ Read the file ----------------*/
  9665. fptr1=fopen(chargingProfiles[k],"r");
  9666. ch=fgetc(fptr1);
  9667. rewind(fptr1);
  9668. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9669. if(ch!=EOF)
  9670. {
  9671. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9672. {
  9673. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9674. if(sLineWord[0]=='\0')
  9675. {
  9676. isEmptyFile = TRUE;
  9677. break;
  9678. }
  9679. else
  9680. {
  9681. isEmptyFile = FALSE;
  9682. break;
  9683. }
  9684. }
  9685. }
  9686. else
  9687. isEmptyFile = TRUE;
  9688. fclose(fptr1);
  9689. if(isEmptyFile == TRUE)
  9690. {
  9691. memset(str, 0, ARRAY_SIZE(str));
  9692. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9693. system(str);
  9694. }
  9695. /*------- End of reading ---------------*/
  9696. }
  9697. } // while(int k=0; k < ChargeProfileCount; k++)
  9698. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9699. end:
  9700. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9701. {
  9702. if(connectorIdInt == 0)
  9703. {
  9704. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9705. {
  9706. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9707. }
  9708. }
  9709. else
  9710. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9711. }
  9712. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9713. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9714. return result;
  9715. }
  9716. void createFirmwareVersionByDataTransfer(void)
  9717. {
  9718. json_object *FirmwareDataTransfer = json_object_new_object();
  9719. // AC & DC model
  9720. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9721. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9722. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9723. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9724. // DC model
  9725. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9726. {
  9727. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9728. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9729. (gunType[3] != GUN_TYPE_UNKNOWN))
  9730. {
  9731. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9732. }
  9733. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9734. {
  9735. // DS DM DW
  9736. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9737. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9738. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9739. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9740. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9741. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9742. }
  9743. else
  9744. {
  9745. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9746. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9747. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9748. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9749. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9750. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9751. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9752. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9753. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9754. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9755. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9756. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9757. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9758. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9759. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9760. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9761. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9762. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9763. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9764. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9765. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9766. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9767. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9768. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9769. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9770. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9771. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9772. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9773. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9774. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9775. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9776. }
  9777. }
  9778. // 4G model
  9779. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9780. {
  9781. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9782. }
  9783. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9784. json_object_put(FirmwareDataTransfer);
  9785. }
  9786. int handleDataTransferRequest(char *uuid, char *payload)
  9787. {
  9788. mtrace();
  9789. json_object *response = json_object_new_object();
  9790. int result = FAIL;
  9791. char tempvendorId[255]={0};
  9792. char tempmessageId[50]={0};
  9793. char tempdata[10240]={0};
  9794. char message[20480]={0};
  9795. DEBUG_INFO("handleDataTransferRequest...\n");
  9796. if((uuid != NULL) && (payload != NULL))
  9797. {
  9798. json_object *DataTransfer;
  9799. DataTransfer = json_tokener_parse(payload);
  9800. if(!is_error(DataTransfer))
  9801. {
  9802. // Required data
  9803. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9804. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9805. // Optional data
  9806. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9807. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9808. if(json_object_object_get(DataTransfer, "data") != NULL)
  9809. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9810. result = PASS;
  9811. }
  9812. json_object_put(DataTransfer);
  9813. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9814. {
  9815. // Send all moudle firmware version on EVSE
  9816. createFirmwareVersionByDataTransfer();
  9817. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9818. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9819. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9820. json_object_put(response);
  9821. }
  9822. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9823. {
  9824. system("/usr/bin/run_tmate_restart.sh &");
  9825. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9826. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9827. json_object_put(response);
  9828. }
  9829. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9830. {
  9831. json_object *data;
  9832. data = json_tokener_parse(tempdata);
  9833. if(!is_error(data))
  9834. {
  9835. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9836. {
  9837. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9838. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9839. if(json_object_object_get(data, "SOC") != NULL)
  9840. {
  9841. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9842. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9843. }
  9844. if(json_object_object_get(data, "Energy") != NULL)
  9845. {
  9846. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9847. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9848. }
  9849. if(json_object_object_get(data, "Duration") != NULL)
  9850. {
  9851. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9852. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9853. }
  9854. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9855. }
  9856. else
  9857. {
  9858. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9859. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9860. }
  9861. }
  9862. else
  9863. {
  9864. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9865. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9866. }
  9867. json_object_put(data);
  9868. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9869. json_object_put(response);
  9870. }
  9871. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9872. {
  9873. json_object *data;
  9874. data = json_tokener_parse(tempdata);
  9875. if(!is_error(data))
  9876. {
  9877. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9878. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9879. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9880. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9881. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9882. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9883. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9884. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9885. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9886. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9887. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9888. }
  9889. else
  9890. {
  9891. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9892. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9893. }
  9894. json_object_put(data);
  9895. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9896. json_object_put(response);
  9897. }
  9898. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9899. {
  9900. json_object *data;
  9901. data = json_tokener_parse(tempdata);
  9902. if(!is_error(data))
  9903. {
  9904. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9905. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9906. if(json_object_object_get(data, "idToken") != NULL)
  9907. {
  9908. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9909. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9910. }
  9911. else
  9912. {
  9913. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9914. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9915. }
  9916. if(json_object_object_get(data, "price") != NULL) //v1.0
  9917. {
  9918. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9919. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9920. }
  9921. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9922. {
  9923. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9924. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9925. }
  9926. else
  9927. {
  9928. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9929. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9930. }
  9931. }
  9932. else
  9933. {
  9934. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9935. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9936. }
  9937. json_object_put(data);
  9938. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9939. json_object_put(response);
  9940. }
  9941. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9942. {
  9943. json_object *data;
  9944. data = json_tokener_parse(tempdata);
  9945. if(!is_error(data))
  9946. {
  9947. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9948. if(json_object_object_get(data, "txId") != NULL)
  9949. {
  9950. // California pricing V1.0
  9951. DEBUG_INFO("California pricing V1.0\n");
  9952. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9953. sprintf((char*)dmsVersion, "1.0");
  9954. for(int idx = 0;idx<gunTotalNumber;idx++)
  9955. {
  9956. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9957. {
  9958. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9959. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9960. if(json_object_object_get(data, "description") != NULL)
  9961. {
  9962. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9963. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9964. }
  9965. else
  9966. {
  9967. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9968. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9969. }
  9970. }
  9971. }
  9972. }
  9973. else if(json_object_object_get(data, "transactionId") != NULL)
  9974. {
  9975. // California pricing V2.0
  9976. DEBUG_INFO("California pricing V2.0\n");
  9977. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9978. sprintf((char*)dmsVersion, "2.0");
  9979. for(int idx=0;idx<gunTotalNumber;idx++)
  9980. {
  9981. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9982. {
  9983. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9984. if(json_object_object_get(data, "timestamp") != NULL)
  9985. {
  9986. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9987. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9988. }
  9989. else
  9990. {
  9991. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9992. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9993. }
  9994. if(json_object_object_get(data, "meterValue") != NULL)
  9995. {
  9996. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9997. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9998. }
  9999. else
  10000. {
  10001. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10002. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  10003. }
  10004. if(json_object_object_get(data, "cost") != NULL)
  10005. {
  10006. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  10007. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10008. }
  10009. else
  10010. {
  10011. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10012. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10013. }
  10014. if(json_object_object_get(data, "state") != NULL)
  10015. {
  10016. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  10017. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  10018. }
  10019. else
  10020. {
  10021. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10022. json_object_object_add(response, "data", json_object_new_string("state not found."));
  10023. }
  10024. if(json_object_object_get(data, "chargingPrice") != NULL)
  10025. {
  10026. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  10027. {
  10028. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  10029. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  10030. }
  10031. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  10032. {
  10033. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  10034. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  10035. }
  10036. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  10037. {
  10038. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  10039. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  10040. }
  10041. }
  10042. else
  10043. {
  10044. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10045. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10046. }
  10047. if(json_object_object_get(data, "idlePrice") != NULL)
  10048. {
  10049. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  10050. {
  10051. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  10052. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  10053. }
  10054. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  10055. {
  10056. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  10057. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  10058. }
  10059. }
  10060. if(json_object_object_get(data, "nextPeriod") != NULL)
  10061. {
  10062. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  10063. {
  10064. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  10065. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  10066. }
  10067. else
  10068. {
  10069. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10070. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  10071. }
  10072. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  10073. {
  10074. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  10075. {
  10076. 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")));
  10077. 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"));
  10078. }
  10079. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  10080. {
  10081. 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")));
  10082. 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"));
  10083. }
  10084. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  10085. {
  10086. 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")));
  10087. 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"));
  10088. }
  10089. }
  10090. else
  10091. {
  10092. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10093. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10094. }
  10095. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10096. {
  10097. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10098. {
  10099. 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")));
  10100. 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"));
  10101. }
  10102. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10103. {
  10104. 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")));
  10105. 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"));
  10106. }
  10107. }
  10108. }
  10109. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10110. {
  10111. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10112. {
  10113. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10114. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10115. }
  10116. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10117. {
  10118. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10119. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10120. }
  10121. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10122. {
  10123. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10124. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10125. }
  10126. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10127. {
  10128. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10129. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10130. }
  10131. }
  10132. }
  10133. }
  10134. }
  10135. else
  10136. {
  10137. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10138. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10139. }
  10140. }
  10141. else
  10142. {
  10143. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10144. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10145. }
  10146. json_object_put(data);
  10147. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10148. json_object_put(response);
  10149. }
  10150. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10151. {
  10152. json_object *data;
  10153. data = json_tokener_parse(tempdata);
  10154. if(!is_error(data))
  10155. {
  10156. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10157. if(json_object_object_get(data, "txId") != NULL)
  10158. {
  10159. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10160. for(int idx = 0;idx<gunTotalNumber;idx++)
  10161. {
  10162. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10163. {
  10164. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10165. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10166. if(json_object_object_get(data, "description") != NULL)
  10167. {
  10168. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10169. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10170. }
  10171. else
  10172. {
  10173. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10174. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10175. }
  10176. }
  10177. }
  10178. }
  10179. else if(json_object_object_get(data, "transactionId") != NULL)
  10180. {
  10181. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10182. for(int idx = 0;idx<gunTotalNumber;idx++)
  10183. {
  10184. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10185. {
  10186. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10187. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10188. if(json_object_object_get(data, "cost") != NULL)
  10189. {
  10190. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10191. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10192. }
  10193. else
  10194. {
  10195. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10196. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10197. }
  10198. if(json_object_object_get(data, "priceText") != NULL)
  10199. {
  10200. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10201. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10202. }
  10203. else
  10204. {
  10205. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10206. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10207. }
  10208. if(json_object_object_get(data, "qrCodeText") != NULL)
  10209. {
  10210. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10211. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10212. }
  10213. }
  10214. }
  10215. }
  10216. else
  10217. {
  10218. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10219. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10220. }
  10221. }
  10222. else
  10223. {
  10224. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10225. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10226. }
  10227. json_object_put(data);
  10228. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10229. json_object_put(response);
  10230. }
  10231. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10232. {
  10233. json_object *data;
  10234. data = json_tokener_parse(tempdata);
  10235. if(!is_error(data))
  10236. {
  10237. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10238. if(json_object_object_get(data, "Content_Type") != NULL)
  10239. {
  10240. 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))
  10241. {
  10242. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10243. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10244. {
  10245. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10246. }
  10247. }
  10248. else
  10249. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10250. }
  10251. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10252. }
  10253. else
  10254. {
  10255. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10256. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10257. }
  10258. json_object_put(data);
  10259. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10260. json_object_put(response);
  10261. }
  10262. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10263. {
  10264. json_object *data;
  10265. data = json_tokener_parse(tempdata);
  10266. if(!is_error(data))
  10267. {
  10268. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10269. if(json_object_object_get(data, "ConnectorId") != NULL)
  10270. {
  10271. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10272. }
  10273. if(json_object_object_get(data, "SerialNo") != NULL)
  10274. {
  10275. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10276. }
  10277. if(json_object_object_get(data, "Page_Index") != NULL)
  10278. {
  10279. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10280. }
  10281. if(json_object_object_get(data, "Duration") != NULL)
  10282. {
  10283. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10284. }
  10285. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10286. }
  10287. else
  10288. {
  10289. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10290. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10291. }
  10292. json_object_put(data);
  10293. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10294. json_object_put(response);
  10295. }
  10296. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10297. {
  10298. json_object *data;
  10299. data = json_tokener_parse(tempdata);
  10300. if(!is_error(data))
  10301. {
  10302. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10303. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10304. {
  10305. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10306. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10307. else
  10308. {
  10309. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10310. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10311. }
  10312. }
  10313. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10314. {
  10315. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10316. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10317. else
  10318. {
  10319. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10320. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10321. }
  10322. }
  10323. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10324. {
  10325. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10326. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10327. else
  10328. {
  10329. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10330. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10331. }
  10332. }
  10333. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10334. {
  10335. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10336. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10337. else
  10338. {
  10339. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10340. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10341. }
  10342. }
  10343. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10344. {
  10345. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10346. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10347. else
  10348. {
  10349. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10350. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10351. }
  10352. }
  10353. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10354. {
  10355. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10356. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10357. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10358. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10359. else
  10360. {
  10361. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10362. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10363. }
  10364. }
  10365. if(json_object_object_get(data, "isAuthentication") != NULL)
  10366. {
  10367. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10368. {
  10369. case 0:
  10370. case 1:
  10371. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10372. break;
  10373. default:
  10374. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10375. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10376. break;
  10377. }
  10378. }
  10379. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10380. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10381. }
  10382. else
  10383. {
  10384. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10385. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10386. }
  10387. json_object_put(data);
  10388. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10389. json_object_put(response);
  10390. }
  10391. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10392. {
  10393. json_object *data;
  10394. data = json_tokener_parse(tempdata);
  10395. if(!is_error(data))
  10396. {
  10397. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10398. {
  10399. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10400. {
  10401. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10402. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10403. }
  10404. else
  10405. {
  10406. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10407. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10408. }
  10409. }
  10410. else
  10411. {
  10412. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10413. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10414. }
  10415. }
  10416. else
  10417. {
  10418. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10419. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10420. }
  10421. json_object_put(data);
  10422. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10423. json_object_put(response);
  10424. }
  10425. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10426. {
  10427. json_object *data;
  10428. data = json_tokener_parse(tempdata);
  10429. if(!is_error(data))
  10430. {
  10431. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10432. if(json_object_object_get(data, "stationName") != NULL)
  10433. {
  10434. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10435. }
  10436. else
  10437. {
  10438. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10439. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10440. }
  10441. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10442. {
  10443. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10444. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10445. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10446. }
  10447. }
  10448. else
  10449. {
  10450. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10451. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10452. }
  10453. json_object_put(data);
  10454. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10455. json_object_put(response);
  10456. }
  10457. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10458. {
  10459. json_object *data;
  10460. data = json_tokener_parse(tempdata);
  10461. if(!is_error(data))
  10462. {
  10463. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10464. if(json_object_object_get(data, "weatherId") != NULL)
  10465. {
  10466. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10467. }
  10468. else
  10469. {
  10470. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10471. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10472. }
  10473. if(json_object_object_get(data, "Temperature") != NULL)
  10474. {
  10475. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10476. }
  10477. else
  10478. {
  10479. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10480. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10481. }
  10482. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10483. {
  10484. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10485. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10486. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10487. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10488. );
  10489. }
  10490. }
  10491. else
  10492. {
  10493. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10494. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10495. }
  10496. json_object_put(data);
  10497. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10498. json_object_put(response);
  10499. }
  10500. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10501. {
  10502. json_object *data;
  10503. data = json_tokener_parse(tempdata);
  10504. if(!is_error(data))
  10505. {
  10506. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10507. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10508. {
  10509. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10510. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10511. }
  10512. else
  10513. {
  10514. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10515. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10516. }
  10517. }
  10518. else
  10519. {
  10520. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10521. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10522. }
  10523. json_object_put(data);
  10524. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10525. json_object_put(response);
  10526. }
  10527. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10528. {
  10529. json_object *data;
  10530. data = json_tokener_parse(tempdata);
  10531. if(!is_error(data))
  10532. {
  10533. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10534. {
  10535. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10536. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10537. if(gun_index < gunTotalNumber)
  10538. {
  10539. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10540. {
  10541. json_object *responsedata = json_object_new_object();
  10542. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10543. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10544. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10545. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10546. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10547. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10548. }
  10549. else
  10550. {
  10551. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10552. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10553. }
  10554. }
  10555. else
  10556. {
  10557. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10558. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10559. }
  10560. }
  10561. else
  10562. {
  10563. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10564. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10565. }
  10566. }
  10567. else
  10568. {
  10569. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10570. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10571. }
  10572. json_object_put(data);
  10573. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10574. json_object_put(response);
  10575. }
  10576. // Support ISO-15118 related message
  10577. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10578. {
  10579. char cmdBuf[1024]={0};
  10580. sprintf(cmdBuf, "openssl req -newkey rsa:2048 -out %s -nodes -keyout %s -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=%s/OU=IT/CN=%s\" &", CSR_V2G, PRIVATE_KEY_V2G, ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10581. system(cmdBuf);
  10582. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10583. json_object *responsedata = json_object_new_object();
  10584. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10585. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10586. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10587. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10588. json_object_put(response);
  10589. }
  10590. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10591. {
  10592. json_object *data;
  10593. data = json_tokener_parse(tempdata);
  10594. if(!is_error(data))
  10595. {
  10596. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10597. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10598. fclose(fp);
  10599. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10600. json_object *responsedata = json_object_new_object();
  10601. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10602. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10603. else
  10604. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10605. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10606. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10607. }
  10608. else
  10609. {
  10610. json_object *responsedata = json_object_new_object();
  10611. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10612. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10613. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10614. }
  10615. json_object_put(data);
  10616. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10617. json_object_put(response);
  10618. }
  10619. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10620. {
  10621. json_object *data;
  10622. data = json_tokener_parse(tempdata);
  10623. if(!is_error(data))
  10624. {
  10625. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10626. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10627. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10628. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10629. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10630. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10631. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10632. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10633. char temp[256] = {0};
  10634. char compareData[256] = {0};
  10635. int isMatch = TRUE;
  10636. FILE *fp;
  10637. // Check certV2G
  10638. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10639. {
  10640. isMatch = FALSE;
  10641. sprintf(temp ,"openssl x509 -noout -serial -in %s", CERTIFICATE_V2G);
  10642. fp = popen(temp, "r");
  10643. if(fp)
  10644. {
  10645. while(fgets(temp, sizeof(temp), fp) != NULL)
  10646. {
  10647. if(strstr(temp, "serial=") != NULL)
  10648. {
  10649. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10650. sscanf(temp, "%*[^=]=%s", compareData);
  10651. break;
  10652. }
  10653. }
  10654. }
  10655. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  10656. isMatch = FALSE;
  10657. if(isMatch == TRUE)
  10658. {
  10659. memset(compareData, 0, ARRAY_SIZE(compareData));
  10660. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", CERTIFICATE_V2G, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10661. fp = popen(temp, "r");
  10662. if(fp)
  10663. {
  10664. while(fgets(temp, sizeof(temp), fp) != NULL)
  10665. {
  10666. strcat(compareData, temp);
  10667. }
  10668. }
  10669. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  10670. isMatch = FALSE;
  10671. }
  10672. if(isMatch == TRUE)
  10673. {
  10674. memset(compareData, 0, ARRAY_SIZE(compareData));
  10675. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", CERTIFICATE_V2G, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10676. fp = popen(temp, "r");
  10677. if(fp)
  10678. {
  10679. while(fgets(temp, sizeof(temp), fp) != NULL)
  10680. {
  10681. strcat(compareData, temp);
  10682. }
  10683. }
  10684. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10685. isMatch = FALSE;
  10686. }
  10687. if(isMatch == TRUE)
  10688. {
  10689. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10690. system(temp);
  10691. json_object *responsedata = json_object_new_object();
  10692. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10693. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10694. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10695. }
  10696. else
  10697. {
  10698. json_object *responsedata = json_object_new_object();
  10699. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10700. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10701. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10702. }
  10703. }
  10704. else
  10705. {
  10706. json_object *responsedata = json_object_new_object();
  10707. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10708. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10709. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10710. }
  10711. }
  10712. else
  10713. {
  10714. json_object *responsedata = json_object_new_object();
  10715. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10716. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10717. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10718. }
  10719. json_object_put(data);
  10720. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10721. json_object_put(response);
  10722. }
  10723. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10724. {
  10725. json_object *data;
  10726. data = json_tokener_parse(tempdata);
  10727. if(!is_error(data))
  10728. {
  10729. /*
  10730. * TODO:
  10731. * 1. Query certificate to response
  10732. */
  10733. json_object *responsedata = json_object_new_object();
  10734. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10735. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10736. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10737. }
  10738. else
  10739. {
  10740. json_object *responsedata = json_object_new_object();
  10741. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10742. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10743. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10744. }
  10745. json_object_put(data);
  10746. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10747. json_object_put(response);
  10748. }
  10749. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10750. {
  10751. json_object *data;
  10752. data = json_tokener_parse(tempdata);
  10753. if(!is_error(data))
  10754. {
  10755. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10756. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10757. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10758. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10759. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10760. char temp[1024];
  10761. FILE *fp = fopen(tempCert, "w");
  10762. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10763. fclose(fp);
  10764. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10765. char strExpDate[30];
  10766. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10767. fp = popen(temp, "r");
  10768. if(fp)
  10769. {
  10770. while(fgets(temp, sizeof(temp), fp) != NULL)
  10771. {
  10772. if(strstr(temp, "notAfter=") != NULL)
  10773. {
  10774. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10775. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10776. break;
  10777. }
  10778. }
  10779. }
  10780. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10781. struct tm tmExpDate;
  10782. struct timeb tbExpDate;
  10783. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10784. tbExpDate.time = mktime(&tmExpDate);
  10785. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10786. {
  10787. DEBUG_INFO("The enddate is already expired...\n");
  10788. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10789. }
  10790. else
  10791. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10792. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10793. {
  10794. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10795. {
  10796. if(access(ROOTCA_V2G,F_OK) != -1)
  10797. {
  10798. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10799. rename(ROOTCA_V2G, "/Storage/OCPP/rootCaV2g_fallback.pem");
  10800. rename(tempCert, ROOTCA_V2G);
  10801. }
  10802. else
  10803. {
  10804. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10805. rename(tempCert, ROOTCA_V2G);
  10806. }
  10807. json_object *responsedata = json_object_new_object();
  10808. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10809. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10810. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10811. }
  10812. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10813. {
  10814. if(access(ROOTCA_MO,F_OK) != -1)
  10815. {
  10816. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10817. rename(ROOTCA_MO, "/Storage/OCPP/rootCaMo_fallback.pem");
  10818. rename(tempCert, ROOTCA_MO);
  10819. }
  10820. else
  10821. {
  10822. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10823. rename(tempCert, ROOTCA_MO);
  10824. }
  10825. json_object *responsedata = json_object_new_object();
  10826. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10827. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10828. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10829. }
  10830. else
  10831. {
  10832. json_object *responsedata = json_object_new_object();
  10833. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10834. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10835. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10836. }
  10837. }
  10838. else
  10839. {
  10840. json_object *responsedata = json_object_new_object();
  10841. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10842. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10843. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10844. }
  10845. }
  10846. else
  10847. {
  10848. json_object *responsedata = json_object_new_object();
  10849. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10850. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10851. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10852. }
  10853. json_object_put(data);
  10854. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10855. json_object_put(response);
  10856. }
  10857. else
  10858. {
  10859. // Can not find valid message id
  10860. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10861. }
  10862. }
  10863. else
  10864. {
  10865. // Payload is null
  10866. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10867. }
  10868. LWS_Send(message);
  10869. return result;
  10870. }
  10871. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10872. {
  10873. mtrace();
  10874. int result = FAIL;
  10875. int connectorIdInt, durationInt;
  10876. char chargingRateUnitStr[4]={0};
  10877. char comfirmstr[20];
  10878. int confirmPeriods = 0;
  10879. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10880. json_object *GetCompositeSchedule;
  10881. GetCompositeSchedule = json_tokener_parse(payload);
  10882. if(!is_error(GetCompositeSchedule))
  10883. {
  10884. // Required data
  10885. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10886. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10887. else
  10888. connectorIdInt = -1;
  10889. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10890. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10891. else
  10892. durationInt = 86400;
  10893. // Optional data
  10894. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10895. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10896. }
  10897. json_object_put(GetCompositeSchedule);
  10898. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10899. if((connectorIdInt == 0) ||
  10900. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10901. {
  10902. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10903. struct StructChargingProfile tmpProfile[1];
  10904. if(strstr(chargingRateUnitStr, "W") != NULL)
  10905. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10906. else
  10907. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10908. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10909. {
  10910. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10911. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10912. }
  10913. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10914. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10915. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10916. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10917. {
  10918. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10919. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10920. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10921. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10922. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10923. {
  10924. confirmPeriods = idx;
  10925. break;
  10926. }
  10927. }
  10928. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10929. {
  10930. confirmPeriods += 1;
  10931. }
  10932. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10933. }
  10934. else
  10935. {
  10936. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10937. }
  10938. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10939. return result;
  10940. }
  10941. int handleGetConfigurationRequest(char *uuid, char *payload)
  10942. {
  10943. mtrace();
  10944. int result = FAIL;
  10945. int MaxKeySupported = 0;
  10946. int n_keys = 0;
  10947. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10948. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10949. json_object *GetConfiguration;
  10950. GetConfiguration = json_tokener_parse(payload);
  10951. if(!is_error(GetConfiguration))
  10952. {
  10953. // Optional data
  10954. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10955. {
  10956. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10957. {
  10958. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10959. n_keys = idx + 1;
  10960. }
  10961. }
  10962. }
  10963. json_object_put(GetConfiguration);
  10964. UnknownKeynum = 0;
  10965. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10966. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10967. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10968. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10969. if(n_keys != 0)
  10970. {
  10971. for(int i=0;i<n_keys;i++)
  10972. {
  10973. getKeyValue(requestKey[i]);
  10974. }
  10975. }
  10976. else
  10977. {
  10978. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10979. getKeyValue("");
  10980. }
  10981. processUnkownKey();
  10982. sendGetConfigurationConfirmation(uuid);
  10983. return result;
  10984. }
  10985. static char fnamePlusPath[100]={0};
  10986. static char fnamePWithNoPath[60]={0};
  10987. void checkUploadLog(void)
  10988. {
  10989. FILE *fp;
  10990. /* Open the command for reading. */
  10991. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10992. if (fp == NULL) {
  10993. DEBUG_WARN("Failed to run command\n" );
  10994. exit(1);
  10995. }
  10996. int ftppathlen = 0;
  10997. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10998. int i = 0;
  10999. /* Read the output a line at a time - output it. */
  11000. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  11001. if(i==0)
  11002. {
  11003. ftppathlen = strlen(fnamePlusPath);
  11004. DEBUG_INFO("%s\n", fnamePlusPath);
  11005. fnamePlusPath[ftppathlen]='\0';
  11006. break;
  11007. }
  11008. i= i+1;
  11009. }
  11010. /* close */
  11011. pclose(fp);
  11012. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  11013. {
  11014. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  11015. {
  11016. fnamePlusPath[k]='\0';
  11017. }
  11018. }
  11019. i=1;
  11020. //char fname[60]={0};
  11021. while(i < ftppathlen)
  11022. {
  11023. int len=ftppathlen-i;
  11024. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  11025. {
  11026. DEBUG_INFO("compare '/' all right\n");
  11027. break;
  11028. }
  11029. i=i+1;
  11030. }
  11031. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11032. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11033. fnamePWithNoPath[i+1] = '\0';
  11034. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11035. {
  11036. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11037. {
  11038. fnamePWithNoPath[j]='\0';
  11039. }
  11040. }
  11041. FILE* fp1 = fopen(fnamePlusPath, "r");
  11042. if (fp1)
  11043. {
  11044. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11045. // file exists
  11046. fclose(fp1);
  11047. }
  11048. else
  11049. {
  11050. // file doesn't exist
  11051. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11052. }
  11053. }
  11054. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11055. {
  11056. mtrace();
  11057. int result = FAIL;
  11058. time_t CurrentTime;
  11059. struct tm *tm;
  11060. pthread_t th_Status;
  11061. CurrentTime = time(NULL);
  11062. tm = localtime(&CurrentTime);
  11063. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11064. 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);
  11065. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11066. if(!interLock.isGetDiagnosticGoing)
  11067. {
  11068. interLock.isGetDiagnosticGoing = 1;
  11069. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11070. sleep(1);
  11071. }
  11072. else
  11073. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11074. return result;
  11075. }
  11076. void* GetDiagnosticsProcess(void* data)
  11077. {
  11078. pthread_detach(pthread_self());
  11079. mtrace();
  11080. int retriesInt=0, retryIntervalInt=0;
  11081. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11082. 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};
  11083. int port=0;
  11084. int isSuccess = FALSE;
  11085. char cmdBuf[2048];
  11086. struct tm *tmNow;
  11087. time_t CurrentTime;
  11088. struct tm tmStart;
  11089. struct tm tmStop;
  11090. CurrentTime = time(NULL);
  11091. tmNow=localtime(&CurrentTime);
  11092. uint16_t targetYear, targetMonth;
  11093. json_object *GetDiagnostics;
  11094. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11095. GetDiagnostics = json_tokener_parse(data);
  11096. if(!is_error(GetDiagnostics))
  11097. {
  11098. // Required data
  11099. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11100. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11101. // Optional data
  11102. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11103. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11104. else
  11105. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11106. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11107. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11108. else
  11109. retryIntervalInt = 30;
  11110. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11111. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11112. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11113. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11114. }
  11115. json_object_put(GetDiagnostics);
  11116. // Pack log to compress file
  11117. 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) &&
  11118. (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))
  11119. {
  11120. // Pack system log
  11121. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11122. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11123. targetYear = tmStart.tm_year;
  11124. targetMonth = tmStart.tm_mon;
  11125. do
  11126. {
  11127. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11128. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11129. if(targetMonth+1>=13)
  11130. {
  11131. targetYear += 1;
  11132. targetMonth = 1;
  11133. }
  11134. else
  11135. {
  11136. targetMonth += 1;
  11137. }
  11138. }while((targetYear < (tmNow->tm_year+1900)) ||
  11139. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11140. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11141. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11142. system(cmdBuf);
  11143. // Pack charging & event log
  11144. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11145. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11146. targetYear = tmStart.tm_year;
  11147. targetMonth = tmStart.tm_mon;
  11148. do
  11149. {
  11150. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11151. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  11152. if(targetMonth+1>=13)
  11153. {
  11154. targetYear += 1;
  11155. targetMonth = 1;
  11156. }
  11157. else
  11158. {
  11159. targetMonth += 1;
  11160. }
  11161. }while((targetYear < (tmNow->tm_year+1900)) ||
  11162. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11163. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11164. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11165. system(cmdBuf);
  11166. // Combine log file
  11167. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11168. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11169. }
  11170. else
  11171. {
  11172. system("exec /root/logPackTools 'log' 6");
  11173. }
  11174. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11175. system(cmdBuf);
  11176. checkUploadLog();
  11177. //****************location*******************/
  11178. if(strcmp(locationstr,"")==0)
  11179. {
  11180. DEBUG_INFO("location is <Empty>!\n");
  11181. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11182. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11183. goto end;
  11184. }
  11185. memset(protocol, 0, ARRAY_SIZE(protocol));
  11186. memset(user, 0, ARRAY_SIZE(user) );
  11187. memset(password, 0, ARRAY_SIZE(password));
  11188. memset(host, 0, ARRAY_SIZE(host));
  11189. memset(path, 0, ARRAY_SIZE(path));
  11190. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11191. memset(host1, 0, ARRAY_SIZE(host1));
  11192. memset(path1, 0, ARRAY_SIZE(path1));
  11193. /*location: ftp://user:password@host:port/path*/
  11194. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11195. if((access(fnamePlusPath,F_OK))!=-1)
  11196. {
  11197. DEBUG_INFO("fnamePlusPath exist.\n");
  11198. }
  11199. else
  11200. {
  11201. DEBUG_INFO("fnamePlusPath not exist!\n");
  11202. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11203. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11204. goto end;
  11205. }
  11206. if(strchr(locationstr,'@')==NULL)
  11207. {
  11208. sscanf(locationstr,
  11209. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11210. protocol, host, &port, path);
  11211. strcpy(user,"anonymous");
  11212. strcpy(password,"");
  11213. }
  11214. else
  11215. {
  11216. //DEBUG_INFO("pch=%s\n", pch);
  11217. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11218. protocol, user, password, host, &port, path);
  11219. }
  11220. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11221. {
  11222. DEBUG_INFO("protocol is not ftp/http ! \n");
  11223. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11224. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11225. goto end;
  11226. }
  11227. if(strncmp(locationstr,"http", 4) == 0)
  11228. {
  11229. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11230. sprintf(ftppath,"/%s", path);
  11231. do
  11232. {
  11233. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11234. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11235. sleep(3);
  11236. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11237. if(!isSuccess)
  11238. {
  11239. DEBUG_INFO("Diagnostics fail.\n");
  11240. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11242. sleep(retryIntervalInt);
  11243. }
  11244. else
  11245. {
  11246. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11247. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11248. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11249. }
  11250. retriesInt--;
  11251. }while((isSuccess == 0)&&(retriesInt >= 0));
  11252. }
  11253. else
  11254. {
  11255. sscanf(host,"%[^/]%s",host1, path1);
  11256. if(strlen(path) > 0)
  11257. sprintf(ftppath,"/%s", path);
  11258. else
  11259. sprintf(ftppath,"/%s", path1);
  11260. int ftppathlen=strlen(ftppath);
  11261. int i=1;
  11262. char filenametemp[50];
  11263. while(i < ftppathlen)
  11264. {
  11265. int len=ftppathlen-i;
  11266. if(ftppath[len]== 47) // '/' ascll code: 47
  11267. {
  11268. DEBUG_INFO("find '/' all right\n");
  11269. break;
  11270. }
  11271. i=i+1;
  11272. }
  11273. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11274. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11275. filenametemp[i+1] = 0;
  11276. if(port == 0)
  11277. port = 21;
  11278. do
  11279. {
  11280. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11281. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11282. sleep(3);
  11283. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11284. if(!isSuccess)
  11285. {
  11286. DEBUG_INFO("Diagnostics fail.\n");
  11287. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11288. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11289. sleep(retryIntervalInt);
  11290. }
  11291. else
  11292. {
  11293. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11294. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11295. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11296. }
  11297. retriesInt--;
  11298. }while((!isSuccess)&&(retriesInt >= 0));
  11299. }
  11300. end:
  11301. system("rm -f /mnt/*");
  11302. sleep(5);
  11303. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11304. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11305. interLock.isGetDiagnosticGoing = 0;
  11306. pthread_exit(NULL);
  11307. }
  11308. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11309. {
  11310. mtrace();
  11311. int result = FAIL;
  11312. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11313. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11314. {
  11315. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11316. locallistVersion = -1;
  11317. }
  11318. else
  11319. {
  11320. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11321. locallistVersion = 0;
  11322. OCPP_getListVerion();
  11323. }
  11324. //from db.OCPP_getListVerion
  11325. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11326. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11327. sendGetLocalListVersionConfirmation(uuid,"");
  11328. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11329. return result;
  11330. }
  11331. int handleRemoteStartRequest(char *uuid, char *payload)
  11332. {
  11333. mtrace();
  11334. int result = PASS;
  11335. int connectorIdInt=-1;
  11336. int tempIndex = 0;
  11337. char comfirmstr[20]={0};
  11338. char cmdBuf[512];
  11339. json_object *RemoteStartTransaction;
  11340. FILE *fp;
  11341. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11342. if(server_pending == TRUE)
  11343. {
  11344. result = FAIL;
  11345. }
  11346. RemoteStartTransaction = json_tokener_parse(payload);
  11347. if(!is_error(RemoteStartTransaction))
  11348. {
  11349. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11350. {
  11351. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11352. }
  11353. else
  11354. {
  11355. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11356. {
  11357. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11358. {
  11359. connectorIdInt = (gun_index+1);
  11360. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11361. break;
  11362. }
  11363. }
  11364. }
  11365. if(connectorIdInt == 0)
  11366. {
  11367. DEBUG_WARN("Connector id shall not equal 0.\n");
  11368. result = FAIL;
  11369. }
  11370. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11371. {
  11372. DEBUG_WARN("idTag should not be NULL.\n");
  11373. result = FAIL;
  11374. }
  11375. else if(connectorIdInt == -1)
  11376. {
  11377. DEBUG_INFO("Connector id does not specific.\n");
  11378. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11379. {
  11380. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11381. // Required data
  11382. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11383. // Optional data
  11384. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11385. {
  11386. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11387. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11388. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11389. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11390. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11391. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11392. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11393. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11394. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11395. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11396. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11397. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11398. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11399. {
  11400. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  11401. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11402. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  11403. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11404. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  11405. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11406. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  11407. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11408. {
  11409. 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++)
  11410. {
  11411. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11412. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11413. 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)
  11414. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11415. }
  11416. }
  11417. }
  11418. }
  11419. else
  11420. {
  11421. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11422. }
  11423. }
  11424. }
  11425. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11426. {
  11427. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11428. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11429. // Required data
  11430. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11431. // Optional data
  11432. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11433. {
  11434. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11435. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11436. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11437. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11438. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11439. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11440. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11441. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11442. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11443. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11444. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11445. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11446. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11447. {
  11448. 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")));
  11449. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11450. 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"));
  11451. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11452. 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"));
  11453. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11454. 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")));
  11455. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11456. {
  11457. 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++)
  11458. {
  11459. 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"));
  11460. 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"));
  11461. 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)
  11462. 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"));
  11463. }
  11464. }
  11465. }
  11466. }
  11467. else
  11468. {
  11469. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11470. }
  11471. }
  11472. else
  11473. {
  11474. DEBUG_WARN("Connector id is over maximun value.\n");
  11475. result = FAIL;
  11476. }
  11477. }
  11478. if(result == PASS)
  11479. {
  11480. if(connectorIdInt > 0)
  11481. {
  11482. //check Transaction active
  11483. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11484. {
  11485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11486. {
  11487. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11488. }
  11489. else
  11490. {
  11491. tempIndex = connectorIdInt -1;
  11492. }
  11493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11494. {
  11495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11496. {
  11497. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11498. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11499. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11500. {
  11501. //Reserved
  11502. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11503. }
  11504. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11505. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11506. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11507. {
  11508. //Reserved
  11509. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11510. {
  11511. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11512. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11513. goto end;
  11514. }
  11515. }
  11516. else
  11517. {
  11518. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11519. {
  11520. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11521. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11522. goto end;
  11523. }
  11524. }//END FOR ELSE
  11525. }
  11526. }// END FOR CHAdeMO_QUANTITY
  11527. }
  11528. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11529. {
  11530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11531. {
  11532. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11533. }
  11534. else
  11535. {
  11536. tempIndex = connectorIdInt -1;
  11537. }
  11538. for (int index = 0; index < CCS_QUANTITY; index++)
  11539. {
  11540. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11541. {
  11542. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11543. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11544. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11545. {
  11546. //Reserved
  11547. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11548. }
  11549. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11550. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11551. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11552. {
  11553. //Reserved
  11554. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11555. {
  11556. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11557. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11558. goto end;
  11559. }
  11560. }
  11561. else
  11562. {
  11563. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11564. {
  11565. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11566. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11567. goto end;
  11568. }
  11569. }// END FOR ELSE
  11570. }
  11571. }// END FOR CCS_QUANTITY
  11572. }
  11573. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11574. {
  11575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11576. {
  11577. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11578. }
  11579. else
  11580. {
  11581. tempIndex = connectorIdInt -1;
  11582. }
  11583. for (int index = 0; index < GB_QUANTITY; index++)
  11584. {
  11585. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11586. {
  11587. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11588. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11589. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11590. {
  11591. //Reserved
  11592. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11593. }
  11594. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11595. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11596. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11597. {
  11598. //Reserved
  11599. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11600. {
  11601. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11602. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11603. goto end;
  11604. }
  11605. }
  11606. else
  11607. {
  11608. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11609. {
  11610. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11611. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11612. goto end;
  11613. }
  11614. }// END FOR ELSE
  11615. }
  11616. } // END FOR GB_QUANTITY
  11617. }
  11618. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11619. {
  11620. tempIndex = connectorIdInt -1;
  11621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11622. {
  11623. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11624. {
  11625. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11626. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11627. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11628. {
  11629. //Reserved
  11630. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11631. }
  11632. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11633. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11634. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11635. {
  11636. //Reserved
  11637. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11638. {
  11639. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11640. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11641. goto end;
  11642. }
  11643. }
  11644. else
  11645. {
  11646. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11647. {
  11648. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11649. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11650. goto end;
  11651. }
  11652. }// END FOR ELSE
  11653. }
  11654. } // END FOR GB_QUANTITY
  11655. }
  11656. else
  11657. {
  11658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11659. {
  11660. tempIndex = 2;
  11661. }
  11662. else
  11663. {
  11664. tempIndex = connectorIdInt -1;
  11665. }
  11666. for (int index = 0; index < AC_QUANTITY; index++)
  11667. {
  11668. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11669. {
  11670. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11671. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11672. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11673. {
  11674. //Reserved
  11675. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11676. }
  11677. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11678. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11679. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11680. {
  11681. //Reserved
  11682. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11683. {
  11684. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11685. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11686. goto end;
  11687. }
  11688. }
  11689. else
  11690. {
  11691. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11692. {
  11693. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11694. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11695. goto end;
  11696. }
  11697. }//END FOR ELSE
  11698. }
  11699. }// END FOR AC_QUANTITY
  11700. }
  11701. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11702. {
  11703. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11704. {
  11705. // Save profile to file
  11706. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11707. system(cmdBuf);
  11708. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11709. fp = fopen(cmdBuf, "w");
  11710. 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));
  11711. fclose(fp);
  11712. }
  11713. else
  11714. {
  11715. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11716. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11717. goto end;
  11718. }
  11719. }
  11720. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11721. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11722. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11723. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11724. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11725. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11726. }
  11727. else
  11728. {
  11729. uint8_t isHasIdleConnector = FALSE;
  11730. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11731. {
  11732. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11733. {
  11734. isHasIdleConnector = TRUE;
  11735. break;
  11736. }
  11737. }
  11738. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11739. {
  11740. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11741. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11742. {
  11743. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11744. {
  11745. // Save profile to file
  11746. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11747. system(cmdBuf);
  11748. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11749. fp = fopen(cmdBuf, "w");
  11750. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11751. fclose(fp);
  11752. refreshStartTimer(&clientTime.RemoteStartWait);
  11753. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11754. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11755. }
  11756. else
  11757. {
  11758. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11759. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11760. }
  11761. }
  11762. else
  11763. {
  11764. refreshStartTimer(&clientTime.RemoteStartWait);
  11765. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11766. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11767. }
  11768. }
  11769. else
  11770. {
  11771. DEBUG_INFO("There is not any connector is idle.\n");
  11772. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11773. }
  11774. }
  11775. }
  11776. else
  11777. {
  11778. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11779. }
  11780. end:
  11781. json_object_put(RemoteStartTransaction);
  11782. sendRemoteStartConfirmation(uuid, comfirmstr);
  11783. return result;
  11784. }
  11785. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11786. {
  11787. mtrace();
  11788. int result = FAIL;
  11789. int match = FALSE;
  11790. int GunNO = 0;
  11791. int tempIndex = 0;
  11792. int transactionIdInt=0;
  11793. int transactionIdIsNULL= TRUE;
  11794. char comfirmstr[20];
  11795. json_object *RemoteStopTransaction;
  11796. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11797. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11798. if(server_pending == TRUE)
  11799. {
  11800. return 0;
  11801. }
  11802. RemoteStopTransaction = json_tokener_parse(payload);
  11803. if(!is_error(RemoteStopTransaction))
  11804. {
  11805. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11806. {
  11807. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11808. transactionIdIsNULL = FALSE;
  11809. }
  11810. }
  11811. json_object_put(RemoteStopTransaction);
  11812. if(transactionIdIsNULL == FALSE)
  11813. {
  11814. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11815. {
  11816. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11817. {
  11818. //check Transaction active
  11819. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11820. {
  11821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11822. {
  11823. tempIndex = ((gun_index==2) ? 1: 0);
  11824. }
  11825. else
  11826. {
  11827. tempIndex = gun_index;
  11828. }
  11829. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11830. {
  11831. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11832. {
  11833. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11834. {
  11835. match = TRUE;
  11836. GunNO = gun_index;
  11837. }
  11838. }
  11839. }// END FOR CHAdeMO_QUANTITY
  11840. }
  11841. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11842. {
  11843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11844. {
  11845. tempIndex = ((gun_index==2) ? 1: 0);
  11846. }
  11847. else
  11848. {
  11849. tempIndex = gun_index;
  11850. }
  11851. for (int index = 0; index < CCS_QUANTITY; index++)
  11852. {
  11853. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11854. {
  11855. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11856. {
  11857. match = TRUE;
  11858. GunNO = gun_index;
  11859. }
  11860. }
  11861. }// END FOR CCS_QUANTITY
  11862. }
  11863. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11864. {
  11865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11866. {
  11867. tempIndex = ((gun_index==2) ? 1: 0);
  11868. }
  11869. else
  11870. {
  11871. tempIndex = gun_index;
  11872. }
  11873. for (int index = 0; index < GB_QUANTITY; index++)
  11874. {
  11875. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11876. {
  11877. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11878. {
  11879. match = TRUE;
  11880. GunNO = gun_index;
  11881. }
  11882. }
  11883. }// END FOR GB_QUANTITY
  11884. }
  11885. else if(gunType[gun_index] == GUN_TYPE_DO)
  11886. {
  11887. tempIndex = gun_index;
  11888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11889. {
  11890. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11891. {
  11892. 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
  11893. {
  11894. match = TRUE;
  11895. GunNO = gun_index;
  11896. }
  11897. }
  11898. }// END FOR GB_QUANTITY
  11899. }
  11900. else
  11901. {
  11902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11903. {
  11904. tempIndex = 2;
  11905. }
  11906. else
  11907. {
  11908. tempIndex = gun_index;
  11909. }
  11910. for (int index = 0; index < AC_QUANTITY; index++)
  11911. {
  11912. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11913. {
  11914. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11915. {
  11916. match = TRUE;
  11917. GunNO = gun_index;
  11918. }
  11919. }
  11920. }// END FOR CHAdeMO_QUANTITY
  11921. } // END FOR AC ELSE
  11922. }// CHECK IF ResponseTransactionId == transactionIdInt
  11923. }//END FOR
  11924. if( match == TRUE)
  11925. {
  11926. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11927. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11928. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11929. }
  11930. else
  11931. {
  11932. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11933. }
  11934. }
  11935. else
  11936. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11937. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11938. return result;
  11939. }
  11940. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11941. {
  11942. mtrace();
  11943. int result = FAIL;
  11944. int connectorIdInt=0, reservationIdInt=0;
  11945. int tempIndex = 0;
  11946. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11947. char comfirmstr[20]={0};
  11948. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11949. int c = 0;
  11950. char *loc;
  11951. //char *ptr;
  11952. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11953. strcpy(sstrtemp, stringtrimspace(payload));
  11954. //***(1)connectorId ****/
  11955. c=0;
  11956. loc = strstr(sstrtemp, "connectorId");
  11957. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11958. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11959. {
  11960. sstr[c] = loc[strlen("connectorId")+2+c];
  11961. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11962. c++;
  11963. }
  11964. sstr[c] = '\0';
  11965. connectorIdInt = atoi(sstr);
  11966. //***(2)expiryDate ****/
  11967. loc = strstr(sstrtemp, "expiryDate");
  11968. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11969. c = 0;
  11970. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11971. {
  11972. sstr[c] = loc[3+strlen("expiryDate")+c];
  11973. c++;
  11974. }
  11975. sstr[c] = '\0';
  11976. strcpy(expiryDatestr, sstr);
  11977. //***(3)idTag ****/
  11978. loc = strstr(sstrtemp, "idTag");
  11979. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11980. c = 0;
  11981. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11982. {
  11983. sstr[c] = loc[3+strlen("idTag")+c];
  11984. c++;
  11985. }
  11986. sstr[c] = '\0';
  11987. strcpy(idTagstr, sstr);
  11988. //***(4)parentIdTag ****/
  11989. loc = strstr(sstrtemp, "parentIdTag");
  11990. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11991. c = 0;
  11992. if(loc == NULL)
  11993. {
  11994. strcpy(parentIdTagstr, "");
  11995. }
  11996. else
  11997. {
  11998. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11999. {
  12000. sstr[c] = loc[3+strlen("parentIdTag")+c];
  12001. c++;
  12002. }
  12003. sstr[c] = '\0';
  12004. strcpy(parentIdTagstr, sstr);
  12005. }
  12006. //***(5)reservationId ****/
  12007. c=0;
  12008. loc = strstr(sstrtemp, "reservationId");
  12009. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12010. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  12011. {
  12012. sstr[c] = loc[strlen("reservationId")+2+c];
  12013. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12014. c++;
  12015. }
  12016. sstr[c] = '\0';
  12017. reservationIdInt = atoi(sstr);
  12018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12019. /*
  12020. enum SYSTEM_STATUS
  12021. {
  12022. SYS_MODE_BOOTING = 0,
  12023. SYS_MODE_IDLE = 1,
  12024. SYS_MODE_AUTHORIZING = 2,
  12025. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12026. SYS_MODE_REASSIGN = 4,
  12027. SYS_MODE_PREPARING = 5,
  12028. SYS_MODE_PREPARE_FOR_EV = 6,
  12029. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12030. SYS_MODE_CHARGING = 8,
  12031. SYS_MODE_TERMINATING = 9,
  12032. SYS_MODE_COMPLETE = 10,
  12033. SYS_MODE_ALARM = 11,
  12034. SYS_MODE_FAULT = 12,
  12035. SYS_MODE_RESERVATION = 13,
  12036. SYS_MODE_BOOKING = 14,
  12037. SYS_MODE_MAINTAIN = 15,
  12038. SYS_MODE_DEBUG = 16,
  12039. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12040. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12041. SYS_MODE_UPDATE = 19
  12042. };
  12043. */
  12044. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12045. {
  12046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12047. goto end;
  12048. }
  12049. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12050. {
  12051. //check Transaction active
  12052. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12053. {
  12054. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12055. {
  12056. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12057. }
  12058. else
  12059. {
  12060. tempIndex = connectorIdInt -1;
  12061. }
  12062. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12063. {
  12064. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12065. {
  12066. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12067. {
  12068. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12069. {
  12070. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12071. {
  12072. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12073. {
  12074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12075. }
  12076. else
  12077. {
  12078. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12079. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12080. }
  12081. }
  12082. 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'))
  12083. {
  12084. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12085. }
  12086. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12087. {
  12088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12089. }
  12090. else
  12091. {
  12092. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12093. }
  12094. }
  12095. 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
  12096. {
  12097. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12098. }
  12099. }
  12100. else
  12101. {
  12102. //replace reservation
  12103. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12105. }
  12106. }
  12107. } // END FOR CHAdeMO_QUANTITY
  12108. }
  12109. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12110. {
  12111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12112. {
  12113. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12114. }
  12115. else
  12116. {
  12117. tempIndex = connectorIdInt -1;
  12118. }
  12119. for (int index = 0; index < CCS_QUANTITY; index++)
  12120. {
  12121. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12122. {
  12123. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12124. {
  12125. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12126. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12127. {
  12128. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12129. {
  12130. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12131. {
  12132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12133. }
  12134. else
  12135. {
  12136. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12138. }
  12139. }
  12140. 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'))
  12141. {
  12142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12143. }
  12144. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12145. {
  12146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12147. }
  12148. else
  12149. {
  12150. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12151. }
  12152. }
  12153. 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
  12154. {
  12155. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12156. }
  12157. }
  12158. else
  12159. {
  12160. //replace reservation
  12161. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12163. }
  12164. }
  12165. } // END FOR CCS_QUANTITY
  12166. }
  12167. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12168. {
  12169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12170. {
  12171. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12172. }
  12173. else
  12174. {
  12175. tempIndex = connectorIdInt -1;
  12176. }
  12177. for (int index = 0; index < GB_QUANTITY; index++)
  12178. {
  12179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12180. {
  12181. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12182. {
  12183. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12184. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12185. {
  12186. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12187. {
  12188. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12189. {
  12190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12191. }
  12192. else
  12193. {
  12194. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12195. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12196. }
  12197. }
  12198. 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'))
  12199. {
  12200. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12201. }
  12202. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12203. {
  12204. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12205. }
  12206. else
  12207. {
  12208. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12209. }
  12210. }
  12211. 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
  12212. {
  12213. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12214. }
  12215. }
  12216. else
  12217. {
  12218. //replace reservation
  12219. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12221. }
  12222. }
  12223. }// END FOR GB_QUANTITY
  12224. }
  12225. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12226. {
  12227. tempIndex = connectorIdInt -1;
  12228. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12229. {
  12230. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12231. {
  12232. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12233. {
  12234. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12235. 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
  12236. {
  12237. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12238. {
  12239. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12240. {
  12241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12242. }
  12243. else
  12244. {
  12245. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12246. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12247. }
  12248. }
  12249. 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'))
  12250. {
  12251. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12252. }
  12253. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12254. {
  12255. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12256. }
  12257. else
  12258. {
  12259. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12260. }
  12261. }
  12262. 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
  12263. {
  12264. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12265. }
  12266. }
  12267. else
  12268. {
  12269. //replace reservation
  12270. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12272. }
  12273. }
  12274. }// END FOR GB_QUANTITY
  12275. }
  12276. else
  12277. {
  12278. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12279. {
  12280. tempIndex = 2;
  12281. }
  12282. else
  12283. {
  12284. tempIndex = (connectorIdInt -1);
  12285. }
  12286. for (int index = 0; index < AC_QUANTITY; index++)
  12287. {
  12288. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12289. {
  12290. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12291. {
  12292. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12293. {
  12294. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12295. {
  12296. 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))
  12297. {
  12298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12299. }
  12300. else
  12301. {
  12302. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12303. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12304. }
  12305. }
  12306. 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'))
  12307. {
  12308. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12309. }
  12310. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12311. {
  12312. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12313. }
  12314. else
  12315. {
  12316. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12317. }
  12318. }
  12319. 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
  12320. {
  12321. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12322. }
  12323. }
  12324. else
  12325. {
  12326. //replace reservation
  12327. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12329. }
  12330. }
  12331. } // END FOR AC_QUANTITY
  12332. }
  12333. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12334. }
  12335. else if(connectorIdInt == 0)
  12336. {
  12337. //check Transaction active
  12338. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12339. {
  12340. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12341. {
  12342. 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'))
  12343. {
  12344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12345. goto end;
  12346. }
  12347. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12348. {
  12349. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12350. goto end;
  12351. }
  12352. 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
  12353. {
  12354. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12355. goto end;
  12356. }
  12357. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12358. {
  12359. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12360. goto end;
  12361. }
  12362. }
  12363. }// END FOR CHAdeMO_QUANTITY
  12364. for (int index = 0; index < CCS_QUANTITY; index++)
  12365. {
  12366. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12367. {
  12368. 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'))
  12369. {
  12370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12371. goto end;
  12372. }
  12373. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12374. {
  12375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12376. goto end;
  12377. }
  12378. 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
  12379. {
  12380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12381. goto end;
  12382. }
  12383. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12384. {
  12385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12386. goto end;
  12387. }
  12388. }
  12389. } // END FOR CCS_QUANTITY
  12390. for (int index = 0; index < GB_QUANTITY; index++)
  12391. {
  12392. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12393. {
  12394. 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'))
  12395. {
  12396. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12397. goto end;
  12398. }
  12399. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12400. {
  12401. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12402. goto end;
  12403. }
  12404. 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
  12405. {
  12406. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12407. goto end;
  12408. }
  12409. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12410. {
  12411. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12412. goto end;
  12413. }
  12414. }
  12415. } // END FOR GB_QUANTITY
  12416. for (int index = 0; index < AC_QUANTITY; index++)
  12417. {
  12418. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12419. {
  12420. 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'))
  12421. {
  12422. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12423. goto end;
  12424. }
  12425. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12426. {
  12427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12428. goto end;
  12429. }
  12430. 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
  12431. {
  12432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12433. goto end;
  12434. }
  12435. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12436. {
  12437. 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))
  12438. {
  12439. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12440. goto end;
  12441. }
  12442. }
  12443. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12444. {
  12445. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12446. goto end;
  12447. }
  12448. }
  12449. }// END FOR AC_QUANTITY
  12450. //The connectorId is 0
  12451. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12452. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12453. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12454. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12455. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12456. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12457. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12458. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12459. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12460. result = TRUE;
  12461. return result;
  12462. }
  12463. else
  12464. {
  12465. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12466. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12467. }
  12468. if(strcmp(comfirmstr,"Accepted") == 0)
  12469. {
  12470. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12471. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12472. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12473. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12474. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12475. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12476. result = TRUE;
  12477. return result;
  12478. }
  12479. end:
  12480. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12481. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12482. return result;
  12483. }
  12484. int handleResetRequest(char *uuid, char *payload)
  12485. {
  12486. mtrace();
  12487. int result = FAIL;
  12488. char sstr[10]={0},sstrtemp[30]={ 0 };
  12489. char typestr[10]={0};
  12490. char comfirmstr[20]={0};
  12491. int c = 0;
  12492. char *loc;
  12493. DEBUG_INFO("handleResetRequest...\n");
  12494. strcpy(sstrtemp, stringtrimspace(payload));
  12495. loc = strstr(sstrtemp, "type");
  12496. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12497. c = 0;
  12498. while (loc[3+strlen("type")+c] != '\"')
  12499. {
  12500. sstr[c] = loc[3+strlen("type")+c];
  12501. c++;
  12502. }
  12503. sstr[c] = '\0';
  12504. strcpy(typestr,sstr);
  12505. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12506. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12507. {
  12508. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12509. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12510. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12511. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12512. }
  12513. else
  12514. {
  12515. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12516. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12517. result = PASS;
  12518. }
  12519. sendResetConfirmation(uuid, comfirmstr);
  12520. return result;
  12521. }
  12522. int handleSendLocalListRequest(char *uuid, char *payload)
  12523. {
  12524. mtrace();
  12525. int result = FAIL;
  12526. char comfirmstr[20];
  12527. int checkState_Faulted = FALSE;
  12528. json_object *SendLocalList;
  12529. DEBUG_INFO("handleSendLocalListRequest...\n");
  12530. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12531. {
  12532. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12533. goto end;
  12534. }
  12535. //check Charge Point state
  12536. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12537. {
  12538. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12539. {
  12540. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12541. }
  12542. }
  12543. for (int index = 0; index < CCS_QUANTITY; index++)
  12544. {
  12545. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12546. {
  12547. checkState_Faulted = TRUE; //OCPP Status
  12548. }
  12549. }
  12550. for (int index = 0; index < GB_QUANTITY; index++)
  12551. {
  12552. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12553. {
  12554. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12555. }
  12556. }
  12557. //check Charge Point state
  12558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12559. {
  12560. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12561. {
  12562. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12563. }
  12564. }
  12565. //check Charge Point state
  12566. for (int index = 0; index < AC_QUANTITY; index++)
  12567. {
  12568. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12569. {
  12570. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12571. }
  12572. }
  12573. if(checkState_Faulted == TRUE)
  12574. {
  12575. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12576. goto end;
  12577. }
  12578. // Parsing payload
  12579. SendLocalList = json_tokener_parse(payload);
  12580. if(!is_error(SendLocalList))
  12581. {
  12582. // Required data
  12583. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12584. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12585. // Optional data
  12586. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12587. {
  12588. //Check UpdateType
  12589. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12590. {
  12591. //Local list full update
  12592. DEBUG_INFO("Local list full update.\n");
  12593. locallistVersion = 0;
  12594. OCPP_getListVerion();
  12595. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12596. {
  12597. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12598. goto end;
  12599. }
  12600. OCPP_cleanLocalList();
  12601. }
  12602. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12603. {
  12604. //Local list different update
  12605. DEBUG_INFO("Local list different update.\n");
  12606. locallistVersion = 0;
  12607. OCPP_getListVerion();
  12608. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12609. {
  12610. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12611. goto end;
  12612. }
  12613. }
  12614. else
  12615. {
  12616. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12617. goto end;
  12618. }
  12619. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12620. {
  12621. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12622. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12623. goto end;
  12624. }
  12625. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12626. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12627. {
  12628. 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")));
  12629. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12630. {
  12631. 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")));
  12632. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12633. 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")));
  12634. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12635. 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")));
  12636. }
  12637. // Add to db
  12638. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12639. {
  12640. //Local list full update
  12641. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12642. idx,
  12643. ShmOCPP16Data->SendLocalList.ListVersion,
  12644. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12645. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12646. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12647. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12648. // update list
  12649. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12650. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12651. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12652. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12653. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12654. }
  12655. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12656. {
  12657. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12658. idx,
  12659. ShmOCPP16Data->SendLocalList.ListVersion,
  12660. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12661. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12662. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12663. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12664. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12665. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12666. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12667. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12668. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12669. }
  12670. }
  12671. }
  12672. else
  12673. {
  12674. //Check UpdateType
  12675. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12676. {
  12677. //Local list full update
  12678. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12679. OCPP_cleanLocalList();
  12680. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12681. goto end;
  12682. }
  12683. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12684. {
  12685. //Local list different update
  12686. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12687. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12688. goto end;
  12689. }
  12690. }
  12691. result = PASS;
  12692. }
  12693. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12694. end:
  12695. json_object_put(SendLocalList);
  12696. sendSendLocalListConfirmation(uuid, comfirmstr);
  12697. return result;
  12698. }
  12699. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12700. {
  12701. mtrace();
  12702. int result = FAIL;
  12703. struct StructSetChargingProfile SetProfileReq = {0};
  12704. int tempchargingProfileIdInt;
  12705. int tempstackLevelInt;
  12706. int chargingSchedulePeriodCount = 0;
  12707. char comfirmstr[20]={0};
  12708. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12709. char rmFileCmd[128]={0};
  12710. int profileQuantity = 0;
  12711. int replaceableProfileCnt = 0;
  12712. json_object *SetChargingProfile;
  12713. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12714. SetChargingProfile = json_tokener_parse(payload);
  12715. if(!is_error(SetChargingProfile))
  12716. {
  12717. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12718. {
  12719. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12720. }
  12721. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12722. {
  12723. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12724. {
  12725. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12726. }
  12727. else
  12728. {
  12729. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12730. DEBUG_WARN("Cannot find chargingProfileId field.");
  12731. goto end;
  12732. }
  12733. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12734. {
  12735. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12736. }
  12737. else
  12738. {
  12739. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12740. DEBUG_WARN("Cannot find stackLevel field.");
  12741. goto end;
  12742. }
  12743. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12744. {
  12745. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12746. }
  12747. else
  12748. {
  12749. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12750. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12751. goto end;
  12752. }
  12753. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12754. {
  12755. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12756. }
  12757. else
  12758. {
  12759. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12760. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12761. goto end;
  12762. }
  12763. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12764. {
  12765. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12766. }
  12767. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12768. {
  12769. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12770. }
  12771. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12772. {
  12773. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12774. }
  12775. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12776. {
  12777. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12778. }
  12779. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12780. {
  12781. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12782. {
  12783. 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")));
  12784. }
  12785. else
  12786. {
  12787. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12788. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12789. goto end;
  12790. }
  12791. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12792. {
  12793. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12794. }
  12795. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12796. {
  12797. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12798. }
  12799. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12800. {
  12801. 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")));
  12802. }
  12803. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12804. {
  12805. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12806. if(chargingSchedulePeriodCount <= 10)
  12807. {
  12808. 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++)
  12809. {
  12810. 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)
  12811. {
  12812. 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"));
  12813. }
  12814. else
  12815. {
  12816. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12817. DEBUG_WARN("Cannot find startPeriod field.");
  12818. goto end;
  12819. }
  12820. 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)
  12821. {
  12822. 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"));
  12823. }
  12824. else
  12825. {
  12826. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12827. DEBUG_WARN("Cannot find limit field.");
  12828. goto end;
  12829. }
  12830. 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)
  12831. {
  12832. 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"));
  12833. }
  12834. }
  12835. }
  12836. }
  12837. else
  12838. {
  12839. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12840. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12841. goto end;
  12842. }
  12843. }
  12844. else
  12845. {
  12846. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12847. DEBUG_WARN("Cannot find chargingSchedule field.");
  12848. goto end;
  12849. }
  12850. }
  12851. }
  12852. // Profile periods quantity check
  12853. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12854. {
  12855. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12856. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12857. goto end;
  12858. }
  12859. // Check invalid limit
  12860. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12861. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12862. {
  12863. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12864. {
  12865. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12866. {
  12867. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  12868. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12869. {
  12870. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12871. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12872. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12873. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12874. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12875. goto end;
  12876. }
  12877. }
  12878. }
  12879. else
  12880. {
  12881. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12882. {
  12883. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower) ||
  12884. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  12885. {
  12886. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12887. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12888. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12889. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12890. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12891. goto end;
  12892. }
  12893. }
  12894. }
  12895. }
  12896. // Profile purpose info check
  12897. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12898. {
  12899. FILE *fp;
  12900. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12901. if(SetProfileReq.ConnectorId != 0)
  12902. {
  12903. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12904. DEBUG_WARN("Profile connector id is not 0.\n");
  12905. goto end;
  12906. }
  12907. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12908. if (!fp)
  12909. {
  12910. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12911. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12912. }
  12913. else
  12914. {
  12915. char *line = NULL;
  12916. size_t len = 0;
  12917. while(getline(&line, &len, fp) != -1)
  12918. {
  12919. json_object *obj = NULL;
  12920. obj = json_tokener_parse(line);
  12921. if(is_error(obj))
  12922. {
  12923. DEBUG_ERROR("Parse txProfile from file error.\n");
  12924. }
  12925. else
  12926. {
  12927. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12928. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12929. {
  12930. profileQuantity += 1;
  12931. }
  12932. else
  12933. replaceableProfileCnt += 1;
  12934. }
  12935. }
  12936. }
  12937. fclose(fp);
  12938. }
  12939. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12940. {
  12941. FILE *fp;
  12942. char filename[128]={0};
  12943. int tmpProfileQuantity;
  12944. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12945. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12946. {
  12947. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12948. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12949. goto end;
  12950. }
  12951. if(SetProfileReq.ConnectorId == 0)
  12952. {
  12953. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12954. {
  12955. tmpProfileQuantity = 0;
  12956. memset(filename, 0, ARRAY_SIZE(filename));
  12957. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12958. fp = fopen(filename, "r");
  12959. if (!fp)
  12960. {
  12961. DEBUG_INFO("%s does not create.\n", filename);
  12962. fp = fopen(filename, "w+");
  12963. }
  12964. else
  12965. {
  12966. char *line = NULL;
  12967. size_t len = 0;
  12968. while(getline(&line, &len, fp) != -1)
  12969. {
  12970. json_object *obj = NULL;
  12971. obj = json_tokener_parse(line);
  12972. if(is_error(obj))
  12973. {
  12974. DEBUG_ERROR("Parse txProfile from file error.\n");
  12975. }
  12976. else
  12977. {
  12978. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12979. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12980. {
  12981. tmpProfileQuantity += 1;
  12982. }
  12983. else
  12984. replaceableProfileCnt += 1;
  12985. }
  12986. }
  12987. }
  12988. fclose(fp);
  12989. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12990. }
  12991. }
  12992. else
  12993. {
  12994. memset(filename, 0, ARRAY_SIZE(filename));
  12995. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12996. fp = fopen(filename, "r");
  12997. if (!fp)
  12998. {
  12999. DEBUG_INFO("%s does not create.\n", filename);
  13000. fp = fopen(filename, "w+");
  13001. }
  13002. else
  13003. {
  13004. char *line = NULL;
  13005. size_t len = 0;
  13006. while(getline(&line, &len, fp) != -1)
  13007. {
  13008. json_object *obj = NULL;
  13009. obj = json_tokener_parse(line);
  13010. if(is_error(obj))
  13011. {
  13012. DEBUG_ERROR("Parse txProfile from file error.\n");
  13013. }
  13014. else
  13015. {
  13016. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13017. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13018. {
  13019. profileQuantity += 1;
  13020. }
  13021. else
  13022. replaceableProfileCnt += 1;
  13023. }
  13024. }
  13025. }
  13026. fclose(fp);
  13027. }
  13028. }
  13029. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13030. {
  13031. int isMatchTransactiodId= FALSE;
  13032. FILE *fp;
  13033. char filename[128]={0};
  13034. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13035. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13036. if(SetProfileReq.ConnectorId == 0)
  13037. {
  13038. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13039. DEBUG_WARN("Profile connector id is 0.\n");
  13040. goto end;
  13041. }
  13042. int tempIndex = 0;
  13043. //check Transaction active
  13044. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13045. {
  13046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13047. {
  13048. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13049. }
  13050. else
  13051. {
  13052. tempIndex = SetProfileReq.ConnectorId -1;
  13053. }
  13054. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13055. {
  13056. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13057. {
  13058. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13059. {
  13060. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13061. {
  13062. isMatchTransactiodId = TRUE;
  13063. break;
  13064. }
  13065. }
  13066. }
  13067. }
  13068. }
  13069. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13070. {
  13071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13072. {
  13073. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13074. }
  13075. else
  13076. {
  13077. tempIndex = SetProfileReq.ConnectorId -1;
  13078. }
  13079. for (int index = 0; index < CCS_QUANTITY; index++)
  13080. {
  13081. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13082. {
  13083. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13084. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13085. {
  13086. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13087. {
  13088. isMatchTransactiodId = TRUE;
  13089. break;
  13090. }
  13091. }
  13092. }
  13093. }
  13094. }
  13095. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13096. {
  13097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13098. {
  13099. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13100. }
  13101. else
  13102. {
  13103. tempIndex = SetProfileReq.ConnectorId -1;
  13104. }
  13105. for (int index = 0; index < GB_QUANTITY; index++)
  13106. {
  13107. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13108. {
  13109. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13110. {
  13111. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13112. {
  13113. isMatchTransactiodId = TRUE;
  13114. break;
  13115. }
  13116. }
  13117. }
  13118. }
  13119. }
  13120. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13121. {
  13122. tempIndex = SetProfileReq.ConnectorId -1;
  13123. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13124. {
  13125. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13126. {
  13127. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13128. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13129. {
  13130. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13131. {
  13132. isMatchTransactiodId = TRUE;
  13133. break;
  13134. }
  13135. }
  13136. }
  13137. }
  13138. }
  13139. else
  13140. {
  13141. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13142. {
  13143. tempIndex = 2;
  13144. }
  13145. else
  13146. {
  13147. tempIndex = (SetProfileReq.ConnectorId -1);
  13148. }
  13149. for (int index = 0; index < AC_QUANTITY; index++)
  13150. {
  13151. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13152. {
  13153. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13154. {
  13155. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13156. {
  13157. isMatchTransactiodId = TRUE;
  13158. break;
  13159. }
  13160. }
  13161. }
  13162. }
  13163. }
  13164. //check Transaction active
  13165. if(isMatchTransactiodId == FALSE)
  13166. {
  13167. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13168. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13169. goto end;
  13170. }
  13171. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13172. {
  13173. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13174. DEBUG_WARN("Connector id is over max gun number.\n");
  13175. goto end;
  13176. }
  13177. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13178. fp = fopen(filename, "r");
  13179. if (!fp)
  13180. {
  13181. DEBUG_INFO("%s does not create.\n", filename);
  13182. fp = fopen(filename, "w+");
  13183. }
  13184. else
  13185. {
  13186. char *line = NULL;
  13187. size_t len = 0;
  13188. while(getline(&line, &len, fp) != -1)
  13189. {
  13190. json_object *obj = NULL;
  13191. obj = json_tokener_parse(line);
  13192. if(is_error(obj))
  13193. {
  13194. DEBUG_ERROR("Parse txProfile from file error.\n");
  13195. }
  13196. else
  13197. {
  13198. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13199. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13200. {
  13201. profileQuantity += 1;
  13202. }
  13203. else
  13204. replaceableProfileCnt += 1;
  13205. }
  13206. }
  13207. }
  13208. fclose(fp);
  13209. }
  13210. // Check ChargeProfileMaxStackLevel
  13211. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13212. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13213. {
  13214. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13215. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13216. goto end;
  13217. }
  13218. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13219. {
  13220. FILE *fp;
  13221. char dataLine[4096]={0};
  13222. char fnametemp[128]={0};
  13223. int tmpProfileQuantity;
  13224. //Check ChargePointMaxProfile.json exit
  13225. profileQuantity = 0;
  13226. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13227. {
  13228. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13229. //Check Charging Profile Count
  13230. tmpProfileQuantity = 0;
  13231. while(fscanf(fp, "%s", dataLine) != EOF)
  13232. {
  13233. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13234. {
  13235. profileQuantity += 1;
  13236. tmpProfileQuantity += 1;
  13237. }
  13238. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13239. }
  13240. fclose(fp);
  13241. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13242. }
  13243. //Check TxDefaultProfile_%d.json
  13244. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13245. {
  13246. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13247. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13248. if((access(fnametemp,F_OK))!=-1)
  13249. {
  13250. fp = fopen(fnametemp, "r");
  13251. //Check Charging Profile Count
  13252. tmpProfileQuantity = 0;
  13253. while(fscanf(fp, "%s", dataLine) != EOF)
  13254. {
  13255. //DEBUG_INFO("word=%s\n",word);
  13256. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13257. {
  13258. profileQuantity += 1;
  13259. tmpProfileQuantity += 1;
  13260. }
  13261. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13262. }
  13263. fclose(fp);
  13264. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13265. }
  13266. }
  13267. //Check TxProfile_%d.json
  13268. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13269. {
  13270. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13271. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13272. if((access(fnametemp,F_OK))!=-1)
  13273. {
  13274. fp = fopen(fnametemp, "r");
  13275. //Check Charging Profile Count
  13276. tmpProfileQuantity = 0;
  13277. while(fscanf(fp, "%s", dataLine) != EOF)
  13278. {
  13279. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13280. {
  13281. profileQuantity += 1;
  13282. tmpProfileQuantity += 1;
  13283. }
  13284. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13285. }
  13286. fclose(fp);
  13287. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13288. }
  13289. }
  13290. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13291. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13292. // To check total Profile quantity
  13293. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13294. {
  13295. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13296. {
  13297. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13298. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13299. goto end;
  13300. }
  13301. }
  13302. else
  13303. {
  13304. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13305. {
  13306. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13307. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13308. goto end;
  13309. }
  13310. }
  13311. }
  13312. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13313. //**********************************Write to File********************************************************/
  13314. {
  13315. FILE *infile;
  13316. FILE *outfile;
  13317. char dataLine[4096]={0};
  13318. char filename[128]={0};
  13319. int chkChar=0;
  13320. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13321. {
  13322. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13323. {
  13324. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13325. }
  13326. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13327. {
  13328. if(SetProfileReq.ConnectorId==0)
  13329. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13330. else
  13331. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13332. }
  13333. else
  13334. {
  13335. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13336. }
  13337. infile = fopen (filename, "r");
  13338. outfile = fopen (tempfile, "w");
  13339. chkChar = fgetc(infile);
  13340. rewind(infile);
  13341. if(chkChar == EOF)
  13342. {
  13343. // Profile is empty
  13344. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13345. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13346. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13347. fclose(infile);
  13348. fclose(outfile);
  13349. sprintf(rmFileCmd,"rm -f %s",filename);
  13350. system(rmFileCmd);
  13351. rename(tempfile, filename);
  13352. }
  13353. else
  13354. {
  13355. // Profile is not empty
  13356. int ChargingProfileAdded = FALSE;
  13357. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13358. {
  13359. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13360. json_object *tmpChargingProfile;
  13361. tmpChargingProfile = json_tokener_parse(dataLine);
  13362. if(!is_error(SetChargingProfile))
  13363. {
  13364. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13365. {
  13366. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13367. {
  13368. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13369. }
  13370. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13371. {
  13372. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13373. }
  13374. }
  13375. }
  13376. json_object_put(tmpChargingProfile);
  13377. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13378. {
  13379. if(ChargingProfileAdded == FALSE)
  13380. {
  13381. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13382. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13383. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13384. ChargingProfileAdded = TRUE;
  13385. }
  13386. }
  13387. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13388. {
  13389. if(ChargingProfileAdded == FALSE)
  13390. {
  13391. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13392. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13393. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13394. ChargingProfileAdded = TRUE;
  13395. }
  13396. }
  13397. else
  13398. {
  13399. fprintf(outfile,"%s\n",dataLine);
  13400. if(ChargingProfileAdded == FALSE)
  13401. {
  13402. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13403. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13404. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13405. ChargingProfileAdded = TRUE;
  13406. }
  13407. }
  13408. } // end of while loop
  13409. fclose(infile);
  13410. fclose(outfile);
  13411. sprintf(rmFileCmd,"rm -f %s",filename);
  13412. system(rmFileCmd);
  13413. rename(tempfile, filename);
  13414. }
  13415. }
  13416. sleep(1);
  13417. result = TRUE;
  13418. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13419. }
  13420. end:
  13421. json_object_put(SetChargingProfile);
  13422. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13423. {
  13424. if(SetProfileReq.ConnectorId == 0)
  13425. {
  13426. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13427. {
  13428. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13429. }
  13430. }
  13431. else
  13432. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13433. }
  13434. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13435. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13436. return result;
  13437. }
  13438. int handleTriggerMessageRequest(char *uuid, char *payload)
  13439. {
  13440. mtrace();
  13441. int result = FAIL;
  13442. int connectorIdIsNULL = FALSE;
  13443. int connectorIdInt =0;
  13444. char sstr[40]={0},sstrtemp[100]={ 0 };
  13445. char requestedMessagestr[40]={0};
  13446. char comfirmstr[20]={0};
  13447. int c = 0;
  13448. char *loc;
  13449. DEBUG_INFO("handleTriggerMessageRequest\n");
  13450. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13451. strcpy(sstrtemp, stringtrimspace(payload));
  13452. c = 0;
  13453. loc = strstr(sstrtemp, "requestedMessage");
  13454. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13455. {
  13456. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13457. c++;
  13458. }
  13459. sstr[c] = '\0';
  13460. strcpy(requestedMessagestr, sstr);
  13461. c = 0;
  13462. loc = strstr(sstrtemp, "connectorId");
  13463. if(loc == NULL)
  13464. {
  13465. connectorIdIsNULL = TRUE;
  13466. }
  13467. else
  13468. {
  13469. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13470. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13471. {
  13472. sstr[c] = loc[strlen("connectorId")+2+c];
  13473. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13474. c++;
  13475. }
  13476. sstr[c] = '\0';
  13477. connectorIdInt = atoi(sstr);
  13478. }
  13479. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13480. {
  13481. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13482. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13483. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13484. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13485. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13486. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13487. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13488. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13489. {
  13490. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13491. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13492. return TRUE;
  13493. }
  13494. else
  13495. {
  13496. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13497. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13498. }
  13499. }
  13500. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13501. {
  13502. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13503. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13504. return TRUE;
  13505. }
  13506. //==========================
  13507. // Trigger message
  13508. //==========================
  13509. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13510. {
  13511. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13512. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13513. {
  13514. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13515. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13516. }
  13517. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13518. }
  13519. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13520. {
  13521. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13522. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13523. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13524. }
  13525. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13526. {
  13527. //sendBootNotificationRequest();
  13528. server_sign = FALSE;
  13529. }
  13530. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13531. {
  13532. refreshStartTimer(&clientTime.Heartbeat);
  13533. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13534. }
  13535. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13536. {
  13537. if(connectorIdIsNULL == FALSE)
  13538. {
  13539. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13540. {
  13541. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13542. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13543. }
  13544. }
  13545. else
  13546. {
  13547. for(int idx=0;idx< gunTotalNumber;idx++)
  13548. {
  13549. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13550. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13551. }
  13552. }
  13553. }
  13554. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13555. {
  13556. if(connectorIdIsNULL == FALSE)
  13557. {
  13558. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13559. {
  13560. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13561. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13562. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13563. }
  13564. }
  13565. else
  13566. {
  13567. for(int idx=0;idx< gunTotalNumber;idx++)
  13568. {
  13569. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13570. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13571. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13572. }
  13573. }
  13574. }
  13575. return result;
  13576. }
  13577. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13578. {
  13579. mtrace();
  13580. int result = FAIL;
  13581. int connectorIdInt =0;
  13582. char comfirmstr[20]={0};
  13583. int tempIndex = 0;
  13584. json_object *UnlockConnector;
  13585. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13586. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13587. UnlockConnector = json_tokener_parse(payload);
  13588. if(!is_error(UnlockConnector))
  13589. {
  13590. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13591. {
  13592. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13593. }
  13594. }
  13595. json_object_put(UnlockConnector);
  13596. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13597. if(gunTotalNumber == 0)
  13598. {
  13599. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13600. goto end;
  13601. }
  13602. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13603. {
  13604. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13605. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13606. goto end;
  13607. }
  13608. else
  13609. {
  13610. //check Transaction active
  13611. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13612. {
  13613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13614. {
  13615. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13616. }
  13617. else
  13618. {
  13619. tempIndex = connectorIdInt -1;
  13620. }
  13621. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13622. {
  13623. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13624. {
  13625. //stop Transaction
  13626. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13627. }
  13628. }
  13629. }
  13630. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13631. {
  13632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13633. {
  13634. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13635. }
  13636. else
  13637. {
  13638. tempIndex = connectorIdInt -1;
  13639. }
  13640. for (int index = 0; index < CCS_QUANTITY; index++)
  13641. {
  13642. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13643. {
  13644. //stop Transaction
  13645. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13646. }
  13647. }
  13648. }
  13649. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13650. {
  13651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13652. {
  13653. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13654. }
  13655. else
  13656. {
  13657. tempIndex = connectorIdInt -1;
  13658. }
  13659. for (int index = 0; index < GB_QUANTITY; index++)
  13660. {
  13661. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13662. {
  13663. //stop Transaction
  13664. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13665. }
  13666. }
  13667. }
  13668. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13669. {
  13670. tempIndex = connectorIdInt -1;
  13671. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13672. {
  13673. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13674. {
  13675. //stop Transaction
  13676. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13677. }
  13678. }
  13679. }
  13680. else
  13681. {
  13682. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13683. {
  13684. tempIndex = 2;
  13685. }
  13686. else
  13687. {
  13688. tempIndex = connectorIdInt-1;
  13689. }
  13690. for (int index = 0; index < AC_QUANTITY; index++)
  13691. {
  13692. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13693. {
  13694. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13695. }
  13696. }
  13697. }
  13698. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13699. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13700. result = TRUE;
  13701. return result;
  13702. }
  13703. end:
  13704. //json_object_put(obj); --- remove temporally
  13705. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13706. return result;
  13707. }
  13708. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13709. {
  13710. mtrace();
  13711. int result = FAIL;
  13712. pthread_t t;
  13713. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13714. sendUpdateFirmwareConfirmation(uuid);
  13715. if(!interLock.isUpdateFirmwareGoing)
  13716. {
  13717. interLock.isUpdateFirmwareGoing = 1;
  13718. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13719. sleep(1);
  13720. }
  13721. else
  13722. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13723. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13724. return result;
  13725. }
  13726. void *UpdateFirmwareProcess(void *data)
  13727. {
  13728. pthread_detach(pthread_self());
  13729. mtrace();
  13730. int retriesInt =0, retryIntervalInt=0;
  13731. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13732. int port=0;
  13733. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13734. int isSuccess = 0;
  13735. char ftpbuf[1024];
  13736. char temp[1024];
  13737. char * pch;
  13738. json_object *UpdateFirmware;
  13739. UpdateFirmware = json_tokener_parse(data);
  13740. if(!is_error(UpdateFirmware))
  13741. {
  13742. // Required data
  13743. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13744. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13745. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13746. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13747. // Optional data
  13748. if(json_object_object_get(UpdateFirmware, "retries"))
  13749. {
  13750. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13751. }
  13752. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13753. {
  13754. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13755. }
  13756. }
  13757. json_object_put(UpdateFirmware);
  13758. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13759. memset(path, 0, ARRAY_SIZE(path));
  13760. // Wait retrieveData
  13761. if(strlen(retrieveDatestr) > 10)
  13762. {
  13763. do
  13764. {
  13765. sleep(1);
  13766. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13767. }
  13768. // Ready to download
  13769. system("rm -f /mnt/*");
  13770. if(strncmp(locationstr,"http", 4) == 0)
  13771. {
  13772. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13773. sprintf(ftppath,"/%s", path);
  13774. DEBUG_INFO("locationstr: %s\n", locationstr);
  13775. DEBUG_INFO("protocol: %s\n",protocol);
  13776. DEBUG_INFO("host: %s\n",host);
  13777. DEBUG_INFO("path: %s\n",path);
  13778. DEBUG_INFO("ftppath: %s\n",ftppath);
  13779. int ftppathlen=strlen(ftppath);
  13780. int i=1;
  13781. char filenametemp[50];
  13782. while(i < ftppathlen)
  13783. {
  13784. int len=ftppathlen-i;
  13785. if(ftppath[len]== 47) // '/' ascll code: 47
  13786. {
  13787. DEBUG_INFO("compare '/' all right\n");
  13788. break;
  13789. }
  13790. i=i+1;
  13791. }
  13792. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13793. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13794. filenametemp[i+1] = 0;
  13795. do
  13796. {
  13797. sleep(1);
  13798. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13799. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13800. sleep(1);
  13801. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13802. if(!isSuccess)
  13803. {
  13804. sleep(1);
  13805. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13806. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13807. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13808. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13809. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13810. }
  13811. else
  13812. {
  13813. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13814. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13815. }
  13816. retriesInt--;
  13817. }while((isSuccess == 0)&&(retriesInt >= 0));
  13818. }
  13819. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13820. {
  13821. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13822. memset(temp, 0, ARRAY_SIZE(temp));
  13823. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13824. strcpy(ftpbuf, locationstr);
  13825. int ftppathlen=strlen(ftpbuf);
  13826. int i=1;
  13827. char filenametemp[50];
  13828. while(i < ftppathlen)
  13829. {
  13830. int len=ftppathlen-i;
  13831. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13832. {
  13833. DEBUG_INFO(" compare '/' all right\n");
  13834. break;
  13835. }
  13836. i=i+1;
  13837. }
  13838. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13839. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13840. filenametemp[i+1] = 0;
  13841. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13842. pch=strchr(temp,'@');
  13843. if(pch==NULL)
  13844. {
  13845. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13846. protocol, host, &port, path);
  13847. strcpy(user,"anonymous");
  13848. strcpy(password,"");
  13849. }
  13850. else
  13851. {
  13852. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13853. protocol, user, host, &port, path);
  13854. }
  13855. sscanf(host,"%[^/]%s",host1, path1);
  13856. sprintf(ftppath,"%s:/%s", host,path);
  13857. if(port == 0)
  13858. {
  13859. port = 21;
  13860. }
  13861. do
  13862. {
  13863. sleep(1);
  13864. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13865. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13866. sleep(1);
  13867. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13868. if(!isSuccess)
  13869. {
  13870. //BulldogUtil.sleepMs(interval*1000);
  13871. DEBUG_INFO("Update firmware request and download file fail.\n");
  13872. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13873. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13874. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13875. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13876. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13877. }
  13878. else
  13879. {
  13880. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13881. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13882. }
  13883. retriesInt--;
  13884. }while((!isSuccess)&&(retriesInt >= 0));
  13885. }
  13886. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13887. {
  13888. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13889. memset(temp, 0, ARRAY_SIZE(temp));
  13890. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13891. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13892. int ftppathlen=strlen(ftpbuf);
  13893. int i=1;
  13894. char filenametemp[50];
  13895. while(i < ftppathlen)
  13896. {
  13897. int len=ftppathlen-i;
  13898. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13899. {
  13900. DEBUG_INFO(" compare '/' all right\n");
  13901. break;
  13902. }
  13903. i=i+1;
  13904. }
  13905. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13906. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13907. filenametemp[i+1] = 0;
  13908. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13909. pch=strchr(temp,'@');
  13910. if(pch==NULL)
  13911. {
  13912. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13913. protocol, host, &port, path);
  13914. strcpy(user,"anonymous");
  13915. strcpy(password,"");
  13916. }
  13917. else
  13918. {
  13919. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13920. protocol, user, password, host, &port, path);
  13921. }
  13922. sscanf(host,"%[^/]%s",host1, path1);
  13923. sprintf(ftppath,"%s", path1);
  13924. //DEBUG_INFO("protocol =%s\n",protocol);
  13925. //DEBUG_INFO("user =%s\n",user);
  13926. //DEBUG_INFO("password =%s\n",password);
  13927. //DEBUG_INFO("host1 =%s\n",host1);
  13928. //DEBUG_INFO("port =%d\n",port);
  13929. //DEBUG_INFO("path1 =%s\n",path1);
  13930. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13931. //ftpFile(host, user, password, port, ftppath, fname);
  13932. //download firmware pthred
  13933. if(port == 0)
  13934. {
  13935. port = 21;
  13936. }
  13937. do
  13938. {
  13939. sleep(1);
  13940. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13941. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13942. sleep(1);
  13943. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13944. if(!isSuccess)
  13945. {
  13946. //BulldogUtil.sleepMs(interval*1000);
  13947. DEBUG_INFO("Update firmware request and download file fail.\n");
  13948. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13949. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13950. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13951. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13952. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13953. }
  13954. else
  13955. {
  13956. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13957. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13958. }
  13959. retriesInt--;
  13960. }while((!isSuccess)&&(retriesInt >= 0));
  13961. }
  13962. else
  13963. {
  13964. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13965. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13966. sleep(1);
  13967. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13968. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13969. }
  13970. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13971. {
  13972. sleep(3);
  13973. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13974. }
  13975. interLock.isUpdateFirmwareGoing = 0;
  13976. pthread_exit(NULL);
  13977. }
  13978. int handleCertificateSignedRequest(char *uuid, char *payload)
  13979. {
  13980. mtrace();
  13981. int result = PASS;
  13982. json_object *CertificateSigned;
  13983. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13984. CertificateSigned = json_tokener_parse(payload);
  13985. if(!is_error(CertificateSigned))
  13986. {
  13987. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13988. }
  13989. json_object_put(CertificateSigned);
  13990. FILE *fp = fopen(CERTIFICATE_CP, "w");
  13991. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13992. fclose(fp);
  13993. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13994. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13995. if(certVerify(PRIVATE_KEY_CP, CERTIFICATE_CP) == PASS)
  13996. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13997. else
  13998. {
  13999. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  14000. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  14001. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14002. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14003. }
  14004. sendCertificateSignedConfirmation(uuid);
  14005. return result;
  14006. }
  14007. int handleDeleteCertificateRequest(char *uuid, char *payload)
  14008. {
  14009. mtrace();
  14010. int result = PASS;
  14011. json_object *DeleteCertificate;
  14012. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  14013. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14014. DeleteCertificate = json_tokener_parse(payload);
  14015. if(!is_error(DeleteCertificate))
  14016. {
  14017. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14018. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14019. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14020. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14021. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14022. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14023. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14024. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14025. char temp[256] = {0};
  14026. char compareData[256] = {0};
  14027. int isMatch = TRUE;
  14028. FILE *fp;
  14029. if(access(ROOTCA_CS,F_OK) != -1)
  14030. {
  14031. // Check CentralSystemRootCertificate
  14032. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14033. sprintf(temp ,"openssl x509 -noout -serial -in %s", ROOTCA_CS);
  14034. fp = popen(temp, "r");
  14035. if(fp)
  14036. {
  14037. while(fgets(temp, sizeof(temp), fp) != NULL)
  14038. {
  14039. if(strstr(temp, "serial=") != NULL)
  14040. {
  14041. sscanf(temp, "%*[^=]=%s", compareData);
  14042. break;
  14043. }
  14044. }
  14045. DEBUG_INFO("SerialNumber= %s...\n", compareData);
  14046. }
  14047. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14048. isMatch = FALSE;
  14049. if(isMatch == TRUE)
  14050. {
  14051. memset(compareData, 0, ARRAY_SIZE(compareData));
  14052. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", ROOTCA_CS, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14053. fp = popen(temp, "r");
  14054. if(fp)
  14055. {
  14056. while(fgets(temp, sizeof(temp), fp) != NULL)
  14057. {
  14058. strcat(compareData, temp);
  14059. }
  14060. }
  14061. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  14062. isMatch = FALSE;
  14063. }
  14064. if(isMatch == TRUE)
  14065. {
  14066. memset(compareData, 0, ARRAY_SIZE(compareData));
  14067. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", ROOTCA_CS, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14068. fp = popen(temp, "r");
  14069. if(fp)
  14070. {
  14071. while(fgets(temp, sizeof(temp), fp) != NULL)
  14072. {
  14073. strcat(compareData, temp);
  14074. }
  14075. }
  14076. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14077. isMatch = FALSE;
  14078. }
  14079. if(isMatch == TRUE)
  14080. {
  14081. sprintf(temp, "rm -f /Storage/OCPP/%s", ROOTCA_CS);
  14082. system(temp);
  14083. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14084. goto End;
  14085. }
  14086. }
  14087. // Check ManufacturerRootCertificate
  14088. if(access(ROOTCA_MFG,F_OK) != -1)
  14089. {
  14090. isMatch = FALSE;
  14091. sprintf(temp ,"openssl x509 -noout -serial -in %s", ROOTCA_MFG);
  14092. fp = popen(temp, "r");
  14093. if(fp)
  14094. {
  14095. while(fgets(temp, sizeof(temp), fp) != NULL)
  14096. {
  14097. if(strstr(temp, "serial=") != NULL)
  14098. {
  14099. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14100. sscanf(temp, "%*[^=]=%s", compareData);
  14101. break;
  14102. }
  14103. }
  14104. }
  14105. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14106. isMatch = FALSE;
  14107. if(isMatch == TRUE)
  14108. {
  14109. memset(compareData, 0, ARRAY_SIZE(compareData));
  14110. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", ROOTCA_MFG, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14111. fp = popen(temp, "r");
  14112. if(fp)
  14113. {
  14114. while(fgets(temp, sizeof(temp), fp) != NULL)
  14115. {
  14116. strcat(compareData, temp);
  14117. }
  14118. }
  14119. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  14120. isMatch = FALSE;
  14121. }
  14122. if(isMatch == TRUE)
  14123. {
  14124. memset(compareData, 0, ARRAY_SIZE(compareData));
  14125. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", ROOTCA_MFG, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14126. fp = popen(temp, "r");
  14127. if(fp)
  14128. {
  14129. while(fgets(temp, sizeof(temp), fp) != NULL)
  14130. {
  14131. strcat(compareData, temp);
  14132. }
  14133. }
  14134. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14135. isMatch = FALSE;
  14136. }
  14137. if(isMatch == TRUE)
  14138. {
  14139. sprintf(temp, "rm -f %s", ROOTCA_MFG);
  14140. system(temp);
  14141. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14142. goto End;
  14143. }
  14144. }
  14145. // Check certCP
  14146. if(access(CERTIFICATE_CP,F_OK) != -1)
  14147. {
  14148. isMatch = FALSE;
  14149. sprintf(temp ,"openssl x509 -noout -serial -in %s", CERTIFICATE_CP);
  14150. fp = popen(temp, "r");
  14151. if(fp)
  14152. {
  14153. while(fgets(temp, sizeof(temp), fp) != NULL)
  14154. {
  14155. if(strstr(temp, "serial=") != NULL)
  14156. {
  14157. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14158. sscanf(temp, "%*[^=]=%s", compareData);
  14159. break;
  14160. }
  14161. }
  14162. }
  14163. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14164. isMatch = FALSE;
  14165. if(isMatch == TRUE)
  14166. {
  14167. memset(compareData, 0, ARRAY_SIZE(compareData));
  14168. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14169. fp = popen(temp, "r");
  14170. if(fp)
  14171. {
  14172. while(fgets(temp, sizeof(temp), fp) != NULL)
  14173. {
  14174. strcat(compareData, temp);
  14175. }
  14176. }
  14177. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  14178. isMatch = FALSE;
  14179. }
  14180. if(isMatch == TRUE)
  14181. {
  14182. memset(compareData, 0, ARRAY_SIZE(compareData));
  14183. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14184. fp = popen(temp, "r");
  14185. if(fp)
  14186. {
  14187. while(fgets(temp, sizeof(temp), fp) != NULL)
  14188. {
  14189. strcat(compareData, temp);
  14190. }
  14191. }
  14192. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14193. isMatch = FALSE;
  14194. }
  14195. if(isMatch == TRUE)
  14196. {
  14197. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14198. system(temp);
  14199. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14200. goto End;
  14201. }
  14202. }
  14203. }
  14204. End:
  14205. json_object_put(DeleteCertificate);
  14206. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14207. sendDeleteCertificateConfirmation(uuid);
  14208. return result;
  14209. }
  14210. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14211. {
  14212. mtrace();
  14213. int result = PASS;
  14214. json_object *ExtendedTriggerMessage;
  14215. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14216. ExtendedTriggerMessage = json_tokener_parse(payload);
  14217. if(!is_error(ExtendedTriggerMessage))
  14218. {
  14219. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14220. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14221. {
  14222. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14223. }
  14224. else
  14225. {
  14226. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14227. }
  14228. }
  14229. json_object_put(ExtendedTriggerMessage);
  14230. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14231. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14232. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14233. {
  14234. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14235. }
  14236. else
  14237. {
  14238. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14239. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14240. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14241. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14242. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14243. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14244. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14245. {
  14246. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14247. }
  14248. else
  14249. {
  14250. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14251. }
  14252. }
  14253. sendExtendedTriggerMessageConfirmation(uuid);
  14254. //==========================
  14255. // Trigger message
  14256. //==========================
  14257. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14258. {
  14259. //sendBootNotificationRequest();
  14260. server_sign = FALSE;
  14261. }
  14262. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14263. {
  14264. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14265. }
  14266. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14267. {
  14268. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14269. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14270. {
  14271. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14272. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14273. }
  14274. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14275. }
  14276. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14277. {
  14278. refreshStartTimer(&clientTime.Heartbeat);
  14279. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14280. }
  14281. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14282. {
  14283. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14284. {
  14285. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14286. }
  14287. else
  14288. {
  14289. for(int idx=0;idx< gunTotalNumber;idx++)
  14290. {
  14291. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14292. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14293. }
  14294. }
  14295. }
  14296. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14297. {
  14298. char cmdBuf[1024]={0};
  14299. sprintf(cmdBuf, "openssl req -newkey rsa:2048 -out %s -nodes -keyout %s -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=%s/OU=IT/CN=%s\" &", CSR_CP, PRIVATE_KEY_CP, ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14300. system(cmdBuf);
  14301. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14302. }
  14303. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14304. {
  14305. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14306. {
  14307. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14308. }
  14309. else
  14310. {
  14311. for(int idx=0;idx< gunTotalNumber;idx++)
  14312. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14313. }
  14314. }
  14315. return result;
  14316. }
  14317. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14318. {
  14319. mtrace();
  14320. int result = PASS;
  14321. json_object *GetInstalledCertificateIds;
  14322. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14323. GetInstalledCertificateIds = json_tokener_parse(payload);
  14324. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14325. if(!is_error(GetInstalledCertificateIds))
  14326. {
  14327. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14328. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14329. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14330. char temp[512] = {0};
  14331. char capturedData[256] = {0};
  14332. char hashType[10] = {0};
  14333. FILE *fp;
  14334. // Check CentralSystemRootCertificate
  14335. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL) && (access(ROOTCA_CS,F_OK) != -1))
  14336. {
  14337. memset(hashType, 0, ARRAY_SIZE(hashType));
  14338. sprintf(temp ,"openssl x509 -noout -text -in %s", ROOTCA_CS);
  14339. fp = popen(temp, "r");
  14340. if(fp)
  14341. {
  14342. while(fgets(temp, sizeof(temp), fp) != NULL)
  14343. {
  14344. if(strstr(temp, "Signature Algorithm:") != NULL)
  14345. {
  14346. if(strstr(temp, "sha256") != NULL)
  14347. sprintf((char*)hashType, "SHA256");
  14348. if(strstr(temp, "sha384") != NULL)
  14349. sprintf((char*)hashType, "SHA384");
  14350. if(strstr(temp, "sha512") != NULL)
  14351. sprintf((char*)hashType, "SHA512");
  14352. break;
  14353. }
  14354. }
  14355. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  14356. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, hashType);
  14357. }
  14358. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  14359. sprintf(temp ,"openssl x509 -noout -serial -in %s", ROOTCA_CS);
  14360. fp = popen(temp, "r");
  14361. if(fp)
  14362. {
  14363. while(fgets(temp, sizeof(temp), fp) != NULL)
  14364. {
  14365. if(strstr(temp, "serial=") != NULL)
  14366. {
  14367. sscanf(temp, "%*[^=]=%s", capturedData);
  14368. break;
  14369. }
  14370. }
  14371. DEBUG_INFO("serialNumber: %s\n", capturedData);
  14372. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, capturedData);
  14373. }
  14374. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  14375. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", ROOTCA_CS, (char*)hashType);
  14376. fp = popen(temp, "r");
  14377. if(fp)
  14378. {
  14379. while(fgets(temp, sizeof(temp), fp) != NULL)
  14380. {
  14381. if(strstr(temp, "(stdin)=") != NULL)
  14382. {
  14383. sscanf(temp, "%*[^=]=%s", capturedData);
  14384. break;
  14385. }
  14386. }
  14387. stringtrimspace(capturedData);
  14388. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  14389. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, capturedData);
  14390. }
  14391. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  14392. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", ROOTCA_CS, (char*)hashType);
  14393. fp = popen(temp, "r");
  14394. if(fp)
  14395. {
  14396. while(fgets(temp, sizeof(temp), fp) != NULL)
  14397. {
  14398. if(strstr(temp, "(stdin)=") != NULL)
  14399. {
  14400. sscanf(temp, "%*[^=]=%s", capturedData);
  14401. break;
  14402. }
  14403. }
  14404. stringtrimspace(capturedData);
  14405. DEBUG_INFO("issuerKeyHash: %s\n", capturedData);
  14406. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, capturedData);
  14407. }
  14408. }
  14409. else
  14410. {
  14411. DEBUG_INFO(">>> No CentralSystemRootCertificate found.\n");
  14412. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14413. }
  14414. // Check ManufacturerRootCertificate
  14415. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL) && (access(ROOTCA_MFG,F_OK) != -1))
  14416. {
  14417. memset(hashType, 0, ARRAY_SIZE(hashType));
  14418. sprintf(temp ,"openssl x509 -noout -text -in %s", ROOTCA_MFG);
  14419. fp = popen(temp, "r");
  14420. if(fp)
  14421. {
  14422. while(fgets(temp, sizeof(temp), fp) != NULL)
  14423. {
  14424. if(strstr(temp, "Signature Algorithm:") != NULL)
  14425. {
  14426. if(strstr(temp, "sha256") != NULL)
  14427. sprintf((char*)hashType, "SHA256");
  14428. if(strstr(temp, "sha384") != NULL)
  14429. sprintf((char*)hashType, "SHA384");
  14430. if(strstr(temp, "sha512") != NULL)
  14431. sprintf((char*)hashType, "SHA512");
  14432. break;
  14433. }
  14434. }
  14435. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  14436. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, hashType);
  14437. }
  14438. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  14439. sprintf(temp ,"openssl x509 -noout -serial -in %s", ROOTCA_MFG);
  14440. fp = popen(temp, "r");
  14441. if(fp)
  14442. {
  14443. while(fgets(temp, sizeof(temp), fp) != NULL)
  14444. {
  14445. if(strstr(temp, "serial=") != NULL)
  14446. {
  14447. sscanf(temp, "%*[^=]=%s", capturedData);
  14448. break;
  14449. }
  14450. }
  14451. DEBUG_INFO("serialNumber: %s\n", capturedData);
  14452. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, capturedData);
  14453. }
  14454. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  14455. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", ROOTCA_MFG, (char*)hashType);
  14456. fp = popen(temp, "r");
  14457. if(fp)
  14458. {
  14459. while(fgets(temp, sizeof(temp), fp) != NULL)
  14460. {
  14461. if(strstr(temp, "(stdin)=") != NULL)
  14462. {
  14463. sscanf(temp, "%*[^=]=%s", capturedData);
  14464. break;
  14465. }
  14466. }
  14467. stringtrimspace(capturedData);
  14468. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  14469. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, capturedData);
  14470. }
  14471. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  14472. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", ROOTCA_MFG, (char*)hashType);
  14473. fp = popen(temp, "r");
  14474. if(fp)
  14475. {
  14476. while(fgets(temp, sizeof(temp), fp) != NULL)
  14477. {
  14478. if(strstr(temp, "(stdin)=") != NULL)
  14479. {
  14480. sscanf(temp, "%*[^=]=%s", capturedData);
  14481. break;
  14482. }
  14483. }
  14484. stringtrimspace(capturedData);
  14485. DEBUG_INFO("issuerKeyHash: %s\n", capturedData);
  14486. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, capturedData);
  14487. }
  14488. }
  14489. else
  14490. {
  14491. DEBUG_INFO(">>> No ManufacturerRootCertificate found.\n");
  14492. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14493. }
  14494. }
  14495. json_object_put(GetInstalledCertificateIds);
  14496. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14497. sendGetInstalledCertificateIdsConfirmation(uuid);
  14498. return result;
  14499. }
  14500. void* GetLogProcess(void* data)
  14501. {
  14502. pthread_detach(pthread_self());
  14503. mtrace();
  14504. 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};
  14505. int port=0;
  14506. int isSuccess = FALSE;
  14507. char cmdBuf[2048];
  14508. struct tm *tmNow;
  14509. time_t CurrentTime;
  14510. struct tm tmStart;
  14511. struct tm tmStop;
  14512. CurrentTime = time(NULL);
  14513. tmNow=localtime(&CurrentTime);
  14514. uint16_t targetYear, targetMonth;
  14515. json_object *GetLog;
  14516. DEBUG_INFO("GetLogProcess...\n");
  14517. GetLog = json_tokener_parse(data);
  14518. if(!is_error(GetLog))
  14519. {
  14520. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14521. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14522. if(json_object_object_get(GetLog, "retries") != NULL)
  14523. {
  14524. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14525. }
  14526. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14527. {
  14528. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14529. }
  14530. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14531. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14532. {
  14533. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14534. }
  14535. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14536. {
  14537. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14538. }
  14539. }
  14540. json_object_put(GetLog);
  14541. // Pack log to compress file
  14542. if((sscanf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%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) &&
  14543. (sscanf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%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))
  14544. {
  14545. // Pack system log
  14546. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14547. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14548. targetYear = tmStart.tm_year;
  14549. targetMonth = tmStart.tm_mon;
  14550. do
  14551. {
  14552. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14553. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14554. if(targetMonth+1>=13)
  14555. {
  14556. targetYear += 1;
  14557. targetMonth = 1;
  14558. }
  14559. else
  14560. {
  14561. targetMonth += 1;
  14562. }
  14563. }while((targetYear < (tmNow->tm_year+1900)) ||
  14564. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14565. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14566. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14567. system(cmdBuf);
  14568. // Pack charging & event log
  14569. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14570. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14571. targetYear = tmStart.tm_year;
  14572. targetMonth = tmStart.tm_mon;
  14573. do
  14574. {
  14575. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14576. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14577. if(targetMonth+1>=13)
  14578. {
  14579. targetYear += 1;
  14580. targetMonth = 1;
  14581. }
  14582. else
  14583. {
  14584. targetMonth += 1;
  14585. }
  14586. }while((targetYear < (tmNow->tm_year+1900)) ||
  14587. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14588. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14589. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14590. system(cmdBuf);
  14591. // Combine log file
  14592. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14593. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14594. }
  14595. else
  14596. {
  14597. system("exec /root/logPackTools 'log' 6");
  14598. }
  14599. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14600. system(cmdBuf);
  14601. checkUploadLog();
  14602. //****************location*******************/
  14603. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14604. {
  14605. DEBUG_INFO("location is <Empty>!\n");
  14606. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14607. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14608. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14609. goto end;
  14610. }
  14611. memset(protocol, 0, ARRAY_SIZE(protocol));
  14612. memset(user, 0, ARRAY_SIZE(user) );
  14613. memset(password, 0, ARRAY_SIZE(password));
  14614. memset(host, 0, ARRAY_SIZE(host));
  14615. memset(path, 0, ARRAY_SIZE(path));
  14616. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14617. memset(host1, 0, ARRAY_SIZE(host1));
  14618. memset(path1, 0, ARRAY_SIZE(path1));
  14619. /*location: ftp://user:password@host:port/path*/
  14620. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14621. if((access(fnamePlusPath,F_OK))!=-1)
  14622. {
  14623. DEBUG_INFO("fnamePlusPath exist.\n");
  14624. }
  14625. else
  14626. {
  14627. DEBUG_INFO("fnamePlusPath not exist!\n");
  14628. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14629. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14630. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14631. goto end;
  14632. }
  14633. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14634. {
  14635. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14636. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14637. protocol, host, &port, path);
  14638. strcpy(user,"anonymous");
  14639. strcpy(password,"");
  14640. }
  14641. else
  14642. {
  14643. //DEBUG_INFO("pch=%s\n", pch);
  14644. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14645. protocol, user, password, host, &port, path);
  14646. }
  14647. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14648. {
  14649. DEBUG_INFO("protocol is not ftp/http ! \n");
  14650. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14651. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14652. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14653. goto end;
  14654. }
  14655. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14656. {
  14657. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14658. sprintf(ftppath,"/%s", path);
  14659. do
  14660. {
  14661. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14662. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14663. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14664. sleep(3);
  14665. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14666. if(!isSuccess)
  14667. {
  14668. DEBUG_INFO("Diagnostics fail.\n");
  14669. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14670. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14671. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14672. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14673. }
  14674. else
  14675. {
  14676. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14677. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14678. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14679. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14680. }
  14681. ShmOCPP16Data->GetLog.retries--;
  14682. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14683. }
  14684. else
  14685. {
  14686. sscanf(host,"%[^/]%s",host1, path1);
  14687. if(strlen(path) > 0)
  14688. sprintf(ftppath,"/%s", path);
  14689. else
  14690. sprintf(ftppath,"/%s", path1);
  14691. int ftppathlen=strlen(ftppath);
  14692. int i=1;
  14693. char filenametemp[50];
  14694. while(i < ftppathlen)
  14695. {
  14696. int len=ftppathlen-i;
  14697. if(ftppath[len]== 47) // '/' ascll code: 47
  14698. {
  14699. DEBUG_INFO("find '/' all right\n");
  14700. break;
  14701. }
  14702. i=i+1;
  14703. }
  14704. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14705. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14706. filenametemp[i+1] = 0;
  14707. if(port == 0)
  14708. port = 21;
  14709. do
  14710. {
  14711. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14712. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14713. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14714. sleep(3);
  14715. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14716. if(!isSuccess)
  14717. {
  14718. DEBUG_INFO("Diagnostics fail.\n");
  14719. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14720. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14721. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14722. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14723. }
  14724. else
  14725. {
  14726. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14727. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14728. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14729. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14730. }
  14731. ShmOCPP16Data->GetLog.retries--;
  14732. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14733. }
  14734. end:
  14735. system("rm -f /mnt/*");
  14736. sleep(5);
  14737. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14738. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14739. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14740. interLock.isGetDiagnosticGoing = 0;
  14741. pthread_exit(NULL);
  14742. }
  14743. int handleGetLogRequest(char *uuid, char *payload)
  14744. {
  14745. mtrace();
  14746. int result = PASS;
  14747. time_t CurrentTime;
  14748. struct tm *tm;
  14749. DEBUG_INFO("handleGetLogRequest...\n");
  14750. pthread_t th_Status;
  14751. CurrentTime = time(NULL);
  14752. tm = localtime(&CurrentTime);
  14753. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14754. sprintf((char*)ShmOCPP16Data->GetLog.Response_filename, "%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);
  14755. if(!interLock.isGetDiagnosticGoing)
  14756. {
  14757. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14758. interLock.isGetDiagnosticGoing = 1;
  14759. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14760. sleep(1);
  14761. }
  14762. else
  14763. {
  14764. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14765. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14766. }
  14767. sendGetLogConfirmation(uuid);
  14768. return result;
  14769. }
  14770. int handleInstallCertificateRequest(char *uuid, char *payload)
  14771. {
  14772. mtrace();
  14773. int result = PASS;
  14774. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14775. json_object *InstallCertificate;
  14776. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14777. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14778. InstallCertificate = json_tokener_parse(payload);
  14779. if(!is_error(InstallCertificate))
  14780. {
  14781. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14782. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14783. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14784. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14785. char temp[1024];
  14786. FILE *fp = fopen(tempCert, "w");
  14787. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14788. fclose(fp);
  14789. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14790. char strExpDate[30];
  14791. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14792. fp = popen(temp, "r");
  14793. if(fp)
  14794. {
  14795. while(fgets(temp, sizeof(temp), fp) != NULL)
  14796. {
  14797. if(strstr(temp, "notAfter=") != NULL)
  14798. {
  14799. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14800. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14801. break;
  14802. }
  14803. }
  14804. }
  14805. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14806. struct tm tmExpDate;
  14807. struct timeb tbExpDate;
  14808. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14809. tbExpDate.time = mktime(&tmExpDate);
  14810. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14811. {
  14812. DEBUG_INFO("The enddate is already expired...\n");
  14813. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14814. goto End;
  14815. }
  14816. // Verify certificate with rootCA
  14817. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14818. fp = popen(temp, "r");
  14819. if(fp)
  14820. {
  14821. while(fgets(temp, sizeof(temp), fp) != NULL)
  14822. {
  14823. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14824. {
  14825. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14826. break;
  14827. }
  14828. else
  14829. {
  14830. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14831. }
  14832. }
  14833. }
  14834. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14835. {
  14836. //=====================================================
  14837. // Verify if the certificate is valid or not. (OCSP?)
  14838. //=====================================================
  14839. /*
  14840. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14841. // Get ocsp url
  14842. char ocspUrl[512];
  14843. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14844. fp = popen(temp, "r");
  14845. if(fp)
  14846. {
  14847. while(fgets(temp, sizeof(temp), fp) != NULL)
  14848. {
  14849. if(strstr(temp, "://") != NULL)
  14850. {
  14851. strcpy(ocspUrl, temp);
  14852. }
  14853. }
  14854. }
  14855. // Get certificate chain for issuer
  14856. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14857. *
  14858. // Execute OCSP
  14859. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14860. fp = popen(temp, "r");
  14861. if(fp)
  14862. {
  14863. while(fgets(temp, sizeof(temp), fp) != NULL)
  14864. {
  14865. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14866. {
  14867. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14868. break;
  14869. }
  14870. }
  14871. }
  14872. system("rm -f /Storage/OCPP/tempChain.pem");
  14873. pclose(fp);
  14874. */
  14875. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14876. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14877. {
  14878. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14879. goto End;
  14880. }
  14881. else
  14882. DEBUG_INFO("OCSP verifying...PASS.\n");
  14883. }
  14884. else
  14885. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14886. }
  14887. End:
  14888. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14889. {
  14890. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14891. {
  14892. if(access(ROOTCA_CS,F_OK) != -1)
  14893. {
  14894. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14895. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14896. rename(tempCert, ROOTCA_CS);
  14897. }
  14898. else
  14899. {
  14900. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14901. rename(tempCert, ROOTCA_CS);
  14902. }
  14903. }
  14904. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14905. {
  14906. if(access(ROOTCA_MFG,F_OK) != -1)
  14907. {
  14908. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14909. rename(ROOTCA_MFG, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14910. rename(tempCert, ROOTCA_MFG);
  14911. }
  14912. else
  14913. {
  14914. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14915. rename(tempCert, ROOTCA_MFG);
  14916. }
  14917. }
  14918. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14919. }
  14920. sendInstallCertificateConfirmation(uuid);
  14921. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14922. {
  14923. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14924. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14925. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14926. }
  14927. json_object_put(InstallCertificate);
  14928. return result;
  14929. }
  14930. void *SignedUpdateFirmwareProcess(void *data)
  14931. {
  14932. pthread_detach(pthread_self());
  14933. mtrace();
  14934. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14935. int port=0;
  14936. int isSuccess = 0;
  14937. char ftpbuf[1024];
  14938. char temp[1024];
  14939. char * pch;
  14940. char firmwareFileName[50];
  14941. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14942. json_object *SignedUpdateFirmware;
  14943. SignedUpdateFirmware = json_tokener_parse(data);
  14944. if(!is_error(SignedUpdateFirmware))
  14945. {
  14946. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14947. {
  14948. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14949. }
  14950. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14951. {
  14952. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14953. }
  14954. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14955. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14956. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14957. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14958. {
  14959. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14960. }
  14961. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14962. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14963. }
  14964. json_object_put(SignedUpdateFirmware);
  14965. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14966. memset(path, 0, ARRAY_SIZE(path));
  14967. // Wait retrieveData
  14968. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14969. {
  14970. do
  14971. {
  14972. sleep(1);
  14973. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14974. }
  14975. // Ready to download
  14976. system("rm -f /mnt/*");
  14977. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14978. {
  14979. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14980. sprintf(ftppath,"/%s", path);
  14981. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14982. DEBUG_INFO("protocol: %s\n",protocol);
  14983. DEBUG_INFO("host: %s\n",host);
  14984. DEBUG_INFO("path: %s\n",path);
  14985. DEBUG_INFO("ftppath: %s\n",ftppath);
  14986. int ftppathlen=strlen(ftppath);
  14987. int i=1;
  14988. while(i < ftppathlen)
  14989. {
  14990. int len=ftppathlen-i;
  14991. if(ftppath[len]== 47) // '/' ascll code: 47
  14992. {
  14993. DEBUG_INFO("compare '/' all right\n");
  14994. break;
  14995. }
  14996. i=i+1;
  14997. }
  14998. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14999. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  15000. firmwareFileName[i+1] = 0;
  15001. do
  15002. {
  15003. sleep(1);
  15004. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15005. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15006. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15007. sleep(1);
  15008. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15009. if(!isSuccess)
  15010. {
  15011. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15012. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15013. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15014. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15015. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15016. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15017. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15018. }
  15019. else
  15020. {
  15021. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15022. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15023. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15024. }
  15025. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15026. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15027. }
  15028. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  15029. {
  15030. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15031. memset(temp, 0, ARRAY_SIZE(temp));
  15032. //DEBUG_INFO("locationstr=%s\n",locationstr);
  15033. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15034. int ftppathlen=strlen(ftpbuf);
  15035. int i=1;
  15036. while(i < ftppathlen)
  15037. {
  15038. int len=ftppathlen-i;
  15039. if(ftpbuf[len]== 47) // '/' ascii code: 47
  15040. {
  15041. DEBUG_INFO(" compare '/' all right\n");
  15042. break;
  15043. }
  15044. i=i+1;
  15045. }
  15046. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  15047. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  15048. firmwareFileName[i+1] = 0;
  15049. strncpy(temp, ftpbuf, ftppathlen-i+1);
  15050. pch=strchr(temp,'@');
  15051. if(pch==NULL)
  15052. {
  15053. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15054. protocol, host, &port, path);
  15055. strcpy(user,"anonymous");
  15056. strcpy(password,"");
  15057. }
  15058. else
  15059. {
  15060. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  15061. protocol, user, host, &port, path);
  15062. }
  15063. sscanf(host,"%[^/]%s",host1, path1);
  15064. sprintf(ftppath,"%s:/%s", host,path);
  15065. if(port == 0)
  15066. {
  15067. port = 21;
  15068. }
  15069. do
  15070. {
  15071. sleep(1);
  15072. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15073. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15074. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15075. sleep(1);
  15076. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15077. if(!isSuccess)
  15078. {
  15079. sleep(1);
  15080. DEBUG_INFO("Update firmware request and download file fail.\n");
  15081. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15082. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15083. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15084. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15085. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15086. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15087. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15088. }
  15089. else
  15090. {
  15091. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15092. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15093. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15094. }
  15095. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15096. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15097. }
  15098. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  15099. {
  15100. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15101. memset(temp, 0, ARRAY_SIZE(temp));
  15102. //DEBUG_INFO("locationstr=%s\n",locationstr);
  15103. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15104. int ftppathlen=strlen(ftpbuf);
  15105. int i=1;
  15106. while(i < ftppathlen)
  15107. {
  15108. int len=ftppathlen-i;
  15109. if(ftpbuf[len]== 47) // '/' ascll code: 47
  15110. {
  15111. DEBUG_INFO(" compare '/' all right\n");
  15112. break;
  15113. }
  15114. i=i+1;
  15115. }
  15116. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  15117. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  15118. firmwareFileName[i+1] = 0;
  15119. strncpy(temp, ftpbuf, ftppathlen-i+1);
  15120. pch=strchr(temp,'@');
  15121. if(pch==NULL)
  15122. {
  15123. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15124. protocol, host, &port, path);
  15125. strcpy(user,"anonymous");
  15126. strcpy(password,"");
  15127. }
  15128. else
  15129. {
  15130. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  15131. protocol, user, password, host, &port, path);
  15132. }
  15133. sscanf(host,"%[^/]%s",host1, path1);
  15134. sprintf(ftppath,"%s", path1);
  15135. //DEBUG_INFO("protocol =%s\n",protocol);
  15136. //DEBUG_INFO("user =%s\n",user);
  15137. //DEBUG_INFO("password =%s\n",password);
  15138. //DEBUG_INFO("host1 =%s\n",host1);
  15139. //DEBUG_INFO("port =%d\n",port);
  15140. //DEBUG_INFO("path1 =%s\n",path1);
  15141. //DEBUG_INFO("ftppath=%s\n",ftppath);
  15142. //ftpFile(host, user, password, port, ftppath, fname);
  15143. //download firmware pthred
  15144. if(port == 0)
  15145. {
  15146. port = 21;
  15147. }
  15148. do
  15149. {
  15150. sleep(1);
  15151. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15152. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15153. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15154. sleep(1);
  15155. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15156. if(!isSuccess)
  15157. {
  15158. //BulldogUtil.sleepMs(interval*1000);
  15159. DEBUG_INFO("Update firmware request and download file fail.\n");
  15160. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15161. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15162. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15163. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15164. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15165. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15166. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15167. }
  15168. else
  15169. {
  15170. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15171. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15172. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15173. }
  15174. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15175. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15176. }
  15177. else
  15178. {
  15179. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15180. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15181. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15182. sleep(1);
  15183. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15184. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15185. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15186. }
  15187. // Verify firmware image signature
  15188. struct stat st;
  15189. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15190. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15191. fclose(fp);
  15192. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15193. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15194. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15195. fclose(fp);
  15196. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15197. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15198. if(st.st_size == 0)
  15199. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15200. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15201. {
  15202. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15203. fp = popen(temp, "r");
  15204. if(fp)
  15205. {
  15206. while(fgets(temp, sizeof(temp), fp) != NULL)
  15207. {
  15208. if(strstr(temp, "Verified OK") != NULL)
  15209. {
  15210. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15211. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15212. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15213. }
  15214. else
  15215. {
  15216. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15217. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15218. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15219. sleep(1);
  15220. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15221. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15222. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15223. sleep(1);
  15224. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15225. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15226. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15227. }
  15228. break;
  15229. }
  15230. }
  15231. pclose(fp);
  15232. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15233. }
  15234. interLock.isUpdateFirmwareGoing = 0;
  15235. pthread_exit(NULL);
  15236. }
  15237. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15238. {
  15239. mtrace();
  15240. int result = PASS;
  15241. pthread_t t;
  15242. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15243. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15244. sendSignedUpdateFirmwareConfirmation(uuid);
  15245. if(!interLock.isUpdateFirmwareGoing)
  15246. {
  15247. interLock.isUpdateFirmwareGoing = 1;
  15248. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15249. sleep(1);
  15250. }
  15251. else
  15252. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15253. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15254. return result;
  15255. }
  15256. int handleUnknownRequest(char *uuid, char *payload)
  15257. {
  15258. mtrace();
  15259. int result = PASS;
  15260. DEBUG_INFO("handleUnknownRequest...\n");
  15261. sendUnknownConfirmation(uuid);
  15262. return result;
  15263. }
  15264. //==========================================
  15265. // Handle server response routine
  15266. //==========================================
  15267. void handleAuthorizeResponse(char *payload, int gun_index)
  15268. {
  15269. mtrace();
  15270. char expiryDatestr[36]={0};
  15271. char parentIdTagstr[21]={0};
  15272. char statusstr[20]={0};
  15273. int expiryDateISNULL=FALSE;
  15274. int parentIdTagISNULL=FALSE;
  15275. DEBUG_INFO("handleAuthorizeResponse...\n");
  15276. json_object *Authorize;
  15277. Authorize = json_tokener_parse(payload);
  15278. if(!is_error(Authorize))
  15279. {
  15280. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15281. {
  15282. // Required data
  15283. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15284. // Optional data
  15285. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15286. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15287. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15288. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15289. }
  15290. }
  15291. json_object_put(Authorize);
  15292. if(expiryDateISNULL == FALSE)
  15293. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15294. if(parentIdTagISNULL == FALSE)
  15295. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15296. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15297. //Update idTag information to authorization cache if supproted
  15298. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15299. {
  15300. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15301. }
  15302. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15303. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15304. authorizeRetryTimes = 0;
  15305. }
  15306. void handleBootNotificationResponse(char *payload, int gun_index)
  15307. {
  15308. mtrace();
  15309. char statusStr[12]={0};
  15310. char currentTimeStr[30]={0};
  15311. int intervalInt = 0;
  15312. DEBUG_INFO("handleBootNotificationResponse...\n");
  15313. json_object *BootNotification;
  15314. BootNotification = json_tokener_parse(payload);
  15315. if(!is_error(BootNotification))
  15316. {
  15317. // Required data
  15318. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15319. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15320. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15321. }
  15322. json_object_put(BootNotification);
  15323. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15324. BootNotificationInterval = intervalInt;
  15325. //write back to ShmOCPP16Data->BootNotification
  15326. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15327. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15328. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15329. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15330. {
  15331. BootNotificationInterval = 0;
  15332. if((intervalInt == 0) || (intervalInt >= 10))
  15333. {
  15334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15335. HeartBeatWaitTime = intervalInt;
  15336. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15337. }
  15338. server_sign = TRUE;
  15339. server_pending =FALSE;
  15340. }
  15341. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15342. {
  15343. server_pending = TRUE;
  15344. }
  15345. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15346. srand(time(NULL));
  15347. refreshStartTimer(&clientTime.Heartbeat);
  15348. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15349. SetOcppConnStatus(TRUE);
  15350. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15351. }
  15352. void handleDataTransferResponse(char *payload, int gun_index)
  15353. {
  15354. json_object *DataTransfer = json_tokener_parse(payload);
  15355. if(!is_error(DataTransfer))
  15356. {
  15357. // Required data
  15358. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15359. // Optional data
  15360. if(json_object_object_get(DataTransfer, "data") != NULL)
  15361. {
  15362. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15363. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15364. if(!is_error(Data))
  15365. {
  15366. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15367. {
  15368. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15369. {
  15370. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15371. }
  15372. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15373. {
  15374. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "certificateStatus"), "status")));
  15375. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15376. {
  15377. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "certificateStatus"), "cacheExpiryDateTime")));
  15378. }
  15379. }
  15380. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15381. }
  15382. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15383. {
  15384. if(json_object_object_get(Data, "status") != NULL)
  15385. {
  15386. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15387. }
  15388. if(json_object_object_get(Data, "exiResponse") != NULL)
  15389. {
  15390. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15391. }
  15392. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15393. }
  15394. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15395. {
  15396. if(json_object_object_get(Data, "status") != NULL)
  15397. {
  15398. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15399. }
  15400. if(json_object_object_get(Data, "ocspResult") != NULL)
  15401. {
  15402. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15403. }
  15404. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15405. }
  15406. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15407. {
  15408. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15409. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15410. }
  15411. else
  15412. {
  15413. if(json_object_object_get(Data, "msgId") != NULL)
  15414. {
  15415. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15416. {
  15417. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  15418. }
  15419. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15420. {
  15421. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15422. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15423. }
  15424. }
  15425. }
  15426. }
  15427. json_object_put(Data);
  15428. }
  15429. }
  15430. json_object_put(DataTransfer);
  15431. }
  15432. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15433. {
  15434. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15435. //struct json_object *obj;
  15436. // obj = json_tokener_parse(payload);
  15437. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15438. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15439. //No fields are defined.
  15440. }
  15441. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15442. {
  15443. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15444. //struct json_object *obj;
  15445. // obj = json_tokener_parse(payload);
  15446. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15447. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15448. //No fields are defined.
  15449. }
  15450. void handleHeartbeatResponse(char *payload, int gun_index)
  15451. {
  15452. mtrace();
  15453. DEBUG_INFO("handleHeartbeatResponse...\n");
  15454. json_object *Heartbeat;
  15455. Heartbeat = json_tokener_parse(payload);
  15456. if(!is_error(Heartbeat))
  15457. {
  15458. // Required data
  15459. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15460. }
  15461. json_object_put(Heartbeat);
  15462. if(FirstHeartBeat == 0)
  15463. {
  15464. FirstHeartBeat = 1;
  15465. DEBUG_INFO("FirstHeartBeat \n");
  15466. }
  15467. HeartBeatWithNOResponse = 0;
  15468. refreshStartTimer(&clientTime.Heartbeat);
  15469. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15470. }
  15471. void handleMeterValuesResponse(char *payload, int gun_index)
  15472. {
  15473. mtrace();
  15474. DEBUG_INFO("handleMeterValuesResponse...\n");
  15475. isQueueSendable = 1;
  15476. }
  15477. void handleStartTransactionResponse(char *payload, int gun_index)
  15478. {
  15479. mtrace();
  15480. //int transactionIdInt = 0;
  15481. FILE *outfile;
  15482. char data[100]={0};
  15483. DEBUG_INFO("handleStartTransactionResponse...\n");
  15484. json_object *StartTransaction;
  15485. StartTransaction = json_tokener_parse(payload);
  15486. if(!is_error(StartTransaction))
  15487. {
  15488. // Required data
  15489. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15490. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15491. // Optional data
  15492. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15493. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15494. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15495. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15496. }
  15497. json_object_put(StartTransaction);
  15498. OCPP_updatePeriodEnergy(gun_index);
  15499. //-----------Start : write to the Queue TransactionId file -----------------//
  15500. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15501. {}
  15502. else
  15503. {
  15504. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15505. if(log == NULL)
  15506. {
  15507. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15508. return ;
  15509. }
  15510. else
  15511. {
  15512. fclose(log);
  15513. }
  15514. }
  15515. // open file for writing
  15516. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15517. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15518. {
  15519. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15520. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15521. fputs(data, outfile);
  15522. fclose (outfile);
  15523. }
  15524. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15525. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15526. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15527. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15528. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15529. isQueueSendable = 1;
  15530. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15531. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15532. }
  15533. void handleStatusNotificationResponse(char *payload, int gun_index)
  15534. {
  15535. mtrace();
  15536. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15537. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15538. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15539. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15540. }
  15541. void handleStopTransactionnResponse(char *payload, int gun_index)
  15542. {
  15543. mtrace();
  15544. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15545. json_object *StopTransaction;
  15546. StopTransaction = json_tokener_parse(payload);
  15547. if(!is_error(StopTransaction))
  15548. {
  15549. // Optional data
  15550. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15551. {
  15552. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15553. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15554. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15555. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15556. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15557. }
  15558. }
  15559. json_object_put(StopTransaction);
  15560. isQueueSendable = 1;
  15561. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15562. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15563. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15564. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15565. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15566. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15567. }
  15568. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15569. {
  15570. mtrace();
  15571. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15572. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15573. }
  15574. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15575. {
  15576. mtrace();
  15577. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15578. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15579. }
  15580. void handleSignCertificateResponse(char *payload, int gun_index)
  15581. {
  15582. mtrace();
  15583. DEBUG_INFO("handleSignCertificateResponse...\n");
  15584. json_object *SignCertificate;
  15585. SignCertificate = json_tokener_parse(payload);
  15586. if(!is_error(SignCertificate))
  15587. {
  15588. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15589. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15590. }
  15591. json_object_put(SignCertificate);
  15592. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15593. }
  15594. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15595. {
  15596. mtrace();
  15597. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15598. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15599. }
  15600. //==========================================
  15601. // Handle Error routine
  15602. //==========================================
  15603. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15604. {
  15605. mtrace();
  15606. #ifdef SystemLogMessage
  15607. DEBUG_INFO("errorCode: %s\n", errorCode);
  15608. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15609. DEBUG_INFO("errorDetails: %s\n", payload);
  15610. #endif
  15611. }
  15612. //===============================================
  15613. // Common routine
  15614. //===============================================
  15615. int initialConfigurationTable(void)
  15616. {
  15617. //clock_t start_t, end_t, total_t;
  15618. FILE *fp;
  15619. FILE *outfile;
  15620. char str[512]={0};
  15621. char sstr[256]={0};
  15622. int c = 0;
  15623. char *loc;
  15624. int confVersion = 21;
  15625. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15626. //start_t = clock();
  15627. //printf("Starting of the program, start_t = %ld\n", start_t);
  15628. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15629. // Check configuration file size is correct
  15630. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15631. {
  15632. struct stat st;
  15633. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15634. if(st.st_size < 3100)
  15635. {
  15636. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15637. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15638. }
  15639. }
  15640. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15641. {
  15642. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15643. if(outfile == NULL)
  15644. {
  15645. DEBUG_INFO("Error opening file\n");
  15646. return FALSE;
  15647. }
  15648. /*Core Profile*/
  15649. //AllowOfflineTxForUnknownId
  15650. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15654. //AuthorizationCacheEnabled
  15655. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15659. //AuthorizeRemoteTxRequests
  15660. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15664. //BlinkRepeat
  15665. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15669. //ClockAlignedDataInterval
  15670. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15674. //ConnectionTimeOut
  15675. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15677. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15679. else
  15680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15682. //GetConfigurationMaxKeys
  15683. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15687. // HeartbeatInterval
  15688. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15692. // LightIntensity
  15693. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15697. // LocalAuthorizeOffline
  15698. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15702. // LocalPreAuthorize
  15703. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15707. // MaxEnergyOnInvalidId
  15708. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15712. // MeterValuesAlignedData
  15713. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15715. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15716. 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" );
  15717. else
  15718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15720. // MeterValuesAlignedDataMaxLength
  15721. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15723. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15725. else
  15726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15728. // MeterValuesSampledData
  15729. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15731. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15732. 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" );
  15733. else
  15734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15736. // MeterValuesSampledDataMaxLength
  15737. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15741. else
  15742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15744. // MeterValueSampleInterval
  15745. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15749. // MinimumStatusDuration
  15750. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15753. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15755. // NumberOfConnectors
  15756. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15759. {
  15760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15761. }
  15762. else
  15763. {
  15764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15765. }
  15766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15767. // ResetRetries
  15768. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15772. // ConnectorPhaseRotation
  15773. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15777. // ConnectorPhaseRotationMaxLength
  15778. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15782. // StopTransactionOnEVSideDisconnect
  15783. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15787. // StopTransactionOnInvalidId
  15788. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15792. // StopTxnAlignedData
  15793. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15797. // StopTxnAlignedDataMaxLength
  15798. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15802. // StopTxnSampledData
  15803. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15805. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  15807. else
  15808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  15809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15810. // StopTxnSampledDataMaxLength
  15811. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15813. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15814. {
  15815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  15816. }
  15817. else
  15818. {
  15819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  15820. }
  15821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15822. // SupportedFeatureProfiles
  15823. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15827. // SupportedFeatureProfilesMaxLength
  15828. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15832. // TransactionMessageAttempts
  15833. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15836. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15838. // TransactionMessageRetryInterval
  15839. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15842. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15844. // UnlockConnectorOnEVSideDisconnect
  15845. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15849. // WebSocketPingInterval
  15850. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15854. // QueueOffLineMeterValues
  15855. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15859. // AuthorizationKey
  15860. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15864. // SecurityProfile
  15865. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15869. // DefaultPrice
  15870. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15874. // CustomDisplayCostAndPrice
  15875. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15879. // CustomIdleFeeAfterStop
  15880. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15884. // TimeOffset
  15885. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15889. // NextTimeOffsetTransitionDateTime
  15890. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15894. // TimeOffsetNextTransition
  15895. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15899. // SystemUptimeSec
  15900. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15904. // FreeVend
  15905. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15909. // FreeVendIdtag
  15910. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15914. // OcppServer
  15915. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15917. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15919. // MaintainServer
  15920. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15922. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15924. // StatusNotificationPeriodically
  15925. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15929. // StatusNotificationInterval
  15930. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15934. // PreAuthAmount
  15935. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15939. // isEnableLocalPowerSharing
  15940. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15944. // PowerSharingServerIP
  15945. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15947. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15949. // EVCCID_PREFIX
  15950. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15954. // OffLineMaxChargingPower
  15955. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15959. // Configuration Version
  15960. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15962. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15964. // Charging profile refresh interval
  15965. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15969. // CpoName
  15970. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15974. // Ocpp Software certificated version
  15975. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15979. //* Local Auth List Management Profile*/
  15980. #if 0
  15981. //For OCTT Test Case
  15982. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15985. #endif
  15986. #if 1
  15987. //LocalAuthListEnabled
  15988. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15992. #endif
  15993. //LocalAuthListMaxLength
  15994. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15998. //SendLocalListMaxLength
  15999. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  16002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16003. //ReserveConnectorZeroSupported
  16004. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16008. //* Smart Charging Profile */
  16009. //ChargeProfileMaxStackLevel
  16010. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  16013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16014. // ChargingScheduleAllowedChargingRateUnit
  16015. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  16018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16019. // ChargingScheduleMaxPeriods
  16020. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16024. // ConnectorSwitch3to1PhaseSupported
  16025. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  16028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16029. // MaxChargingProfilesInstalled
  16030. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  16033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16034. fclose(outfile);
  16035. }
  16036. else
  16037. {
  16038. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  16039. char keystr[60]={0};
  16040. char readonlystr[10]={0};
  16041. char valuestr[256]={0};
  16042. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  16043. if(fp == NULL) {
  16044. DEBUG_INFO("Error opening file");
  16045. return FALSE;
  16046. }
  16047. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  16048. {
  16049. //DEBUG_INFO("Get Configuration \n");
  16050. if(strlen(str) > 0)
  16051. {
  16052. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16053. //*************************key*********************************/
  16054. if(strstr(str, "key") != NULL)
  16055. {
  16056. loc = strstr(str, "key");
  16057. c = 0;
  16058. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16059. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  16060. {
  16061. sstr[c] = loc[strlen("key")+3+c];
  16062. c++;
  16063. }
  16064. sstr[c] = '\0';
  16065. strcpy(keystr,sstr);
  16066. }
  16067. //*************************readonly*********************************/
  16068. if(strstr(str, "readonly") != NULL)
  16069. {
  16070. loc = strstr(str, "readonly");
  16071. c = 0;
  16072. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16073. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  16074. {
  16075. sstr[c] = loc[strlen("readonly")+2+c];
  16076. c++;
  16077. }
  16078. sstr[c] = '\0';
  16079. strcpy(readonlystr,sstr);
  16080. }
  16081. //*************************value*********************************/
  16082. if(strstr(str, "value") != NULL)
  16083. {
  16084. loc = strstr(str, "value");
  16085. c = 0;
  16086. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16087. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  16088. {
  16089. sstr[c] = loc[strlen("value")+3+c];
  16090. c++;
  16091. }
  16092. sstr[c] = '\0';
  16093. strcpy(valuestr,sstr);
  16094. }
  16095. // DEBUG_INFO("keystr=%s\n",keystr);
  16096. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  16097. // DEBUG_INFO("valuestr=%s\n",valuestr);
  16098. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  16099. {
  16100. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16101. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  16103. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16104. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16105. }
  16106. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  16107. {
  16108. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16109. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  16111. }
  16112. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  16113. {
  16114. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  16116. }
  16117. if(strcmp(keystr, "BlinkRepeat") == 0)
  16118. {
  16119. //Charger.BlinkRepeat = Integer.parseInt(value);
  16120. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  16122. }
  16123. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  16124. {
  16125. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  16127. }
  16128. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16129. {
  16130. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16132. }
  16133. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16134. {
  16135. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16137. }
  16138. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16139. {
  16140. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16142. HeartBeatWaitTime = atoi(valuestr);
  16143. }
  16144. if(strcmp(keystr, "LightIntensity") == 0)
  16145. {
  16146. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16148. }
  16149. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16150. {
  16151. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16153. }
  16154. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16155. {
  16156. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16158. }
  16159. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16160. {
  16161. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16163. }
  16164. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16165. {
  16166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16168. }
  16169. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16170. {
  16171. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16173. }
  16174. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16175. {
  16176. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16178. }
  16179. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16180. {
  16181. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16183. }
  16184. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16185. {
  16186. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16188. }
  16189. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16190. {
  16191. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16193. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16194. }
  16195. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16196. {
  16197. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16199. }
  16200. if(strcmp(keystr, "ResetRetries") == 0)
  16201. {
  16202. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16204. }
  16205. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16206. {
  16207. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16209. }
  16210. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16211. {
  16212. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16214. }
  16215. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16216. {
  16217. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16219. }
  16220. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16221. {
  16222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16224. }
  16225. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16226. {
  16227. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16229. }
  16230. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16231. {
  16232. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16234. }
  16235. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16236. {
  16237. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16239. }
  16240. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16241. {
  16242. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16244. }
  16245. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16246. {
  16247. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16249. }
  16250. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16251. {
  16252. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16254. }
  16255. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16256. {
  16257. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16259. TransactionMessageAttemptsValue = atoi(valuestr);
  16260. }
  16261. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16262. {
  16263. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16265. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16266. }
  16267. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16268. {
  16269. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16271. }
  16272. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16273. {
  16274. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16276. }
  16277. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16278. {
  16279. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16281. }
  16282. if(strcmp(keystr, "AuthorizationKey") == 0)
  16283. {
  16284. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16285. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16287. }
  16288. if(strcmp(keystr, "SecurityProfile") == 0)
  16289. {
  16290. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16292. }
  16293. if(strcmp(keystr, "DefaultPrice") == 0)
  16294. {
  16295. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16297. }
  16298. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16299. {
  16300. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16302. }
  16303. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16304. {
  16305. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16307. }
  16308. if(strcmp(keystr, "TimeOffset") == 0)
  16309. {
  16310. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16312. }
  16313. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16314. {
  16315. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16317. }
  16318. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16319. {
  16320. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16322. }
  16323. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16324. {
  16325. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16327. }
  16328. if(strcmp(keystr, "FreeVend") == 0)
  16329. {
  16330. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16332. }
  16333. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16334. {
  16335. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16337. }
  16338. if(strcmp(keystr, "OcppServer") == 0)
  16339. {
  16340. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16341. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16342. }
  16343. if(strcmp(keystr, "MaintainServer") == 0)
  16344. {
  16345. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16346. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16347. }
  16348. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16349. {
  16350. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16352. }
  16353. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16354. {
  16355. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16357. }
  16358. if(strcmp(keystr, "PreAuthAmount") == 0)
  16359. {
  16360. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16362. }
  16363. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16364. {
  16365. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16367. }
  16368. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16369. {
  16370. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16371. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16372. }
  16373. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16374. {
  16375. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16377. }
  16378. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16379. {
  16380. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16382. }
  16383. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16384. {
  16385. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16387. }
  16388. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16389. {
  16390. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16392. }
  16393. if(strcmp(keystr, "CpoName") == 0)
  16394. {
  16395. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16397. }
  16398. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16399. {
  16400. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16402. }
  16403. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16404. {
  16405. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16407. }
  16408. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16409. {
  16410. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16412. }
  16413. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16414. {
  16415. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16417. }
  16418. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16419. {
  16420. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16422. }
  16423. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16424. {
  16425. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16427. }
  16428. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16429. {
  16430. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16432. }
  16433. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16434. {
  16435. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16437. }
  16438. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16439. {
  16440. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16442. }
  16443. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16444. {
  16445. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16447. }
  16448. }
  16449. }
  16450. fclose(fp);
  16451. }
  16452. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16453. {
  16454. return PASS;
  16455. }
  16456. else
  16457. {
  16458. return FAIL;
  16459. }
  16460. }
  16461. void StoreConfigurationTable(void)
  16462. {
  16463. FILE *outfile;
  16464. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16465. if(outfile == NULL)
  16466. {
  16467. DEBUG_INFO("Error opening file");
  16468. return ;
  16469. }
  16470. /*Core Profile*/
  16471. //AllowOfflineTxForUnknownId
  16472. /*
  16473. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16474. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16477. */
  16478. //DEBUG_INFO("data=%s\n",data);
  16479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16480. //AuthorizationCacheEnabled
  16481. /*
  16482. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16485. */
  16486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16487. //AuthorizeRemoteTxRequests
  16488. /*
  16489. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16492. */
  16493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16494. //BlinkRepeat
  16495. /*
  16496. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16499. */
  16500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16501. //ClockAlignedDataInterval
  16502. /*
  16503. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16506. */
  16507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16508. //ConnectionTimeOut
  16509. /*
  16510. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16513. */
  16514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16515. //GetConfigurationMaxKeys
  16516. /*
  16517. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16520. */
  16521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16522. // HeartbeatInterval
  16523. /*
  16524. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16527. */
  16528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16529. // LightIntensity
  16530. /*
  16531. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16534. */
  16535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16536. // LocalAuthorizeOffline
  16537. /*
  16538. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16541. */
  16542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16543. // LocalPreAuthorize
  16544. /*
  16545. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16548. */
  16549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16550. // MaxEnergyOnInvalidId
  16551. /*
  16552. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16555. */
  16556. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16558. // MeterValuesAlignedData
  16559. /*
  16560. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16563. */
  16564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16565. // MeterValuesAlignedDataMaxLength
  16566. /*
  16567. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16570. */
  16571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16572. // MeterValuesSampledData
  16573. /*
  16574. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16577. */
  16578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16579. // MeterValuesSampledDataMaxLength
  16580. /*
  16581. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16584. */
  16585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16586. // MeterValueSampleInterval
  16587. /*
  16588. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16591. */
  16592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16593. // MinimumStatusDuration
  16594. /*
  16595. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16598. */
  16599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16600. // NumberOfConnectors
  16601. /*
  16602. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16604. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16605. {
  16606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16607. }
  16608. else
  16609. {
  16610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16611. }
  16612. */
  16613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16614. // ResetRetries
  16615. /*
  16616. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16619. */
  16620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16621. // ConnectorPhaseRotation
  16622. /*
  16623. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16626. */
  16627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16628. // ConnectorPhaseRotationMaxLength
  16629. /*
  16630. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16633. */
  16634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16635. // StopTransactionOnEVSideDisconnect
  16636. /*
  16637. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16640. */
  16641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16642. // StopTransactionOnInvalidId
  16643. /*
  16644. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16647. */
  16648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16649. // StopTxnAlignedData
  16650. /*
  16651. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16654. */
  16655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16656. // StopTxnAlignedDataMaxLength
  16657. /*
  16658. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16661. */
  16662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16663. // StopTxnSampledData
  16664. /*
  16665. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16668. */
  16669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16670. // StopTxnSampledDataMaxLength
  16671. /*
  16672. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16675. */
  16676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16677. // SupportedFeatureProfiles
  16678. /*
  16679. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16682. */
  16683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16684. // SupportedFeatureProfilesMaxLength
  16685. /*
  16686. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16689. */
  16690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16691. // TransactionMessageAttempts
  16692. /*
  16693. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16696. */
  16697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16698. // TransactionMessageRetryInterval
  16699. /*
  16700. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16703. */
  16704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16705. // UnlockConnectorOnEVSideDisconnect
  16706. /*
  16707. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16710. */
  16711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16712. // WebSocketPingInterval
  16713. /*
  16714. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16717. */
  16718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16719. // QueueOffLineMeterValues
  16720. /*
  16721. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16724. */
  16725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16726. // AuthorizationKey
  16727. /*
  16728. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16731. */
  16732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16733. // SecurityProfile
  16734. /*
  16735. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16738. */
  16739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16740. // DefaultPrice
  16741. /*
  16742. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16745. */
  16746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16747. // CustomDisplayCostAndPrice
  16748. /*
  16749. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16752. */
  16753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16754. // CustomIdleFeeAfterStop
  16755. /*
  16756. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16759. */
  16760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16761. // TimeOffset
  16762. /*
  16763. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16766. */
  16767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16768. // NextTimeOffsetTransitionDateTime
  16769. /*
  16770. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16773. */
  16774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16775. // TimeOffsetNextTransition
  16776. /*
  16777. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16780. */
  16781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16782. // SystemUptimeSec
  16783. /*
  16784. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16787. */
  16788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16789. // FreeVend
  16790. /*
  16791. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16794. */
  16795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16796. // FreeVendIdtag
  16797. /*
  16798. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16801. */
  16802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16803. // OcppServer
  16804. /*
  16805. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16808. */
  16809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16810. // MaintainServer
  16811. /*
  16812. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16815. */
  16816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16817. // StatusNotificationPeriodically
  16818. /*
  16819. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16822. */
  16823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16824. // StatusNotificationInterval
  16825. /*
  16826. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16829. */
  16830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16831. // PreAuthAmount
  16832. /*
  16833. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16836. */
  16837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16838. // isEnableLocalPowerSharing
  16839. /*
  16840. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16843. */
  16844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16845. // PowerSharingServerIP
  16846. /*
  16847. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16850. */
  16851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16852. // EVCCID_PREFIX
  16853. /*
  16854. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16857. */
  16858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16859. // OffLineMaxChargingPower
  16860. /*
  16861. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16864. */
  16865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16866. // ConfigurationVersion
  16867. /*
  16868. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16871. */
  16872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16873. // CharingProfileRefreshInterval
  16874. /*
  16875. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16878. */
  16879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16880. // CpoName
  16881. /*
  16882. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16885. */
  16886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16887. // OcppSoftwareVersion
  16888. /*
  16889. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16892. */
  16893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16894. //* Local Auth List Management Profile*/
  16895. //LocalAuthListEnabled
  16896. /*
  16897. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16900. */
  16901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16902. //LocalAuthListMaxLength
  16903. /*
  16904. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16907. */
  16908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16909. //SendLocalListMaxLength
  16910. /*
  16911. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16914. */
  16915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16916. //ReserveConnectorZeroSupported
  16917. /*
  16918. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16921. */
  16922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16923. //* Smart Charging Profile */
  16924. //ChargeProfileMaxStackLevel
  16925. /*
  16926. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16929. */
  16930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16931. // ChargingScheduleAllowedChargingRateUnit
  16932. /*
  16933. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16936. */
  16937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16938. // ChargingScheduleMaxPeriods
  16939. /*
  16940. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16943. */
  16944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16945. // ConnectorSwitch3to1PhaseSupported
  16946. /*
  16947. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16950. */
  16951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16952. // MaxChargingProfilesInstalled
  16953. /*
  16954. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16957. */
  16958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16959. fclose(outfile);
  16960. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16961. }
  16962. void getKeyValue(char *keyReq)
  16963. {
  16964. int isEmpty = FALSE;
  16965. int isKnowKey = FALSE;
  16966. DEBUG_INFO("keyReq = %s\n", keyReq);
  16967. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16968. isEmpty = TRUE;
  16969. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16970. {
  16971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16974. {
  16975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16976. }
  16977. else
  16978. {
  16979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16980. }
  16981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16982. isKnowKey = TRUE;
  16983. }
  16984. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16985. {
  16986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16989. {
  16990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16991. }
  16992. else
  16993. {
  16994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16995. }
  16996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16997. isKnowKey = TRUE;
  16998. }
  16999. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  17000. {
  17001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  17002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  17003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17004. {
  17005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  17006. }
  17007. else
  17008. {
  17009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  17010. }
  17011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  17012. isKnowKey = TRUE;
  17013. }
  17014. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  17015. {
  17016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  17017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  17018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17019. {
  17020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  17021. }
  17022. else
  17023. {
  17024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  17025. }
  17026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  17027. isKnowKey = TRUE;
  17028. }
  17029. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  17030. {
  17031. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  17032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  17033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17034. {
  17035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  17036. }
  17037. else
  17038. {
  17039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  17040. }
  17041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  17042. isKnowKey = TRUE;
  17043. }
  17044. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  17045. {
  17046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  17048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17049. {
  17050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  17051. }
  17052. else
  17053. {
  17054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  17055. }
  17056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  17057. isKnowKey = TRUE;
  17058. }
  17059. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  17060. {
  17061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  17063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17064. {
  17065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  17066. }
  17067. else
  17068. {
  17069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  17070. }
  17071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  17072. isKnowKey = TRUE;
  17073. }
  17074. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  17075. {
  17076. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  17078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17079. {
  17080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  17081. }
  17082. else
  17083. {
  17084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  17085. }
  17086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  17087. isKnowKey = TRUE;
  17088. }
  17089. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  17090. {
  17091. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  17093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17094. {
  17095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  17096. }
  17097. else
  17098. {
  17099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  17100. }
  17101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  17102. isKnowKey = TRUE;
  17103. }
  17104. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  17105. {
  17106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  17108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17109. {
  17110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  17111. }
  17112. else
  17113. {
  17114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  17115. }
  17116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  17117. isKnowKey = TRUE;
  17118. }
  17119. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  17120. {
  17121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  17122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  17123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17124. {
  17125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  17126. }
  17127. else
  17128. {
  17129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17130. }
  17131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17132. isKnowKey = TRUE;
  17133. }
  17134. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17135. {
  17136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17139. {
  17140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17141. }
  17142. else
  17143. {
  17144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17145. }
  17146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17147. isKnowKey = TRUE;
  17148. }
  17149. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17150. {
  17151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17154. {
  17155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17156. }
  17157. else
  17158. {
  17159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17160. }
  17161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17162. isKnowKey = TRUE;
  17163. }
  17164. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17165. {
  17166. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17169. {
  17170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17171. }
  17172. else
  17173. {
  17174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17175. }
  17176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17177. isKnowKey = TRUE;
  17178. }
  17179. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17180. {
  17181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17184. {
  17185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17186. }
  17187. else
  17188. {
  17189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17190. }
  17191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17192. isKnowKey = TRUE;
  17193. }
  17194. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17195. {
  17196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17199. {
  17200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17201. }
  17202. else
  17203. {
  17204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17205. }
  17206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17207. isKnowKey = TRUE;
  17208. }
  17209. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17210. {
  17211. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17214. {
  17215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17216. }
  17217. else
  17218. {
  17219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17220. }
  17221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17222. isKnowKey = TRUE;
  17223. }
  17224. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17225. {
  17226. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17229. {
  17230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17231. }
  17232. else
  17233. {
  17234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17235. }
  17236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17237. isKnowKey = TRUE;
  17238. }
  17239. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17240. {
  17241. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17243. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17244. {
  17245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17246. }
  17247. else
  17248. {
  17249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17250. }
  17251. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17253. isKnowKey = TRUE;
  17254. }
  17255. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17256. {
  17257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17260. {
  17261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17262. }
  17263. else
  17264. {
  17265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17266. }
  17267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17268. isKnowKey = TRUE;
  17269. }
  17270. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17271. {
  17272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17275. {
  17276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17277. }
  17278. else
  17279. {
  17280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17281. }
  17282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17283. isKnowKey = TRUE;
  17284. }
  17285. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17286. {
  17287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17290. {
  17291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17292. }
  17293. else
  17294. {
  17295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17296. }
  17297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17298. isKnowKey = TRUE;
  17299. }
  17300. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17301. {
  17302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17305. {
  17306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17307. }
  17308. else
  17309. {
  17310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17311. }
  17312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17313. isKnowKey = TRUE;
  17314. }
  17315. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17316. {
  17317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17320. {
  17321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17322. }
  17323. else
  17324. {
  17325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17326. }
  17327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17328. isKnowKey = TRUE;
  17329. }
  17330. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17331. {
  17332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17335. {
  17336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17337. }
  17338. else
  17339. {
  17340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17341. }
  17342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17343. isKnowKey = TRUE;
  17344. }
  17345. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17346. {
  17347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17350. {
  17351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17352. }
  17353. else
  17354. {
  17355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17356. }
  17357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17358. isKnowKey = TRUE;
  17359. }
  17360. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17361. {
  17362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17365. {
  17366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17367. }
  17368. else
  17369. {
  17370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17371. }
  17372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17373. isKnowKey = TRUE;
  17374. }
  17375. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17376. {
  17377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17380. {
  17381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17382. }
  17383. else
  17384. {
  17385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17386. }
  17387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17388. isKnowKey = TRUE;
  17389. }
  17390. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17391. {
  17392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17395. {
  17396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17397. }
  17398. else
  17399. {
  17400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17401. }
  17402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17403. isKnowKey = TRUE;
  17404. }
  17405. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17406. {
  17407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17410. {
  17411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17412. }
  17413. else
  17414. {
  17415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17416. }
  17417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17418. isKnowKey = TRUE;
  17419. }
  17420. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17421. {
  17422. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17425. {
  17426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17427. }
  17428. else
  17429. {
  17430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17431. }
  17432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17433. isKnowKey = TRUE;
  17434. }
  17435. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17436. {
  17437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17440. {
  17441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17442. }
  17443. else
  17444. {
  17445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17446. }
  17447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17448. isKnowKey = TRUE;
  17449. }
  17450. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17451. {
  17452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17455. {
  17456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17457. }
  17458. else
  17459. {
  17460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17461. }
  17462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17463. isKnowKey = TRUE;
  17464. }
  17465. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17466. {
  17467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17470. {
  17471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17472. }
  17473. else
  17474. {
  17475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17476. }
  17477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17478. isKnowKey = TRUE;
  17479. }
  17480. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17481. {
  17482. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17485. {
  17486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17487. }
  17488. else
  17489. {
  17490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17491. }
  17492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17493. isKnowKey = TRUE;
  17494. }
  17495. /*
  17496. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17497. {
  17498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17501. {
  17502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17503. }
  17504. else
  17505. {
  17506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17507. }
  17508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17509. isKnowKey = TRUE;
  17510. }*/
  17511. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17512. {
  17513. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17516. {
  17517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17518. }
  17519. else
  17520. {
  17521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17522. }
  17523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17524. isKnowKey = TRUE;
  17525. }
  17526. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17527. {
  17528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17531. {
  17532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17533. }
  17534. else
  17535. {
  17536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17537. }
  17538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17539. isKnowKey = TRUE;
  17540. }
  17541. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17542. {
  17543. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17546. {
  17547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17548. }
  17549. else
  17550. {
  17551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17552. }
  17553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17554. isKnowKey = TRUE;
  17555. }
  17556. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17557. {
  17558. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17561. {
  17562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17563. }
  17564. else
  17565. {
  17566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17567. }
  17568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17569. isKnowKey = TRUE;
  17570. }
  17571. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17572. {
  17573. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17576. {
  17577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17578. }
  17579. else
  17580. {
  17581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17582. }
  17583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17584. isKnowKey = TRUE;
  17585. }
  17586. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17587. {
  17588. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17591. {
  17592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17593. }
  17594. else
  17595. {
  17596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17597. }
  17598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17599. isKnowKey = TRUE;
  17600. }
  17601. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17602. {
  17603. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17606. {
  17607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17608. }
  17609. else
  17610. {
  17611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17612. }
  17613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17614. isKnowKey = TRUE;
  17615. }
  17616. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17617. {
  17618. struct sysinfo s_info;
  17619. int error = sysinfo(&s_info);
  17620. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17623. {
  17624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17625. }
  17626. else
  17627. {
  17628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17629. }
  17630. if(error != 0)
  17631. {
  17632. DEBUG_WARN("System uptime get error: %d\n", error);
  17633. }
  17634. else
  17635. {
  17636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17637. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17638. }
  17639. isKnowKey = TRUE;
  17640. }
  17641. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17642. {
  17643. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17646. {
  17647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17648. }
  17649. else
  17650. {
  17651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17652. }
  17653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17654. isKnowKey = TRUE;
  17655. }
  17656. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17657. {
  17658. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17660. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17661. {
  17662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17663. }
  17664. else
  17665. {
  17666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17667. }
  17668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17669. isKnowKey = TRUE;
  17670. }
  17671. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17672. {
  17673. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17676. {
  17677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17678. }
  17679. else
  17680. {
  17681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17682. }
  17683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17684. isKnowKey = TRUE;
  17685. }
  17686. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17687. {
  17688. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17691. {
  17692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17693. }
  17694. else
  17695. {
  17696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17697. }
  17698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17699. isKnowKey = TRUE;
  17700. }
  17701. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17702. {
  17703. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17706. {
  17707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17708. }
  17709. else
  17710. {
  17711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17712. }
  17713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17714. isKnowKey = TRUE;
  17715. }
  17716. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17717. {
  17718. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17721. {
  17722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17723. }
  17724. else
  17725. {
  17726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17727. }
  17728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17729. isKnowKey = TRUE;
  17730. }
  17731. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17732. {
  17733. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17736. {
  17737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17738. }
  17739. else
  17740. {
  17741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17742. }
  17743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17744. isKnowKey = TRUE;
  17745. }
  17746. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17747. {
  17748. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17750. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17751. {
  17752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17753. }
  17754. else
  17755. {
  17756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17757. }
  17758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17759. isKnowKey = TRUE;
  17760. }
  17761. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17762. {
  17763. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17766. {
  17767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17768. }
  17769. else
  17770. {
  17771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17772. }
  17773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17774. isKnowKey = TRUE;
  17775. }
  17776. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17777. {
  17778. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17781. {
  17782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17783. }
  17784. else
  17785. {
  17786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17787. }
  17788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17789. isKnowKey = TRUE;
  17790. }
  17791. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17792. {
  17793. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17796. {
  17797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17798. }
  17799. else
  17800. {
  17801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17802. }
  17803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17804. isKnowKey = TRUE;
  17805. }
  17806. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17807. {
  17808. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17810. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17811. {
  17812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17813. }
  17814. else
  17815. {
  17816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17817. }
  17818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17819. isKnowKey = TRUE;
  17820. }
  17821. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17822. {
  17823. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17826. {
  17827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17828. }
  17829. else
  17830. {
  17831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17832. }
  17833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17834. isKnowKey = TRUE;
  17835. }
  17836. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17837. {
  17838. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17841. {
  17842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17843. }
  17844. else
  17845. {
  17846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17847. }
  17848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17849. isKnowKey = TRUE;
  17850. }
  17851. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17852. {
  17853. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17856. {
  17857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17858. }
  17859. else
  17860. {
  17861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17862. }
  17863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17864. isKnowKey = TRUE;
  17865. }
  17866. #if 1
  17867. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17868. {
  17869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17871. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17872. {
  17873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17874. }
  17875. else
  17876. {
  17877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17878. }
  17879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17880. isKnowKey = TRUE;
  17881. }
  17882. #endif
  17883. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17884. {
  17885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17887. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17888. {
  17889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17890. }
  17891. else
  17892. {
  17893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17894. }
  17895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17896. isKnowKey = TRUE;
  17897. }
  17898. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17899. {
  17900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17902. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17903. {
  17904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17905. }
  17906. else
  17907. {
  17908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17909. }
  17910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17911. isKnowKey = TRUE;
  17912. }
  17913. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17914. {
  17915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17917. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17918. {
  17919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17920. }
  17921. else
  17922. {
  17923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17924. }
  17925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17926. isKnowKey = TRUE;
  17927. }
  17928. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17929. {
  17930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17932. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17933. {
  17934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17935. }
  17936. else
  17937. {
  17938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17939. }
  17940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17941. isKnowKey = TRUE;
  17942. }
  17943. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17944. {
  17945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17947. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17948. {
  17949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17950. }
  17951. else
  17952. {
  17953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17954. }
  17955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17956. isKnowKey = TRUE;
  17957. }
  17958. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17959. {
  17960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17962. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17963. {
  17964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17965. }
  17966. else
  17967. {
  17968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17969. }
  17970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17971. isKnowKey = TRUE;
  17972. }
  17973. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17974. {
  17975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17977. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17978. {
  17979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17980. }
  17981. else
  17982. {
  17983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17984. }
  17985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17986. isKnowKey = TRUE;
  17987. }
  17988. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17989. {
  17990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17992. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17993. {
  17994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17995. }
  17996. else
  17997. {
  17998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17999. }
  18000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  18001. isKnowKey = TRUE;
  18002. }
  18003. //=========================================================
  18004. if(!isEmpty && !isKnowKey)
  18005. {
  18006. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  18007. strcpy(unknownkey[UnknownKeynum], keyReq);
  18008. UnknownKeynum = UnknownKeynum + 1;
  18009. }
  18010. }
  18011. void processUnkownKey(void)
  18012. {
  18013. DEBUG_INFO("processUnkownKey...\n");
  18014. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  18015. for(int index=0; index < UnknownKeynum; index++)
  18016. {
  18017. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  18018. {
  18019. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  18020. }
  18021. }
  18022. }
  18023. int setKeyValue(char *key, char *value)
  18024. {
  18025. int isSuccess = NotSupported;
  18026. int check_ascii=0;
  18027. char str[501]={0};
  18028. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  18029. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  18030. {
  18031. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  18032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  18033. {
  18034. strcpy(str, (const char*)value);
  18035. for(int i = 0; str[i]; i++){
  18036. str[i] = tolower(str[i]);
  18037. }
  18038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18039. isSuccess = ConfigurationStatus_Accepted;
  18040. }
  18041. else
  18042. {
  18043. isSuccess = ConfigurationStatus_Rejected;
  18044. }
  18045. }
  18046. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  18047. {
  18048. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  18049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  18050. {
  18051. strcpy(str, (const char*)value);
  18052. for(int i = 0; str[i]; i++){
  18053. str[i] = tolower(str[i]);
  18054. }
  18055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18056. isSuccess = ConfigurationStatus_Accepted;
  18057. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  18058. }
  18059. else
  18060. {
  18061. isSuccess = ConfigurationStatus_Rejected;
  18062. }
  18063. }
  18064. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  18065. {
  18066. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  18067. {
  18068. strcpy(str, (const char*)value);
  18069. for(int i = 0; str[i]; i++)
  18070. {
  18071. str[i] = tolower(str[i]);
  18072. }
  18073. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  18074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18075. isSuccess = ConfigurationStatus_Accepted;
  18076. }
  18077. else
  18078. {
  18079. isSuccess = ConfigurationStatus_Rejected;
  18080. }
  18081. }
  18082. if(strcmp(key, "BlinkRepeat") == 0)
  18083. {
  18084. //Charger.BlinkRepeat = Integer.parseInt(value);
  18085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  18086. {
  18087. check_ascii = value[0];
  18088. if( (check_ascii < 48) || (check_ascii > 57) )
  18089. {
  18090. isSuccess = ConfigurationStatus_Rejected;
  18091. }
  18092. else
  18093. {
  18094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  18095. isSuccess = ConfigurationStatus_Accepted;
  18096. }
  18097. }
  18098. else
  18099. {
  18100. isSuccess = ConfigurationStatus_Rejected;
  18101. }
  18102. }
  18103. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  18104. {
  18105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  18106. {
  18107. check_ascii = value[0];
  18108. if( (check_ascii < 48) || (check_ascii > 57) )
  18109. {
  18110. isSuccess = ConfigurationStatus_Rejected;
  18111. }
  18112. else
  18113. {
  18114. if((atoi(value) == 0) || (atoi(value) >= 5))
  18115. {
  18116. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  18118. isSuccess = ConfigurationStatus_Accepted;
  18119. }
  18120. else
  18121. isSuccess = ConfigurationStatus_Rejected;
  18122. }
  18123. }
  18124. else
  18125. {
  18126. isSuccess = ConfigurationStatus_Rejected;
  18127. }
  18128. }
  18129. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18130. {
  18131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18132. {
  18133. check_ascii = value[0];
  18134. if( (check_ascii < 48) || (check_ascii > 57) )
  18135. {
  18136. isSuccess = ConfigurationStatus_Rejected;
  18137. }
  18138. else
  18139. {
  18140. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18142. isSuccess = ConfigurationStatus_Accepted;
  18143. }
  18144. }
  18145. else
  18146. {
  18147. isSuccess = ConfigurationStatus_Rejected;
  18148. }
  18149. }
  18150. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18151. {
  18152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18153. {
  18154. check_ascii = value[0];
  18155. if( (check_ascii < 48) || (check_ascii > 57) )
  18156. {
  18157. isSuccess = ConfigurationStatus_Rejected;
  18158. }
  18159. else
  18160. {
  18161. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18163. isSuccess = ConfigurationStatus_Accepted;
  18164. }
  18165. }
  18166. else
  18167. {
  18168. isSuccess = ConfigurationStatus_Rejected;
  18169. }
  18170. }
  18171. if(strcmp(key, "HeartbeatInterval") == 0)
  18172. {
  18173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18174. {
  18175. check_ascii = value[0];
  18176. if( (check_ascii < 48) || (check_ascii > 57) )
  18177. {
  18178. isSuccess = ConfigurationStatus_Rejected;
  18179. }
  18180. else
  18181. {
  18182. if((atoi(value) == 0) || (atoi(value) >= 10))
  18183. {
  18184. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18186. HeartBeatWaitTime = atoi(value);
  18187. isSuccess = ConfigurationStatus_Accepted;
  18188. }
  18189. else
  18190. {
  18191. isSuccess = ConfigurationStatus_Rejected;
  18192. }
  18193. }
  18194. }
  18195. else
  18196. {
  18197. isSuccess = ConfigurationStatus_Rejected;
  18198. }
  18199. }
  18200. if(strcmp(key, "LightIntensity") == 0)
  18201. {
  18202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18203. {
  18204. check_ascii = value[0];
  18205. if( (check_ascii < 48) || (check_ascii > 57) )
  18206. {
  18207. isSuccess = ConfigurationStatus_Rejected;
  18208. }
  18209. else
  18210. {
  18211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18212. isSuccess = ConfigurationStatus_Accepted;
  18213. }
  18214. }
  18215. else
  18216. {
  18217. isSuccess = ConfigurationStatus_Rejected;
  18218. }
  18219. }
  18220. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18221. {
  18222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18223. {
  18224. strcpy(str, (const char*)value);
  18225. for(int i = 0; str[i]; i++)
  18226. {
  18227. str[i] = tolower(str[i]);
  18228. }
  18229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18230. isSuccess = ConfigurationStatus_Accepted;
  18231. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18232. }
  18233. else
  18234. {
  18235. isSuccess = ConfigurationStatus_Rejected;
  18236. }
  18237. }
  18238. if(strcmp(key, "LocalPreAuthorize") == 0)
  18239. {
  18240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18241. {
  18242. strcpy(str, (const char*)value);
  18243. for(int i = 0; str[i]; i++)
  18244. {
  18245. str[i] = tolower(str[i]);
  18246. }
  18247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18248. isSuccess = ConfigurationStatus_Accepted;
  18249. }
  18250. else
  18251. {
  18252. isSuccess = ConfigurationStatus_Rejected;
  18253. }
  18254. }
  18255. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18256. {
  18257. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18258. {
  18259. check_ascii = value[0];
  18260. if( (check_ascii < 48) || (check_ascii > 57) )
  18261. {
  18262. isSuccess = ConfigurationStatus_Rejected;
  18263. }
  18264. else
  18265. {
  18266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18267. isSuccess = ConfigurationStatus_Accepted;
  18268. }
  18269. }
  18270. else
  18271. {
  18272. isSuccess = ConfigurationStatus_Rejected;
  18273. }
  18274. }
  18275. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18276. {
  18277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18278. {
  18279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18280. isSuccess = ConfigurationStatus_Accepted;
  18281. }
  18282. else
  18283. {
  18284. isSuccess = ConfigurationStatus_Rejected;
  18285. }
  18286. }
  18287. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18288. {
  18289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18290. {
  18291. check_ascii = value[0];
  18292. if( (check_ascii < 48) || (check_ascii > 57) )
  18293. {
  18294. isSuccess = ConfigurationStatus_Rejected;
  18295. }
  18296. else
  18297. {
  18298. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18300. isSuccess = ConfigurationStatus_Accepted;
  18301. }
  18302. }
  18303. else
  18304. {
  18305. isSuccess = ConfigurationStatus_Rejected;
  18306. }
  18307. }
  18308. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18309. {
  18310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18311. {
  18312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18313. isSuccess = ConfigurationStatus_Accepted;
  18314. }
  18315. else
  18316. {
  18317. isSuccess = ConfigurationStatus_Rejected;
  18318. }
  18319. }
  18320. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18321. {
  18322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18323. {
  18324. check_ascii = value[0];
  18325. if( (check_ascii < 48) || (check_ascii > 57) )
  18326. {
  18327. isSuccess = ConfigurationStatus_Rejected;
  18328. }
  18329. else
  18330. {
  18331. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18333. isSuccess = ConfigurationStatus_Accepted;
  18334. }
  18335. }
  18336. else
  18337. {
  18338. isSuccess = ConfigurationStatus_Rejected;
  18339. }
  18340. }
  18341. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18342. {
  18343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18344. {
  18345. check_ascii = value[0];
  18346. if( (check_ascii < 48) || (check_ascii > 57) )
  18347. {
  18348. isSuccess = ConfigurationStatus_Rejected;
  18349. }
  18350. else
  18351. {
  18352. if((atoi(value) == 0) || (atoi(value) >= 3))
  18353. {
  18354. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18356. isSuccess = ConfigurationStatus_Accepted;
  18357. }
  18358. else
  18359. {
  18360. isSuccess = ConfigurationStatus_Rejected;
  18361. }
  18362. }
  18363. }
  18364. else
  18365. {
  18366. isSuccess = ConfigurationStatus_Rejected;
  18367. }
  18368. }
  18369. if(strcmp(key, "MinimumStatusDuration") == 0)
  18370. {
  18371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18372. {
  18373. check_ascii = value[0];
  18374. if( (check_ascii < 48) || (check_ascii > 57) )
  18375. {
  18376. isSuccess = ConfigurationStatus_Rejected;
  18377. }
  18378. else
  18379. {
  18380. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18381. {
  18382. isSuccess = ConfigurationStatus_Rejected;
  18383. }
  18384. else
  18385. {
  18386. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18388. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18389. isSuccess = ConfigurationStatus_Accepted;
  18390. }
  18391. }
  18392. }
  18393. else
  18394. {
  18395. isSuccess = ConfigurationStatus_Rejected;
  18396. }
  18397. }
  18398. if(strcmp(key, "NumberOfConnectors") == 0)
  18399. {
  18400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18401. {
  18402. check_ascii = value[0];
  18403. if( (check_ascii < 48) || (check_ascii > 57) )
  18404. {
  18405. isSuccess = ConfigurationStatus_Rejected;
  18406. }
  18407. else
  18408. {
  18409. //Charger.ResetRetries = Integer.parseInt(value);
  18410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18411. isSuccess = ConfigurationStatus_Accepted;
  18412. }
  18413. }
  18414. else
  18415. {
  18416. isSuccess = ConfigurationStatus_Rejected;
  18417. }
  18418. }
  18419. if(strcmp(key, "ResetRetries") == 0)
  18420. {
  18421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18422. {
  18423. check_ascii = value[0];
  18424. if( (check_ascii < 48) || (check_ascii > 57) )
  18425. {
  18426. isSuccess = ConfigurationStatus_Rejected;
  18427. }
  18428. else
  18429. {
  18430. //Charger.ResetRetries = Integer.parseInt(value);
  18431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18432. isSuccess = ConfigurationStatus_Accepted;
  18433. }
  18434. }
  18435. else
  18436. {
  18437. isSuccess = ConfigurationStatus_Rejected;
  18438. }
  18439. }
  18440. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18441. {
  18442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18443. {
  18444. strcpy(str, (const char*)value);
  18445. for(int i = 0; str[i]; i++)
  18446. {
  18447. str[i] = tolower(str[i]);
  18448. }
  18449. if(strcmp(str, "notapplicable")== 0)
  18450. {
  18451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18452. isSuccess = ConfigurationStatus_Accepted;
  18453. }
  18454. else if(strcmp(str, "unknown")== 0)
  18455. {
  18456. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18457. isSuccess = ConfigurationStatus_Accepted;
  18458. }
  18459. else if(strcmp(str, "rst")== 0)
  18460. {
  18461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18462. isSuccess = ConfigurationStatus_Accepted;
  18463. }
  18464. else if(strcmp(str, "rts")== 0)
  18465. {
  18466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18467. isSuccess = ConfigurationStatus_Accepted;
  18468. }
  18469. else if(strcmp(str, "srt")== 0)
  18470. {
  18471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18472. isSuccess = ConfigurationStatus_Accepted;
  18473. }
  18474. else if(strcmp(str, "str")== 0)
  18475. {
  18476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18477. isSuccess = ConfigurationStatus_Accepted;
  18478. }
  18479. else if(strcmp(str, "trs")== 0)
  18480. {
  18481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18482. isSuccess = ConfigurationStatus_Accepted;
  18483. }
  18484. else if(strcmp(str, "tsr")== 0)
  18485. {
  18486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18487. isSuccess = ConfigurationStatus_Accepted;
  18488. }
  18489. else
  18490. {
  18491. isSuccess = ConfigurationStatus_Rejected;
  18492. }
  18493. }
  18494. else
  18495. {
  18496. isSuccess = ConfigurationStatus_Rejected;
  18497. }
  18498. }
  18499. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18500. {
  18501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18502. {
  18503. check_ascii = value[0];
  18504. if( (check_ascii < 48) || (check_ascii > 57) )
  18505. {
  18506. isSuccess = ConfigurationStatus_Rejected;
  18507. }
  18508. else
  18509. {
  18510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18511. isSuccess = ConfigurationStatus_Accepted;
  18512. }
  18513. }
  18514. else
  18515. {
  18516. isSuccess = ConfigurationStatus_Rejected;
  18517. }
  18518. }
  18519. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18520. {
  18521. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18522. {
  18523. strcpy(str, (const char*)value);
  18524. for(int i = 0; str[i]; i++)
  18525. {
  18526. str[i] = tolower(str[i]);
  18527. }
  18528. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18530. isSuccess = ConfigurationStatus_Accepted;
  18531. }
  18532. else
  18533. {
  18534. isSuccess = ConfigurationStatus_Rejected;
  18535. }
  18536. }
  18537. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18538. {
  18539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18540. {
  18541. strcpy(str, (const char*)value);
  18542. for(int i = 0; str[i]; i++)
  18543. {
  18544. str[i] = tolower(str[i]);
  18545. }
  18546. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18548. isSuccess = ConfigurationStatus_Accepted;
  18549. }
  18550. else
  18551. {
  18552. isSuccess = ConfigurationStatus_Rejected;
  18553. }
  18554. }
  18555. if(strcmp(key, "StopTxnAlignedData") == 0)
  18556. {
  18557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18558. {
  18559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18560. isSuccess = ConfigurationStatus_Accepted;
  18561. }
  18562. else
  18563. {
  18564. isSuccess = ConfigurationStatus_Rejected;
  18565. }
  18566. }
  18567. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18568. {
  18569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18570. {
  18571. check_ascii = value[0];
  18572. if( (check_ascii < 48) || (check_ascii > 57) )
  18573. {
  18574. isSuccess = ConfigurationStatus_Rejected;
  18575. }
  18576. else
  18577. {
  18578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18579. isSuccess = ConfigurationStatus_Accepted;
  18580. }
  18581. }
  18582. else
  18583. {
  18584. isSuccess = ConfigurationStatus_Rejected;
  18585. }
  18586. }
  18587. if(strcmp(key, "StopTxnSampledData") == 0)
  18588. {
  18589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18590. {
  18591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18592. isSuccess = ConfigurationStatus_Accepted;
  18593. }
  18594. else
  18595. {
  18596. isSuccess = ConfigurationStatus_Rejected;
  18597. }
  18598. }
  18599. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18600. {
  18601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18602. {
  18603. check_ascii = value[0];
  18604. if( (check_ascii < 48) || (check_ascii > 57) )
  18605. {
  18606. isSuccess = ConfigurationStatus_Rejected;
  18607. }
  18608. else
  18609. {
  18610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18611. isSuccess = ConfigurationStatus_Accepted;
  18612. }
  18613. }
  18614. else
  18615. {
  18616. isSuccess = ConfigurationStatus_Rejected;
  18617. }
  18618. }
  18619. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18620. {
  18621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18622. {
  18623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18624. isSuccess = ConfigurationStatus_Accepted;
  18625. }
  18626. else
  18627. {
  18628. isSuccess = ConfigurationStatus_Rejected;
  18629. }
  18630. }
  18631. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18632. {
  18633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18634. {
  18635. check_ascii = value[0];
  18636. if( (check_ascii < 48) || (check_ascii > 57) )
  18637. {
  18638. isSuccess = ConfigurationStatus_Rejected;
  18639. }
  18640. else
  18641. {
  18642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18643. isSuccess = ConfigurationStatus_Accepted;
  18644. }
  18645. }
  18646. else
  18647. {
  18648. isSuccess = ConfigurationStatus_Rejected;
  18649. }
  18650. }
  18651. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18652. {
  18653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18654. {
  18655. check_ascii = value[0];
  18656. if( (check_ascii < 48) || (check_ascii > 57) )
  18657. {
  18658. isSuccess = ConfigurationStatus_Rejected;
  18659. }
  18660. else
  18661. {
  18662. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18664. TransactionMessageAttemptsValue = atoi(value);
  18665. isSuccess = ConfigurationStatus_Accepted;
  18666. }
  18667. }
  18668. else
  18669. {
  18670. isSuccess = ConfigurationStatus_Rejected;
  18671. }
  18672. }
  18673. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18674. {
  18675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18676. {
  18677. check_ascii = value[0];
  18678. if( (check_ascii < 48) || (check_ascii > 57) )
  18679. {
  18680. isSuccess = ConfigurationStatus_Rejected;
  18681. }
  18682. else
  18683. {
  18684. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18686. TransactionMessageRetryIntervalValue = atoi(value);
  18687. isSuccess = ConfigurationStatus_Accepted;
  18688. }
  18689. }
  18690. else
  18691. {
  18692. isSuccess = ConfigurationStatus_Rejected;
  18693. }
  18694. }
  18695. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18696. {
  18697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18698. {
  18699. strcpy(str, (const char*)value);
  18700. for(int i = 0; str[i]; i++)
  18701. {
  18702. str[i] = tolower(str[i]);
  18703. }
  18704. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18706. isSuccess = ConfigurationStatus_Accepted;
  18707. }
  18708. else
  18709. {
  18710. isSuccess = ConfigurationStatus_Rejected;
  18711. }
  18712. }
  18713. if(strcmp(key, "WebSocketPingInterval") == 0)
  18714. {
  18715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18716. {
  18717. check_ascii = value[0];
  18718. if( (check_ascii < 48) || (check_ascii > 57) )
  18719. {
  18720. isSuccess = ConfigurationStatus_Rejected;
  18721. }
  18722. else
  18723. {
  18724. if((atoi(value) == 0) || (atoi(value) >= 10))
  18725. {
  18726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18727. isSuccess = ConfigurationStatus_Accepted;
  18728. }
  18729. else
  18730. isSuccess = ConfigurationStatus_Rejected;
  18731. }
  18732. }
  18733. else
  18734. {
  18735. isSuccess = ConfigurationStatus_Rejected;
  18736. }
  18737. }
  18738. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18739. {
  18740. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18741. {
  18742. strcpy(str, (const char*)value);
  18743. for(int i = 0; str[i]; i++)
  18744. {
  18745. str[i] = tolower(str[i]);
  18746. }
  18747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18748. isSuccess = ConfigurationStatus_Accepted;
  18749. }
  18750. else
  18751. {
  18752. isSuccess = ConfigurationStatus_Rejected;
  18753. }
  18754. }
  18755. if(strcmp(key, "AuthorizationKey") == 0)
  18756. {
  18757. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18758. {
  18759. strcpy(str, (const char*)value);
  18760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  18761. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18762. isSuccess = ConfigurationStatus_Accepted;
  18763. }
  18764. else
  18765. {
  18766. isSuccess = ConfigurationStatus_Rejected;
  18767. }
  18768. }
  18769. if(strcmp(key, "SecurityProfile") == 0)
  18770. {
  18771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18772. {
  18773. check_ascii = value[0];
  18774. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18775. {
  18776. isSuccess = ConfigurationStatus_Rejected;
  18777. }
  18778. else if(check_ascii == 0x33)
  18779. {
  18780. isSuccess = NotSupported;
  18781. }
  18782. else
  18783. {
  18784. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18785. {
  18786. if(((check_ascii - 0x30) == 1) ||
  18787. ((check_ascii - 0x30) == 2) ||
  18788. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18789. {
  18790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18791. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18792. isSuccess = ConfigurationStatus_Accepted;
  18793. }
  18794. else
  18795. isSuccess = ConfigurationStatus_Rejected;
  18796. }
  18797. else
  18798. isSuccess = ConfigurationStatus_Rejected;
  18799. }
  18800. }
  18801. else
  18802. {
  18803. isSuccess = ConfigurationStatus_Rejected;
  18804. }
  18805. }
  18806. if(strcmp(key, "DefaultPrice") == 0)
  18807. {
  18808. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18809. {
  18810. strcpy(str, (const char*)value);
  18811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18812. isSuccess = ConfigurationStatus_Accepted;
  18813. }
  18814. else
  18815. {
  18816. isSuccess = ConfigurationStatus_Rejected;
  18817. }
  18818. }
  18819. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18820. {
  18821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18822. {
  18823. strcpy(str, (const char*)value);
  18824. for(int i = 0; str[i]; i++)
  18825. {
  18826. str[i] = tolower(str[i]);
  18827. }
  18828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18829. isSuccess = ConfigurationStatus_Accepted;
  18830. }
  18831. else
  18832. {
  18833. isSuccess = ConfigurationStatus_Rejected;
  18834. }
  18835. }
  18836. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18837. {
  18838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18839. {
  18840. strcpy(str, (const char*)value);
  18841. for(int i = 0; str[i]; i++)
  18842. {
  18843. str[i] = tolower(str[i]);
  18844. }
  18845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18846. isSuccess = ConfigurationStatus_Accepted;
  18847. }
  18848. else
  18849. {
  18850. isSuccess = ConfigurationStatus_Rejected;
  18851. }
  18852. }
  18853. if(strcmp(key, "TimeOffset") == 0)
  18854. {
  18855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18856. {
  18857. strcpy(str, (const char*)value);
  18858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18859. isSuccess = ConfigurationStatus_Accepted;
  18860. }
  18861. else
  18862. {
  18863. isSuccess = ConfigurationStatus_Rejected;
  18864. }
  18865. }
  18866. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18867. {
  18868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18869. {
  18870. strcpy(str, (const char*)value);
  18871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18872. isSuccess = ConfigurationStatus_Accepted;
  18873. }
  18874. else
  18875. {
  18876. isSuccess = ConfigurationStatus_Rejected;
  18877. }
  18878. }
  18879. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18880. {
  18881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18882. {
  18883. strcpy(str, (const char*)value);
  18884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18885. isSuccess = ConfigurationStatus_Accepted;
  18886. }
  18887. else
  18888. {
  18889. isSuccess = ConfigurationStatus_Rejected;
  18890. }
  18891. }
  18892. if(strcmp(key, "SystemUptimeSec") == 0)
  18893. {
  18894. isSuccess = NotSupported;
  18895. }
  18896. if(strcmp(key, "FreeVend") == 0)
  18897. {
  18898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18899. {
  18900. strcpy(str, (const char*)value);
  18901. for(int i = 0; str[i]; i++)
  18902. {
  18903. str[i] = tolower(str[i]);
  18904. }
  18905. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18907. isSuccess = ConfigurationStatus_Accepted;
  18908. }
  18909. else
  18910. {
  18911. isSuccess = ConfigurationStatus_Rejected;
  18912. }
  18913. }
  18914. if(strcmp(key, "FreeVendIdtag") == 0)
  18915. {
  18916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18917. {
  18918. strcpy(str, (const char*)value);
  18919. if(strlen(str) <= 20)
  18920. {
  18921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18922. isSuccess = ConfigurationStatus_Accepted;
  18923. }
  18924. else
  18925. {
  18926. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18927. isSuccess = ConfigurationStatus_Rejected;
  18928. }
  18929. }
  18930. else
  18931. {
  18932. isSuccess = ConfigurationStatus_Rejected;
  18933. }
  18934. }
  18935. if(strcmp(key, "OcppServer") == 0)
  18936. {
  18937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18938. {
  18939. strcpy(str, (const char*)value);
  18940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18941. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18942. isSuccess = ConfigurationStatus_Accepted;
  18943. }
  18944. else
  18945. {
  18946. isSuccess = ConfigurationStatus_Rejected;
  18947. }
  18948. }
  18949. if(strcmp(key, "MaintainServer") == 0)
  18950. {
  18951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18952. {
  18953. strcpy(str, (const char*)value);
  18954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18955. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18956. isSuccess = ConfigurationStatus_Accepted;
  18957. }
  18958. else
  18959. {
  18960. isSuccess = ConfigurationStatus_Rejected;
  18961. }
  18962. }
  18963. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18964. {
  18965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18966. {
  18967. strcpy(str, (const char*)value);
  18968. for(int i = 0; str[i]; i++)
  18969. {
  18970. str[i] = tolower(str[i]);
  18971. }
  18972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18973. isSuccess = ConfigurationStatus_Accepted;
  18974. }
  18975. else
  18976. {
  18977. isSuccess = ConfigurationStatus_Rejected;
  18978. }
  18979. }
  18980. if(strcmp(key, "StatusNotificationInterval") == 0)
  18981. {
  18982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18983. {
  18984. check_ascii = value[0];
  18985. if( (check_ascii < 48) || (check_ascii > 57) )
  18986. {
  18987. isSuccess = ConfigurationStatus_Rejected;
  18988. }
  18989. else
  18990. {
  18991. if((atoi(value) == 0) || (atoi(value) >= 10))
  18992. {
  18993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18994. isSuccess = ConfigurationStatus_Accepted;
  18995. }
  18996. else
  18997. isSuccess = ConfigurationStatus_Rejected;
  18998. }
  18999. }
  19000. else
  19001. {
  19002. isSuccess = ConfigurationStatus_Rejected;
  19003. }
  19004. }
  19005. if(strcmp(key, "PreAuthAmount") == 0)
  19006. {
  19007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  19008. {
  19009. check_ascii = value[0];
  19010. if( (check_ascii < 48) || (check_ascii > 57) )
  19011. {
  19012. isSuccess = ConfigurationStatus_Rejected;
  19013. }
  19014. else
  19015. {
  19016. if(atof(value) >= 0)
  19017. {
  19018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  19019. isSuccess = ConfigurationStatus_Accepted;
  19020. }
  19021. else
  19022. isSuccess = ConfigurationStatus_Rejected;
  19023. }
  19024. }
  19025. else
  19026. {
  19027. isSuccess = ConfigurationStatus_Rejected;
  19028. }
  19029. }
  19030. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  19031. {
  19032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  19033. {
  19034. check_ascii = value[0];
  19035. if( (check_ascii < 48) || (check_ascii > 57) )
  19036. {
  19037. isSuccess = ConfigurationStatus_Rejected;
  19038. }
  19039. else
  19040. {
  19041. if(atoi(value) >= 0)
  19042. {
  19043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  19044. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  19045. isSuccess = ConfigurationStatus_Accepted;
  19046. }
  19047. else
  19048. isSuccess = ConfigurationStatus_Rejected;
  19049. }
  19050. }
  19051. else
  19052. {
  19053. isSuccess = ConfigurationStatus_Rejected;
  19054. }
  19055. }
  19056. if(strcmp(key, "PowerSharingServerIP") == 0)
  19057. {
  19058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  19059. {
  19060. strcpy(str, (const char*)value);
  19061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  19062. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  19063. isSuccess = ConfigurationStatus_Accepted;
  19064. }
  19065. else
  19066. {
  19067. isSuccess = ConfigurationStatus_Rejected;
  19068. }
  19069. }
  19070. if(strcmp(key, "EVCCID_PREFIX") == 0)
  19071. {
  19072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  19073. {
  19074. strcpy(str, (const char*)value);
  19075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  19076. isSuccess = ConfigurationStatus_Accepted;
  19077. }
  19078. else
  19079. {
  19080. isSuccess = ConfigurationStatus_Rejected;
  19081. }
  19082. }
  19083. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  19084. {
  19085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  19086. {
  19087. if(atoi(value) > modelnameInfo.ratedPower)
  19088. {
  19089. isSuccess = ConfigurationStatus_Rejected;
  19090. }
  19091. else{
  19092. strcpy(str, (const char*)value);
  19093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  19094. isSuccess = ConfigurationStatus_Accepted;
  19095. }
  19096. }
  19097. else
  19098. {
  19099. isSuccess = ConfigurationStatus_Rejected;
  19100. }
  19101. }
  19102. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  19103. {
  19104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19105. {
  19106. if((atoi(value) != 0) && (atoi(value) < 5))
  19107. {
  19108. isSuccess = ConfigurationStatus_Rejected;
  19109. }
  19110. else{
  19111. strcpy(str, (const char*)value);
  19112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  19113. isSuccess = ConfigurationStatus_Accepted;
  19114. }
  19115. }
  19116. else
  19117. {
  19118. isSuccess = ConfigurationStatus_Rejected;
  19119. }
  19120. }
  19121. if(strcmp(key, "CpoName") == 0)
  19122. {
  19123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19124. {
  19125. strcpy(str, (const char*)value);
  19126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19127. isSuccess = ConfigurationStatus_Accepted;
  19128. }
  19129. else
  19130. {
  19131. isSuccess = ConfigurationStatus_Rejected;
  19132. }
  19133. }
  19134. #if 0
  19135. //For OCPP Test Case
  19136. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19137. {
  19138. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19139. {
  19140. strcpy(str, (const char*)value);
  19141. for(int i = 0; str[i]; i++)
  19142. {
  19143. str[i] = tolower(str[i]);
  19144. }
  19145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19146. isSuccess = ConfigurationStatus_Accepted;
  19147. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19148. }
  19149. else
  19150. {
  19151. isSuccess = ConfigurationStatus_Rejected;
  19152. }
  19153. }
  19154. #endif
  19155. #if 1
  19156. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19157. {
  19158. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19159. {
  19160. strcpy(str, (const char*)value);
  19161. for(int i = 0; str[i]; i++)
  19162. {
  19163. str[i] = tolower(str[i]);
  19164. }
  19165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19166. isSuccess = ConfigurationStatus_Accepted;
  19167. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19168. }
  19169. else
  19170. {
  19171. isSuccess = ConfigurationStatus_Rejected;
  19172. }
  19173. }
  19174. #endif
  19175. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19176. {
  19177. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19178. {
  19179. check_ascii = value[0];
  19180. if( (check_ascii < 48) || (check_ascii > 57) )
  19181. {
  19182. isSuccess = ConfigurationStatus_Rejected;
  19183. }
  19184. else
  19185. {
  19186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19187. isSuccess = ConfigurationStatus_Accepted;
  19188. }
  19189. }
  19190. else
  19191. {
  19192. isSuccess = ConfigurationStatus_Rejected;
  19193. }
  19194. }
  19195. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19196. {
  19197. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19198. {
  19199. check_ascii = value[0];
  19200. if( (check_ascii < 48) || (check_ascii > 57) )
  19201. {
  19202. isSuccess = ConfigurationStatus_Rejected;
  19203. }
  19204. else
  19205. {
  19206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19207. isSuccess = ConfigurationStatus_Accepted;
  19208. }
  19209. }
  19210. else
  19211. {
  19212. isSuccess = ConfigurationStatus_Rejected;
  19213. }
  19214. }
  19215. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19216. {
  19217. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19218. {
  19219. strcpy(str, (const char*)value);
  19220. for(int i = 0; str[i]; i++)
  19221. {
  19222. str[i] = tolower(str[i]);
  19223. }
  19224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19225. isSuccess = ConfigurationStatus_Accepted;
  19226. }
  19227. else
  19228. {
  19229. isSuccess = ConfigurationStatus_Rejected;
  19230. }
  19231. }
  19232. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19233. {
  19234. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19235. {
  19236. check_ascii = value[0];
  19237. if( (check_ascii < 48) || (check_ascii > 57) )
  19238. {
  19239. isSuccess = ConfigurationStatus_Rejected;
  19240. }
  19241. else
  19242. {
  19243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19244. isSuccess = ConfigurationStatus_Accepted;
  19245. }
  19246. }
  19247. else
  19248. {
  19249. isSuccess = ConfigurationStatus_Rejected;
  19250. }
  19251. }
  19252. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19253. {
  19254. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19255. {
  19256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19257. isSuccess = ConfigurationStatus_Accepted;
  19258. }
  19259. else
  19260. {
  19261. isSuccess = ConfigurationStatus_Rejected;
  19262. }
  19263. }
  19264. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19265. {
  19266. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19267. {
  19268. check_ascii = value[0];
  19269. if( (check_ascii < 48) || (check_ascii > 57) )
  19270. {
  19271. isSuccess = ConfigurationStatus_Rejected;
  19272. }
  19273. else
  19274. {
  19275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19276. isSuccess = ConfigurationStatus_Accepted;
  19277. }
  19278. }
  19279. else
  19280. {
  19281. isSuccess = ConfigurationStatus_Rejected;
  19282. }
  19283. }
  19284. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19285. {
  19286. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19287. {
  19288. strcpy(str, (const char*)value);
  19289. for(int i = 0; str[i]; i++)
  19290. {
  19291. str[i] = tolower(str[i]);
  19292. }
  19293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19294. isSuccess = ConfigurationStatus_Accepted;
  19295. }
  19296. else
  19297. {
  19298. isSuccess = ConfigurationStatus_Rejected;
  19299. }
  19300. }
  19301. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19302. {
  19303. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19304. {
  19305. check_ascii = value[0];
  19306. if( (check_ascii < 48) || (check_ascii > 57) )
  19307. {
  19308. isSuccess = ConfigurationStatus_Rejected;
  19309. }
  19310. else
  19311. {
  19312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19313. isSuccess = ConfigurationStatus_Accepted;
  19314. }
  19315. }
  19316. else
  19317. {
  19318. isSuccess = ConfigurationStatus_Rejected;
  19319. }
  19320. }
  19321. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19322. return isSuccess;
  19323. }
  19324. int TransactionMessageAttemptsGet(void)
  19325. {
  19326. return TransactionMessageAttemptsValue;
  19327. }
  19328. int FirstHeartBeatResponse(void)
  19329. {
  19330. return FirstHeartBeat;
  19331. }
  19332. int TransactionMessageRetryIntervalGet(void)
  19333. {
  19334. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19335. }
  19336. int ReadHttpStatus(int sock)
  19337. {
  19338. //char c;
  19339. char buff[1024]="",*ptr=buff+1;
  19340. int bytes_received, status;
  19341. DEBUG_INFO("Begin Response ..\n");
  19342. while((bytes_received = recv(sock, ptr, 1, 0))){
  19343. if(bytes_received==-1){
  19344. perror("ReadHttpStatus");
  19345. exit(1);
  19346. }
  19347. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19348. ptr++;
  19349. }
  19350. *ptr=0;
  19351. ptr=buff+1;
  19352. sscanf(ptr,"%*s %d ", &status);
  19353. DEBUG_INFO("%s\n",ptr);
  19354. DEBUG_INFO("status=%d\n",status);
  19355. DEBUG_INFO("End Response ..\n");
  19356. return (bytes_received>0)?status:0;
  19357. }
  19358. //the only filed that it parsed is 'Content-Length'
  19359. int ParseHeader(int sock)
  19360. {
  19361. //char c;
  19362. char buff[1024]="",*ptr=buff+4;
  19363. int bytes_received;
  19364. DEBUG_INFO("Begin HEADER ..\n");
  19365. while((bytes_received = recv(sock, ptr, 1, 0))){
  19366. if(bytes_received==-1){
  19367. perror("Parse Header");
  19368. exit(1);
  19369. }
  19370. if(
  19371. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19372. (ptr[-1]=='\r') && (*ptr=='\n' )
  19373. ) break;
  19374. ptr++;
  19375. }
  19376. *ptr=0;
  19377. ptr=buff+4;
  19378. //printf("%s",ptr);
  19379. if(bytes_received){
  19380. ptr=strstr(ptr,"Content-Length:");
  19381. if(ptr){
  19382. sscanf(ptr,"%*s %d",&bytes_received);
  19383. }else
  19384. bytes_received=-1; //unknown size
  19385. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19386. }
  19387. DEBUG_INFO("End HEADER ..\n");
  19388. return bytes_received ;
  19389. }
  19390. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19391. {
  19392. int result = TRUE;
  19393. char rmFileCmd[100]={0};
  19394. char FilePath[100]={0};
  19395. char ftpbuf[200];
  19396. int systemresult;
  19397. sprintf(FilePath,"/mnt/%s",filename);
  19398. system("ping 8.8.8.8 &");
  19399. if((access(FilePath,F_OK))!=-1)
  19400. {
  19401. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19402. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19403. system(rmFileCmd);
  19404. }
  19405. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19406. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19407. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19408. systemresult = system(ftpbuf);
  19409. if(systemresult != 0)
  19410. {
  19411. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19412. result = FALSE;
  19413. }
  19414. system("pkill ping");
  19415. return result;
  19416. }
  19417. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19418. {
  19419. int result = TRUE;
  19420. char rmFileCmd[100]={0};
  19421. char FilePath[100]={0};
  19422. char ftpbuf[200];
  19423. int systemresult;
  19424. sprintf(FilePath,"/mnt/%s",filename);
  19425. system("ping 8.8.8.8 &");
  19426. if((access(FilePath,F_OK))!=-1)
  19427. {
  19428. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19429. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19430. system(rmFileCmd);
  19431. }
  19432. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19433. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19434. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19435. systemresult = system(ftpbuf);
  19436. if(systemresult != 0)
  19437. {
  19438. DEBUG_WARN("scp error!\n");
  19439. result = FALSE;
  19440. }
  19441. system("pkill ping");
  19442. return result;
  19443. }
  19444. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19445. {
  19446. int result = TRUE;
  19447. char rmFileCmd[100]={0};
  19448. char FilePath[100]={0};
  19449. char ftpbuf[200];
  19450. int systemresult;
  19451. sprintf(FilePath,"/mnt/%s",filename);
  19452. system("ping 8.8.8.8 &");
  19453. if((access(FilePath,F_OK))!=-1)
  19454. {
  19455. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19456. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19457. system(rmFileCmd);
  19458. }
  19459. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19460. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  19461. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19462. systemresult = system(ftpbuf);
  19463. if(systemresult != 0)
  19464. {
  19465. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  19466. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19467. systemresult = system(ftpbuf);
  19468. if(systemresult != 0)
  19469. {
  19470. DEBUG_WARN("FTP download fail!\n");
  19471. result = FALSE;
  19472. }
  19473. }
  19474. system("pkill ping");
  19475. return result;
  19476. }
  19477. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19478. {
  19479. char rmFileCmd[100]={0};
  19480. char FilePath[100]={0};
  19481. char buf[512];
  19482. int systemresult = 0;
  19483. //DEBUG_INFO("filename=%s\n",filename);
  19484. //DEBUG_INFO("url=%s\n",url);
  19485. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19486. if((access(FilePath,F_OK))!=-1)
  19487. {
  19488. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19489. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19490. system(rmFileCmd);
  19491. }
  19492. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19493. if(fp == NULL)
  19494. {
  19495. DEBUG_INFO("log is NULL\n");
  19496. return FALSE;
  19497. }
  19498. else
  19499. {
  19500. fprintf(fp, "%s\n", url);
  19501. fprintf(fp, "%s\n", filename);
  19502. fclose(fp);
  19503. }
  19504. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19505. if(phpFP == NULL)
  19506. {
  19507. DEBUG_INFO("PHP upload fail.\n");
  19508. return FALSE;
  19509. }
  19510. else
  19511. {
  19512. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19513. {
  19514. if(strstr(buf, "result") != NULL)
  19515. {
  19516. sscanf(buf, "result: %d", &systemresult);
  19517. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19518. }
  19519. }
  19520. pclose(phpFP);
  19521. }
  19522. if(systemresult != 1)
  19523. {
  19524. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19525. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19526. if(phpFP == NULL)
  19527. {
  19528. DEBUG_WARN("PHP PUT upload fail.\n");
  19529. return FALSE;
  19530. }
  19531. else
  19532. {
  19533. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19534. {
  19535. if(strstr(buf, "result") != NULL)
  19536. {
  19537. sscanf(buf, "result: %d", &systemresult);
  19538. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19539. }
  19540. }
  19541. pclose(phpFP);
  19542. }
  19543. }
  19544. if(systemresult != 1)
  19545. {
  19546. DEBUG_WARN("PHP PUT upload fail.\n");
  19547. return FALSE;
  19548. }
  19549. return TRUE;
  19550. }
  19551. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19552. {
  19553. int result = FALSE;
  19554. char ftpbuf[200];
  19555. int systemresult;
  19556. /*
  19557. // Domaind name transfer to IP address
  19558. struct hostent* server;
  19559. char *IPbuffer;
  19560. server = gethostbyname(location);
  19561. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19562. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19563. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19564. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19565. systemresult = system(ftpbuf);
  19566. if(systemresult != 0)
  19567. {
  19568. DEBUG_INFO("ftpput error!\n");
  19569. }
  19570. else
  19571. {
  19572. result = TRUE;
  19573. DEBUG_INFO("ftpput OK!\n");
  19574. }
  19575. return result;
  19576. }
  19577. int GetOcppServerURL()
  19578. {
  19579. int result = FALSE;
  19580. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19581. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19582. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19583. struct yuarel url;
  19584. char urlStr[512];
  19585. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19586. {
  19587. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19588. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19589. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19590. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19591. if(yuarel_parse(&url, urlStr) != -1)
  19592. {
  19593. sprintf(OcppProtocol, "%s", url.scheme);
  19594. sprintf(OcppHost, "%s", url.host);
  19595. if(url.path == NULL)
  19596. OcppTempPath[0] = '\0';
  19597. else
  19598. {
  19599. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19600. {
  19601. sprintf(OcppTempPath, "%s/", url.path);
  19602. }
  19603. else
  19604. {
  19605. sprintf(OcppTempPath, "%s", url.path);
  19606. }
  19607. }
  19608. if(url.port == 0)
  19609. {
  19610. if(strcmp(OcppProtocol, "wss") == 0)
  19611. OcppPort = 443;
  19612. else
  19613. OcppPort = 80;
  19614. }
  19615. else
  19616. OcppPort = url.port;
  19617. result = TRUE;
  19618. }
  19619. }
  19620. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19621. {
  19622. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19623. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19624. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19625. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19626. if(yuarel_parse(&url, urlStr) != -1)
  19627. {
  19628. sprintf(OcppProtocol, "%s", url.scheme);
  19629. sprintf(OcppHost, "%s", url.host);
  19630. if(url.path == NULL)
  19631. OcppTempPath[0] = '\0';
  19632. else
  19633. sprintf(OcppTempPath, "%s", url.path);
  19634. if(url.port == 0)
  19635. {
  19636. if(strcmp(OcppProtocol, "wss") == 0)
  19637. OcppPort = 443;
  19638. else
  19639. OcppPort = 80;
  19640. }
  19641. else
  19642. OcppPort = url.port;
  19643. result = TRUE;
  19644. }
  19645. }
  19646. else
  19647. {
  19648. strcpy(OcppHost,"");
  19649. }
  19650. return result;
  19651. }
  19652. int GetOcppPath()
  19653. {
  19654. int result = FALSE;
  19655. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19656. {
  19657. if(OcppTempPath == NULL)
  19658. {
  19659. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19660. }
  19661. else
  19662. {
  19663. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19664. }
  19665. result = TRUE;
  19666. goto End;
  19667. }
  19668. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19669. {
  19670. if(OcppTempPath == NULL)
  19671. {
  19672. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19673. }
  19674. else
  19675. {
  19676. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19677. }
  19678. result = TRUE;
  19679. goto End;
  19680. }
  19681. else
  19682. {
  19683. strcpy(OcppPath,"");
  19684. }
  19685. End:
  19686. return result;
  19687. }
  19688. int GetOcppPort()
  19689. {
  19690. return OcppPort;
  19691. }
  19692. int GetOcppConnStatus(void)
  19693. {
  19694. return ShmOCPP16Data->OcppConnStatus;
  19695. }
  19696. void SetOcppConnStatus(uint8_t status)
  19697. {
  19698. ShmOCPP16Data->OcppConnStatus = status;
  19699. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19700. }
  19701. int GetHeartBeatWithNOResponse(void)
  19702. {
  19703. return HeartBeatWithNOResponse;
  19704. }
  19705. void SetHeartBeatWithNOResponse(void)
  19706. {
  19707. HeartBeatWithNOResponse = 0;
  19708. }
  19709. void GetStartTransactionIdTag(int gun_index)
  19710. {
  19711. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19712. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19713. }
  19714. int GetStartTransactionId(int gun_index)
  19715. {
  19716. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19717. }
  19718. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19719. {
  19720. char ch;
  19721. FILE *fptr1;
  19722. int temptransactionId;
  19723. char str[100]={0};
  19724. temptransactionId = 0;
  19725. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19726. {
  19727. DEBUG_INFO("IdTag is empty.\n");
  19728. return temptransactionId;
  19729. }
  19730. /*------ Read the file ----------------*/
  19731. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19732. if (!fptr1)
  19733. {
  19734. DEBUG_INFO("QueueTransactionId file open error.\n");
  19735. //printf(" File not found or unable to open the input file!!\n");
  19736. return temptransactionId;
  19737. }
  19738. ch=fgetc(fptr1);
  19739. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19740. rewind(fptr1);
  19741. if(ch!=EOF)
  19742. {
  19743. // printf("%c",ch);
  19744. while (fgets(str, 100, fptr1) != NULL)
  19745. {
  19746. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19747. if(str[0]=='\0')
  19748. {
  19749. break;
  19750. }
  19751. char *revbuf[8] = {0}; // Variable store string split
  19752. int num = 0;// Quantity after string split
  19753. DEBUG_INFO("Transaction queue data= %s\n", str);
  19754. splitstring(str,",",revbuf,&num); // String split
  19755. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19756. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19757. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19758. DEBUG_INFO("------------------------------\n");
  19759. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19760. {
  19761. if(isStopTransaction)
  19762. {
  19763. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19764. {
  19765. temptransactionId = atoi(revbuf[2]);
  19766. //break;
  19767. }
  19768. }
  19769. else
  19770. {
  19771. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19772. {
  19773. temptransactionId = atoi(revbuf[2]);
  19774. //break;
  19775. }
  19776. }
  19777. }
  19778. }
  19779. }
  19780. else
  19781. DEBUG_INFO("EOF\n");
  19782. fclose(fptr1);
  19783. /*------- End of reading ---------------*/
  19784. return temptransactionId;
  19785. }
  19786. void SetTransactionIdZero(int transactionId)
  19787. {
  19788. char ch;
  19789. FILE *fptr1, *fptr2;
  19790. int temptransactionId = 0;
  19791. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19792. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19793. if (!fptr1)
  19794. {
  19795. //printf(" File not found or unable to open the input file!!\n");
  19796. return ;
  19797. }
  19798. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19799. if (!fptr2)
  19800. {
  19801. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19802. fclose(fptr1);
  19803. return ;
  19804. }
  19805. ch=fgetc(fptr1);
  19806. rewind(fptr1);
  19807. if(ch!=EOF)
  19808. {
  19809. // copy all contents to the temporary file except the specific line
  19810. while (fgets(str, 100, fptr1) != NULL)
  19811. {
  19812. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19813. if(str[0]=='\0')
  19814. {
  19815. break;
  19816. }
  19817. char *revbuf[8] = {0};
  19818. int num = 0;
  19819. strcpy(strtemp, str);
  19820. splitstring(str,",",revbuf,&num);
  19821. if(revbuf[2][0] != '\0')
  19822. {
  19823. temptransactionId = atoi(revbuf[2]);
  19824. if(transactionId != temptransactionId)
  19825. {
  19826. fprintf(fptr2, "%s\n", strtemp);
  19827. }
  19828. }
  19829. }
  19830. }
  19831. fclose(fptr1);
  19832. fclose(fptr2);
  19833. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19834. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19835. /*------ Read the file ----------------*/
  19836. }
  19837. int InternetDisconnect(void)
  19838. {
  19839. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19840. }
  19841. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19842. void storeTempStopTransaction(int gun_index)
  19843. {
  19844. char guid[37]={0};
  19845. int tempIndex = 0;
  19846. char TempStopTransaction[256];
  19847. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19848. DEBUG_INFO("storeTempStopTransaction...\n");
  19849. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19850. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19851. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  19852. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19853. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19854. {
  19855. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19856. {
  19857. tempIndex = ((gun_index==2) ? 1: 0);
  19858. }
  19859. else
  19860. {
  19861. tempIndex = gun_index;
  19862. }
  19863. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19864. {
  19865. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19866. {
  19867. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19868. }
  19869. }// END OF CHAdeMO_QUANTITY
  19870. }
  19871. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19872. {
  19873. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19874. {
  19875. tempIndex = ((gun_index==2) ? 1: 0);
  19876. }
  19877. else
  19878. {
  19879. tempIndex = gun_index;
  19880. }
  19881. for (int index = 0; index < CCS_QUANTITY; index++)
  19882. {
  19883. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19884. {
  19885. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19886. }
  19887. }// END OF CCS_QUANTITY
  19888. }
  19889. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19890. {
  19891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19892. {
  19893. tempIndex = ((gun_index==2) ? 1: 0);
  19894. }
  19895. else
  19896. {
  19897. tempIndex = gun_index;
  19898. }
  19899. for (int index = 0; index < GB_QUANTITY; index++)
  19900. {
  19901. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19902. {
  19903. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19904. }
  19905. }// END OF GB_QUANTITY
  19906. }
  19907. else if(gunType[gun_index] == GUN_TYPE_DO)
  19908. {
  19909. tempIndex = gun_index;
  19910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19911. {
  19912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19913. {
  19914. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19915. }
  19916. }
  19917. }
  19918. else
  19919. {
  19920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19921. {
  19922. tempIndex = 2;
  19923. }
  19924. else
  19925. {
  19926. tempIndex = gun_index;
  19927. }
  19928. for (int index = 0; index < AC_QUANTITY; index++)
  19929. {
  19930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19931. {
  19932. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19933. }
  19934. }// END OF AC_QUANTITY
  19935. }
  19936. //Stop Transaction Time
  19937. struct timeval tmnow;
  19938. struct tm *tm;
  19939. char buf[28];//, usec_buf[6];
  19940. gettimeofday(&tmnow, NULL);
  19941. time_t t;
  19942. t = time(NULL);
  19943. /*UTC time and date*/
  19944. tm = gmtime(&t);
  19945. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  19946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  19947. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19949. random_uuid(guid);
  19950. /***********************************transactionData******************************************************/
  19951. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  19952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  19953. //=================================
  19954. //1. Transaction_Begin
  19955. //=================================
  19956. //============================== Energy.Active.Import.Interval ===========================================
  19957. //=================================
  19958. //2. Transaction_End
  19959. //=================================
  19960. //2.1====================================== Current.Import L1 ==============================================
  19961. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19962. {
  19963. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  19964. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19965. {
  19966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19967. {
  19968. tempIndex = ((gun_index==2) ? 1: 0);
  19969. }
  19970. else
  19971. {
  19972. tempIndex = gun_index;
  19973. }
  19974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19975. {
  19976. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19977. {
  19978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19979. }
  19980. }// End of for CHAdeMO_QUANTITY
  19981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19982. }
  19983. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19984. {
  19985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19986. {
  19987. tempIndex = ((gun_index==2) ? 1: 0);
  19988. }
  19989. else
  19990. {
  19991. tempIndex = gun_index;
  19992. }
  19993. for (int index = 0; index < CCS_QUANTITY; index++)
  19994. {
  19995. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19996. {
  19997. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19998. }
  19999. }// End of for CCS_QUANTITY
  20000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  20001. }
  20002. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20003. {
  20004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20005. {
  20006. tempIndex = ((gun_index==2) ? 1: 0);
  20007. }
  20008. else
  20009. {
  20010. tempIndex = gun_index;
  20011. }
  20012. for (int index = 0; index < GB_QUANTITY; index++)
  20013. {
  20014. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20015. {
  20016. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  20017. }
  20018. }// End of for GB_QUANTITY
  20019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  20020. }
  20021. else if(gunType[gun_index] == GUN_TYPE_DO)
  20022. {
  20023. tempIndex = gun_index;
  20024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20025. {
  20026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20027. {
  20028. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  20029. }
  20030. }
  20031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  20032. }
  20033. else
  20034. {
  20035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20036. {
  20037. tempIndex = 2;
  20038. }
  20039. else
  20040. {
  20041. tempIndex = gun_index;
  20042. }
  20043. for (int index = 0; index < AC_QUANTITY; index++)
  20044. {
  20045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20046. {
  20047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  20048. }
  20049. }// End of for AC_QUANTITY
  20050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  20051. }
  20052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  20054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  20055. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  20056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  20057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20058. }
  20059. //2.2===================================== Energy.Active.Import.Interval ==========================================
  20060. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  20061. {
  20062. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20063. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20064. {
  20065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20066. {
  20067. tempIndex = ((gun_index==2) ? 1: 0);
  20068. }
  20069. else
  20070. {
  20071. tempIndex = gun_index;
  20072. }
  20073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20074. {
  20075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20076. {
  20077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  20078. }
  20079. }// END OF CHAdeMO_QUANTITY
  20080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20081. }
  20082. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20083. {
  20084. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20085. {
  20086. tempIndex = ((gun_index==2) ? 1: 0);
  20087. }
  20088. else
  20089. {
  20090. tempIndex = gun_index;
  20091. }
  20092. for (int index = 0; index < CCS_QUANTITY; index++)
  20093. {
  20094. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20095. {
  20096. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  20097. }
  20098. }// END OF CCS_QUANTITY
  20099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20100. }
  20101. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20102. {
  20103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20104. {
  20105. tempIndex = ((gun_index==2) ? 1: 0);
  20106. }
  20107. else
  20108. {
  20109. tempIndex = gun_index;
  20110. }
  20111. for (int index = 0; index < GB_QUANTITY; index++)
  20112. {
  20113. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20114. {
  20115. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  20116. }
  20117. }// END OF GB_QUANTITY
  20118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20119. }
  20120. else if(gunType[gun_index] == GUN_TYPE_DO)
  20121. {
  20122. tempIndex = gun_index;
  20123. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20124. {
  20125. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20126. {
  20127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  20128. }
  20129. }
  20130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20131. }
  20132. else
  20133. {
  20134. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20135. {
  20136. tempIndex = 2;
  20137. }
  20138. else
  20139. {
  20140. tempIndex = gun_index;
  20141. }
  20142. for (int index = 0; index < AC_QUANTITY; index++)
  20143. {
  20144. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20145. {
  20146. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  20147. }
  20148. }// END OF AC_QUANTITY
  20149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  20150. }
  20151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  20153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  20154. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  20155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  20156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  20157. }
  20158. //2.3====================================== Power.Active.Import =========================================
  20159. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  20160. {
  20161. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20162. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20163. {
  20164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20165. {
  20166. tempIndex = ((gun_index==2) ? 1: 0);
  20167. }
  20168. else
  20169. {
  20170. tempIndex = gun_index;
  20171. }
  20172. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20173. {
  20174. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20175. {
  20176. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20177. }
  20178. } // End for CHAdeMO_QUANTITY
  20179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20180. }
  20181. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20182. {
  20183. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20184. {
  20185. tempIndex = ((gun_index==2) ? 1: 0);
  20186. }
  20187. else
  20188. {
  20189. tempIndex = gun_index;
  20190. }
  20191. for (int index = 0; index < CCS_QUANTITY; index++)
  20192. {
  20193. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20194. {
  20195. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20196. }
  20197. } // END for CCS_QUANTITY
  20198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20199. }
  20200. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20201. {
  20202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20203. {
  20204. tempIndex = ((gun_index==2) ? 1: 0);
  20205. }
  20206. else
  20207. {
  20208. tempIndex = gun_index;
  20209. }
  20210. for (int index = 0; index < GB_QUANTITY; index++)
  20211. {
  20212. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20213. {
  20214. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20215. }
  20216. }// END for GB_QUANTITY
  20217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20218. }
  20219. else if(gunType[gun_index] == GUN_TYPE_DO)
  20220. {
  20221. tempIndex = gun_index;
  20222. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20223. {
  20224. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20225. {
  20226. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20227. }
  20228. }
  20229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20230. }
  20231. else
  20232. {
  20233. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20234. {
  20235. tempIndex = 2;
  20236. }
  20237. else
  20238. {
  20239. tempIndex = gun_index;
  20240. }
  20241. for (int index = 0; index < AC_QUANTITY; index++)
  20242. {
  20243. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20244. {
  20245. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20246. }
  20247. } // END for AC_QUANTITY
  20248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  20249. }
  20250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  20252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  20253. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  20254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  20255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  20256. }
  20257. //2.4====================================== Voltage L1 ====================================================
  20258. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20259. {
  20260. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20261. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20262. {
  20263. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20264. {
  20265. tempIndex = ((gun_index==2) ? 1: 0);
  20266. }
  20267. else
  20268. {
  20269. tempIndex = gun_index;
  20270. }
  20271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20272. {
  20273. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20274. {
  20275. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20276. }
  20277. } // END OF FOR CHAdeMO_QUANTITY
  20278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20279. }
  20280. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20281. {
  20282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20283. {
  20284. tempIndex = ((gun_index==2) ? 1: 0);
  20285. }
  20286. else
  20287. {
  20288. tempIndex = gun_index;
  20289. }
  20290. for (int index = 0; index < CCS_QUANTITY; index++)
  20291. {
  20292. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20293. {
  20294. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20295. }
  20296. } // END OF FOR CCS_QUANTITY
  20297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20298. }
  20299. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20300. {
  20301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20302. {
  20303. tempIndex = ((gun_index==2) ? 1: 0);
  20304. }
  20305. else
  20306. {
  20307. tempIndex = gun_index;
  20308. }
  20309. for (int index = 0; index < GB_QUANTITY; index++)
  20310. {
  20311. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20312. {
  20313. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20314. }
  20315. } // END OF FOR GB_QUANTITY
  20316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20317. }
  20318. else if(gunType[gun_index] == GUN_TYPE_DO)
  20319. {
  20320. tempIndex = gun_index;
  20321. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20322. {
  20323. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20324. {
  20325. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20326. }
  20327. }
  20328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20329. }
  20330. else
  20331. {
  20332. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20333. {
  20334. tempIndex = 2;
  20335. }
  20336. else
  20337. {
  20338. tempIndex = gun_index;
  20339. }
  20340. for (int index = 0; index < AC_QUANTITY; index++)
  20341. {
  20342. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20343. {
  20344. 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
  20345. }
  20346. } // END OF FOR AC_QUANTITY
  20347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  20348. }
  20349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20350. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  20351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  20352. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  20353. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  20354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20355. }
  20356. //2.5============================================== End SoC =========================================================
  20357. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  20358. {
  20359. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20360. 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))
  20361. {
  20362. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  20363. {
  20364. tempIndex = ((gun_index==2) ? 1: 0);
  20365. }
  20366. else
  20367. {
  20368. tempIndex = gun_index;
  20369. }
  20370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20371. {
  20372. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20373. {
  20374. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20375. {
  20376. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  20377. }
  20378. }
  20379. }
  20380. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20381. {
  20382. for (int index = 0; index < CCS_QUANTITY; index++)
  20383. {
  20384. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20385. {
  20386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  20387. }
  20388. }
  20389. }
  20390. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20391. {
  20392. for (int index = 0; index < GB_QUANTITY; index++)
  20393. {
  20394. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20395. {
  20396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  20397. }
  20398. }
  20399. }
  20400. else if(gunType[gun_index] == GUN_TYPE_DO)
  20401. {
  20402. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20403. {
  20404. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20405. {
  20406. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  20407. }
  20408. }
  20409. }
  20410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  20412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  20413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  20414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  20415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  20416. } // END FOR DC CASE
  20417. }
  20418. //2.6====================================== Current.Import L2 ==============================================
  20419. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20420. {
  20421. // AC 3 phase L2 current
  20422. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20423. {
  20424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20425. {
  20426. tempIndex = 2;
  20427. }
  20428. else
  20429. {
  20430. tempIndex = gun_index;
  20431. }
  20432. for (int index = 0; index < AC_QUANTITY; index++)
  20433. {
  20434. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20435. {
  20436. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  20437. }
  20438. }// End of for AC_QUANTITY
  20439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  20440. }
  20441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  20443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  20444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  20445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20446. }
  20447. //2.7====================================== Current.Import L3 ==============================================
  20448. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20449. {
  20450. // AC 3 phase L3 current
  20451. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20452. {
  20453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20454. {
  20455. tempIndex = 2;
  20456. }
  20457. else
  20458. {
  20459. tempIndex = gun_index;
  20460. }
  20461. for (int index = 0; index < AC_QUANTITY; index++)
  20462. {
  20463. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20464. {
  20465. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  20466. }
  20467. }// End of for AC_QUANTITY
  20468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  20469. }
  20470. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  20472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  20473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  20474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20475. }
  20476. //2.9====================================== Voltage L2 ====================================================
  20477. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20478. {
  20479. // AC 3 phase L2 volatge
  20480. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20481. {
  20482. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20483. {
  20484. tempIndex = 2;
  20485. }
  20486. else
  20487. {
  20488. tempIndex = gun_index;
  20489. }
  20490. for (int index = 0; index < AC_QUANTITY; index++)
  20491. {
  20492. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20493. {
  20494. 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
  20495. }
  20496. } // END OF FOR AC_QUANTITY
  20497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  20498. }
  20499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  20501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  20502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  20503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20504. }
  20505. //2.10====================================== Voltage L3 ====================================================
  20506. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20507. {
  20508. // AC 3 phase L3 volatge
  20509. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20510. {
  20511. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20512. {
  20513. tempIndex = 2;
  20514. }
  20515. else
  20516. {
  20517. tempIndex = gun_index;
  20518. }
  20519. for (int index = 0; index < AC_QUANTITY; index++)
  20520. {
  20521. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20522. {
  20523. 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
  20524. }
  20525. } // END OF FOR AC_QUANTITY
  20526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  20527. }
  20528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  20530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  20531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  20532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20533. }
  20534. //====================== Start SoC ================================
  20535. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  20536. {
  20537. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20538. 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))
  20539. {
  20540. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  20541. {
  20542. tempIndex = ((gun_index==2) ? 1: 0);
  20543. }
  20544. else
  20545. {
  20546. tempIndex = gun_index;
  20547. }
  20548. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20549. {
  20550. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20551. {
  20552. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20553. {
  20554. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  20555. }
  20556. }
  20557. }
  20558. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20559. {
  20560. for (int index = 0; index < CCS_QUANTITY; index++)
  20561. {
  20562. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20563. {
  20564. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  20565. }
  20566. }
  20567. }
  20568. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20569. {
  20570. for (int index = 0; index < GB_QUANTITY; index++)
  20571. {
  20572. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20573. {
  20574. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  20575. }
  20576. }
  20577. }
  20578. else if(gunType[gun_index] == GUN_TYPE_DO)
  20579. {
  20580. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20581. {
  20582. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20583. {
  20584. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  20585. }
  20586. }
  20587. }
  20588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  20589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  20590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  20591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  20592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  20593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  20594. } // END FOR DC CASE
  20595. }
  20596. //======================================== Message create ==============================================
  20597. json_object *StopTransaction = json_object_new_object();
  20598. json_object *transactionDatas = json_object_new_array();
  20599. json_object *sampledValues = json_object_new_array();
  20600. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  20601. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  20602. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  20603. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  20604. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  20605. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  20606. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  20607. {
  20608. json_object *transactionData = json_object_new_object();
  20609. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  20610. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  20611. {
  20612. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  20613. {
  20614. json_object *sampledValue = json_object_new_object();
  20615. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  20616. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  20617. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  20618. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  20619. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  20620. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  20621. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  20622. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  20623. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  20624. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  20625. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  20626. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  20627. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  20628. json_object_array_add(sampledValues, sampledValue);
  20629. }
  20630. }
  20631. json_object_object_add(transactionData, "sampledValue", sampledValues);
  20632. json_object_array_add(transactionDatas, transactionData);
  20633. }
  20634. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  20635. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  20636. ,MESSAGE_TYPE_CALL
  20637. ,guid
  20638. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  20639. json_object_put(StopTransaction);
  20640. // Check File "TempStopTransaction" Exist
  20641. if((access(TempStopTransaction,F_OK))!=-1)
  20642. {
  20643. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  20644. fclose(fopen(TempStopTransaction, "w"));
  20645. }
  20646. else
  20647. {
  20648. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  20649. FILE *log = fopen(TempStopTransaction, "w+");
  20650. if(log == NULL)
  20651. {
  20652. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  20653. return ;
  20654. }
  20655. else
  20656. {
  20657. fclose(log);
  20658. }
  20659. }
  20660. //Add TempStopTransaction | Update TempStopTransaction
  20661. // open file for writing
  20662. FILE *outfile;
  20663. outfile = fopen (TempStopTransaction, "a");
  20664. //DEBUG_INFO("data = %s\n", queuedata);
  20665. fputs(queuedata, outfile);
  20666. fputs("\n", outfile);
  20667. fclose (outfile);
  20668. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20669. OCPP_updatePeriodEnergy(gun_index);
  20670. }
  20671. void checkTempStopTransaction(int gun_index)
  20672. {
  20673. FILE *fptr1;
  20674. char ch;
  20675. char str[QUEUE_MESSAGE_LENGTH]={0};
  20676. char guid[37]={0};
  20677. char tempdata[65]={0};
  20678. char connectorStr[2]={0};
  20679. char TempStopTransaction[256];
  20680. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20681. fptr1 = fopen(TempStopTransaction, "r");
  20682. //TempStopTransaction格式: 槍號,StopTransaction封包
  20683. if (!fptr1)
  20684. {
  20685. //printf(" File not found or unable to open the input file!!\n");
  20686. return ;
  20687. }
  20688. ch=fgetc(fptr1);
  20689. //printf(" Now the content of the file %s is : \n",fname);
  20690. rewind(fptr1);
  20691. if(ch!=EOF)
  20692. {
  20693. // copy all contents to the temporary file except the specific line
  20694. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  20695. {
  20696. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20697. if(str[0]=='\0')
  20698. {
  20699. break;
  20700. }
  20701. //TempStopTransaction格式: 槍號,StopTransaction封包
  20702. strncpy(connectorStr, str, 1);
  20703. if(atoi(connectorStr) != (gun_index+1))
  20704. {
  20705. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  20706. fclose(fptr1);
  20707. return ;
  20708. }
  20709. //random_uuid(guid);
  20710. strncpy(guid, str+6, 36); //copy guid
  20711. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  20712. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  20713. {
  20714. //DEBUG_INFO("StopTransaction mapitem pass\n");
  20715. }
  20716. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  20717. OCPP_insert_transaction_msg(NO, str);
  20718. memset(str,0,ARRAY_SIZE(str));
  20719. }
  20720. }
  20721. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  20722. fclose(fptr1);
  20723. remove(TempStopTransaction); // remove the original file
  20724. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20725. }
  20726. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  20727. {
  20728. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20729. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  20730. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  20731. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  20732. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  20733. }
  20734. void FillTransactionId(int ConnectorId, int TransactionId)
  20735. {
  20736. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20737. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  20738. }
  20739. int GetWebSocketPingInterval(void)
  20740. {
  20741. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  20742. }
  20743. int GetServerSign(void)
  20744. {
  20745. return server_sign;
  20746. }
  20747. uint8_t GetOcppSecurityProfile()
  20748. {
  20749. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  20750. }
  20751. void MergeCertificates()
  20752. {
  20753. char cmdBuf[2048]={0};
  20754. if(access(ROOTCA_CS,F_OK) != -1)
  20755. {
  20756. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  20757. }
  20758. else
  20759. {
  20760. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  20761. }
  20762. system(cmdBuf);
  20763. }
  20764. void GetOcppChargerBoxId(uint8_t *data)
  20765. {
  20766. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20767. }
  20768. void GetOcppSecurityPassword(uint8_t *data)
  20769. {
  20770. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20771. }
  20772. void SetOcppVersion(uint8_t *version)
  20773. {
  20774. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20775. DEBUG_INFO("ocpp version: %s\n", version);
  20776. if(strstr((char*)version, "ocpp1.6") != NULL)
  20777. {
  20778. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20779. }
  20780. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20781. {
  20782. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20783. system("pkill OcppBackend");
  20784. }
  20785. }
  20786. void SetServerSign(int value)
  20787. {
  20788. server_sign = value;
  20789. }
  20790. int GetBootNotificationInterval(void)
  20791. {
  20792. return BootNotificationInterval;
  20793. }
  20794. int GetInternetConn(void)
  20795. {
  20796. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20797. }
  20798. int GetBackendConnectionTimeout(void)
  20799. {
  20800. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20801. }
  20802. int isConnectorInitMode(int gun_index)
  20803. {
  20804. int tempIndex = 0;
  20805. int result = TRUE;
  20806. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20807. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20808. {
  20809. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20810. {
  20811. tempIndex = ((gun_index==2) ? 1: 0);
  20812. }
  20813. else
  20814. {
  20815. tempIndex = gun_index;
  20816. }
  20817. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20818. {
  20819. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20820. {
  20821. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20822. } //end of the same index
  20823. }//end of for CHAdeMO_QUANTITY
  20824. }
  20825. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20826. {
  20827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20828. {
  20829. tempIndex = ((gun_index==2) ? 1: 0);
  20830. }
  20831. else
  20832. {
  20833. tempIndex = gun_index;
  20834. }
  20835. for (int index = 0; index < CCS_QUANTITY; index++)
  20836. {
  20837. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20838. {
  20839. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20840. } //end of the same index
  20841. } // end of for CCS_QUANTITY
  20842. }
  20843. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20844. {
  20845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20846. {
  20847. tempIndex = ((gun_index==2) ? 1: 0);
  20848. }
  20849. else
  20850. {
  20851. tempIndex = gun_index;
  20852. }
  20853. for (int index = 0; index < GB_QUANTITY; index++)
  20854. {
  20855. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20856. {
  20857. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20858. } //end of the same index
  20859. } // end of for GB_QUANTITY
  20860. }
  20861. else if(gunType[gun_index] == GUN_TYPE_DO)
  20862. {
  20863. tempIndex = gun_index;
  20864. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20865. {
  20866. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20867. {
  20868. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20869. } //end of the same index
  20870. }
  20871. }
  20872. else
  20873. {
  20874. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20875. {
  20876. tempIndex = 2;
  20877. }
  20878. else
  20879. {
  20880. tempIndex = gun_index;
  20881. }
  20882. for (int index = 0; index < AC_QUANTITY; index++)
  20883. {
  20884. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20885. {
  20886. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20887. }//end of the same index
  20888. }//end of for AC_QUANTITY
  20889. }
  20890. return result;
  20891. }
  20892. void refreshProcDogTimer()
  20893. {
  20894. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20895. }
  20896. void InitialSystemValue(void)
  20897. {
  20898. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20899. locallistVersion=0;
  20900. BootNotificationInterval = 0;
  20901. authorizeRetryTimes = 0;
  20902. GunStatusInterval = 10;
  20903. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20904. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20905. //Hear Beat
  20906. HeartBeatWithNOResponse = 0;
  20907. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20908. FirstHeartBeat = 0;
  20909. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20910. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20911. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20912. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20913. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20914. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20915. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20916. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20917. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20918. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20919. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20920. //Status && ConnectorPlugIn Setting
  20921. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20922. {
  20923. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20924. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20925. }
  20926. for (int index = 0; index < CCS_QUANTITY; index++)
  20927. {
  20928. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20929. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20930. }
  20931. for (int index = 0; index < GB_QUANTITY; index++)
  20932. {
  20933. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20934. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20935. }
  20936. for (int index = 0; index < AC_QUANTITY; index++)
  20937. {
  20938. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20939. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20940. }
  20941. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20942. {
  20943. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20944. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20945. }
  20946. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20947. {
  20948. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20949. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20950. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20951. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20952. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20953. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20954. }
  20955. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20956. refreshStartTimer(&clientTime.Heartbeat);
  20957. sleep(1);
  20958. }
  20959. void LWS_Send(char *str)
  20960. {
  20961. //=====================================================
  20962. // Check InternetConn 0: disconnected, 1: connected
  20963. //====================================================
  20964. if(GetOcppConnStatus() == 0)
  20965. {
  20966. DEBUG_INFO("offline now !!!\n");
  20967. return;
  20968. }
  20969. // Only disable isWebsocketSendable operation initiated by charger
  20970. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20971. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20972. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20973. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20974. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20975. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20976. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20977. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20978. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20979. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20980. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20981. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20982. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20983. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20984. {
  20985. isWebsocketSendable = 0;
  20986. }
  20987. pthread_mutex_lock(&lock_send);
  20988. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20989. sprintf((char *)SendBuffer, "%s", str);
  20990. SendBufLen = strlen(str);
  20991. pthread_mutex_unlock(&lock_send);
  20992. lws_callback_on_writable(wsi_client);
  20993. //lws_service(context, 0);
  20994. //sleep(1);
  20995. }
  20996. void LWS_SendNow(char *str)
  20997. {
  20998. //=====================================================
  20999. // Check InternetConn 0: disconnected, 1: connected
  21000. //====================================================
  21001. if(GetOcppConnStatus() == 0)
  21002. {
  21003. DEBUG_INFO("offline now !!!\n");
  21004. return;
  21005. }
  21006. // Only disable isWebsocketSendable operation initiated by charger
  21007. if((strstr((char*)str, "\"Authorize\"") != NULL)
  21008. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  21009. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  21010. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  21011. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  21012. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  21013. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  21014. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  21015. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  21016. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  21017. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  21018. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  21019. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  21020. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  21021. {
  21022. isWebsocketSendable = 0;
  21023. }
  21024. pthread_mutex_lock(&lock_send);
  21025. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  21026. sprintf((char *)SendBuffer, "%s", str);
  21027. SendBufLen = strlen(str);
  21028. pthread_mutex_unlock(&lock_send);
  21029. lws_callback_on_writable(wsi_client);
  21030. lws_service(context, 0);
  21031. //sleep(1);
  21032. }