MessageHandler.c 1.0 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976
  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 = FALSE;
  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[gun_index].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. // Parse certificate content
  1366. //==========================================
  1367. int parseCertInfo(char *certPath, int parseType, char *data)
  1368. {
  1369. int result = FAIL;
  1370. memset(data, 0, ARRAY_SIZE(data));
  1371. if(access(certPath,F_OK) != -1)
  1372. {
  1373. char temp[512] = {0};
  1374. char capturedData[256] = {0};
  1375. char hashType[10] = "SHA256";
  1376. FILE *fp;
  1377. // Need to get hash type first
  1378. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1379. fp = popen(temp, "r");
  1380. if(fp)
  1381. {
  1382. while(fgets(temp, sizeof(temp), fp) != NULL)
  1383. {
  1384. if(strstr(temp, "Signature Algorithm:") != NULL)
  1385. {
  1386. result = PASS;
  1387. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1388. sprintf((char*)hashType, "SHA256");
  1389. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1390. sprintf((char*)hashType, "SHA384");
  1391. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1392. sprintf((char*)hashType, "SHA512");
  1393. else
  1394. {
  1395. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1396. result = FAIL;
  1397. }
  1398. break;
  1399. }
  1400. }
  1401. }
  1402. switch(parseType)
  1403. {
  1404. case CERT_PARSE_HashAlgorithm:
  1405. sprintf((char*)data, hashType);
  1406. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1407. break;
  1408. case CERT_PARSE_SerialNumber:
  1409. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1410. fp = popen(temp, "r");
  1411. if(fp)
  1412. {
  1413. while(fgets(temp, sizeof(temp), fp) != NULL)
  1414. {
  1415. if(strstr(temp, "serial=") != NULL)
  1416. {
  1417. sscanf(temp, "%*[^=]=%s", capturedData);
  1418. result = PASS;
  1419. break;
  1420. }
  1421. }
  1422. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1423. sprintf((char*)data, capturedData);
  1424. }
  1425. break;
  1426. case CERT_PARSE_IssuerNameHash:
  1427. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", certPath, (char*)hashType);
  1428. fp = popen(temp, "r");
  1429. if(fp)
  1430. {
  1431. while(fgets(temp, sizeof(temp), fp) != NULL)
  1432. {
  1433. if(strstr(temp, "(stdin)=") != NULL)
  1434. {
  1435. sscanf(temp, "%*[^=]=%s", capturedData);
  1436. result = PASS;
  1437. break;
  1438. }
  1439. }
  1440. stringtrimspace(capturedData);
  1441. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1442. sprintf((char*)data, capturedData);
  1443. }
  1444. break;
  1445. case CERT_PARSE_IssuerKeyHash:
  1446. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", certPath, (char*)hashType);
  1447. fp = popen(temp, "r");
  1448. if(fp)
  1449. {
  1450. while(fgets(temp, sizeof(temp), fp) != NULL)
  1451. {
  1452. if(strstr(temp, "(stdin)=") != NULL)
  1453. {
  1454. sscanf(temp, "%*[^=]=%s", capturedData);
  1455. result = PASS;
  1456. break;
  1457. }
  1458. }
  1459. stringtrimspace(capturedData);
  1460. DEBUG_INFO("issuerKeyHash: %s\n", capturedData);
  1461. sprintf((char*)data, capturedData);
  1462. }
  1463. break;
  1464. case CERT_PARSE_OcspUrl:
  1465. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1466. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1467. fp = popen(temp, "r");
  1468. if(fp)
  1469. {
  1470. while(fgets(temp, sizeof(temp), fp) != NULL)
  1471. {
  1472. if(strstr(temp, "OCSP - URI:") != NULL)
  1473. {
  1474. //strcpy((char*)data, temp);
  1475. sscanf(temp, "%*[^:]:%s", capturedData);
  1476. sprintf((char*)data, capturedData);
  1477. DEBUG_INFO("OCSP_URI: %s\n", data);
  1478. result = PASS;
  1479. break;
  1480. }
  1481. }
  1482. }
  1483. break;
  1484. default:
  1485. DEBUG_INFO("Parse type is invalid.\n");
  1486. break;
  1487. }
  1488. pclose(fp);
  1489. }
  1490. return result;
  1491. }
  1492. //==========================================
  1493. // GetCompositeSchedule logic related function
  1494. //==========================================
  1495. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1496. {
  1497. //return milli-second
  1498. unsigned int StartTime,StopTime;
  1499. StartTime=(unsigned int)ST.time;
  1500. StopTime=(unsigned int)ET.time;
  1501. return (StopTime-StartTime);
  1502. }
  1503. int DiffTimebWithNowSec(struct timeb ST)
  1504. {
  1505. //return milli-second
  1506. struct timeb ET;
  1507. unsigned int StartTime,StopTime;
  1508. ftime(&ET);
  1509. StartTime=(unsigned int)ST.time;
  1510. StopTime=(unsigned int)ET.time;
  1511. return (StopTime-StartTime);
  1512. }
  1513. int getStartStop(uint8_t *start, uint8_t *stop)
  1514. {
  1515. struct ParsingResult
  1516. {
  1517. int result;
  1518. int scanedElement;
  1519. int year;
  1520. int month;
  1521. int mday;
  1522. int hour;
  1523. int min;
  1524. int sec;
  1525. int tz_hour;
  1526. int tz_min;
  1527. float minSec;
  1528. };
  1529. struct ParsingResult parseStart;
  1530. struct ParsingResult parseStop;
  1531. int result = -1;
  1532. struct tm tmStart;
  1533. struct timeb tbStart;
  1534. struct tm tmStop;
  1535. struct timeb tbStop;
  1536. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1537. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1538. // Scan start & stop date time
  1539. if(strstr((char*)start, ".") != NULL)
  1540. {
  1541. // Original data with mini second
  1542. if(strstr((char*)start, "Z") != NULL)
  1543. {
  1544. // Original data with Z
  1545. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1546. &parseStart.year,
  1547. &parseStart.month,
  1548. &parseStart.mday,
  1549. &parseStart.hour,
  1550. &parseStart.min,
  1551. &parseStart.sec,
  1552. &parseStart.minSec);
  1553. }
  1554. else
  1555. {
  1556. // Original data without Z
  1557. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1558. &parseStart.year,
  1559. &parseStart.month,
  1560. &parseStart.mday,
  1561. &parseStart.hour,
  1562. &parseStart.min,
  1563. &parseStart.sec,
  1564. &parseStart.minSec,
  1565. &parseStart.tz_hour,
  1566. &parseStart.tz_min);
  1567. }
  1568. }
  1569. else
  1570. {
  1571. // Original data without mini second
  1572. if(strstr((char*)start, "Z") != NULL)
  1573. {
  1574. // Original data with Z
  1575. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1576. &parseStart.year,
  1577. &parseStart.month,
  1578. &parseStart.mday,
  1579. &parseStart.hour,
  1580. &parseStart.min,
  1581. &parseStart.sec);
  1582. }
  1583. else
  1584. {
  1585. // Original data without Z
  1586. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1587. &parseStart.year,
  1588. &parseStart.month,
  1589. &parseStart.mday,
  1590. &parseStart.hour,
  1591. &parseStart.min,
  1592. &parseStart.sec,
  1593. &parseStart.tz_hour,
  1594. &parseStart.tz_min);
  1595. }
  1596. }
  1597. if(strstr((char*)stop, ".") != NULL)
  1598. {
  1599. // Original data with mini second
  1600. if(strstr((char*)stop, "Z") != NULL)
  1601. {
  1602. // Original data with Z
  1603. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1604. &parseStop.year,
  1605. &parseStop.month,
  1606. &parseStop.mday,
  1607. &parseStop.hour,
  1608. &parseStop.min,
  1609. &parseStop.sec,
  1610. &parseStop.minSec);
  1611. }
  1612. else
  1613. {
  1614. // Original data without Z
  1615. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1616. &parseStop.year,
  1617. &parseStop.month,
  1618. &parseStop.mday,
  1619. &parseStop.hour,
  1620. &parseStop.min,
  1621. &parseStop.sec,
  1622. &parseStop.minSec,
  1623. &parseStop.tz_hour,
  1624. &parseStop.tz_min);
  1625. }
  1626. }
  1627. else
  1628. {
  1629. // Original data without mini second
  1630. if(strstr((char*)stop, "Z") != NULL)
  1631. {
  1632. // Original data with Z
  1633. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1634. &parseStop.year,
  1635. &parseStop.month,
  1636. &parseStop.mday,
  1637. &parseStop.hour,
  1638. &parseStop.min,
  1639. &parseStop.sec);
  1640. }
  1641. else
  1642. {
  1643. // Original data without Z
  1644. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1645. &parseStop.year,
  1646. &parseStop.month,
  1647. &parseStop.mday,
  1648. &parseStop.hour,
  1649. &parseStop.min,
  1650. &parseStop.sec,
  1651. &parseStop.tz_hour,
  1652. &parseStop.tz_min);
  1653. }
  1654. }
  1655. // Calculate date time difference
  1656. if((parseStart.scanedElement >=6) &&
  1657. (parseStop.scanedElement >=6))
  1658. {
  1659. //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);
  1660. //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);
  1661. tmStart.tm_year = parseStart.year - 1900;
  1662. tmStart.tm_mon = parseStart.month - 1;
  1663. tmStart.tm_mday = parseStart.mday;
  1664. tmStart.tm_hour = parseStart.hour;
  1665. tmStart.tm_min = parseStart.min;
  1666. tmStart.tm_sec = parseStart.sec;
  1667. tmStart.tm_gmtoff = 0;
  1668. tbStart.time = mktime(&tmStart);
  1669. tbStart.timezone = 0;
  1670. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1671. tmStop.tm_year = parseStop.year - 1900;
  1672. tmStop.tm_mon = parseStop.month - 1;
  1673. tmStop.tm_mday = parseStop.mday;
  1674. tmStop.tm_hour = parseStop.hour;
  1675. tmStop.tm_min = parseStop.min;
  1676. tmStop.tm_sec = parseStop.sec;
  1677. tmStop.tm_gmtoff = 0;
  1678. tbStop.time = mktime(&tmStop);
  1679. tbStop.timezone = 0;
  1680. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1681. result = DiffTimebSec(tbStart, tbStop);
  1682. //DEBUG_INFO("getStartStop(): %d\n", result);
  1683. }
  1684. else
  1685. {
  1686. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1687. }
  1688. return result;
  1689. }
  1690. int isOvertNow(uint8_t *start)
  1691. {
  1692. int result = NO;
  1693. struct ParsingResult
  1694. {
  1695. int result;
  1696. int scanedElement;
  1697. int year;
  1698. int month;
  1699. int mday;
  1700. int hour;
  1701. int min;
  1702. int sec;
  1703. int tz_hour;
  1704. int tz_min;
  1705. float minSec;
  1706. }parsingResult;
  1707. struct tm tmStart;
  1708. struct timeb tbStart;
  1709. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1710. if(strstr((char*)start, ".") != NULL)
  1711. {
  1712. // Original data with mini second
  1713. if(strstr((char*)start, "Z") != NULL)
  1714. {
  1715. // Original data with Z
  1716. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1717. &parsingResult.year,
  1718. &parsingResult.month,
  1719. &parsingResult.mday,
  1720. &parsingResult.hour,
  1721. &parsingResult.min,
  1722. &parsingResult.sec,
  1723. &parsingResult.minSec);
  1724. }
  1725. else
  1726. {
  1727. // Original data without Z
  1728. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1729. &parsingResult.year,
  1730. &parsingResult.month,
  1731. &parsingResult.mday,
  1732. &parsingResult.hour,
  1733. &parsingResult.min,
  1734. &parsingResult.sec,
  1735. &parsingResult.minSec,
  1736. &parsingResult.tz_hour,
  1737. &parsingResult.tz_min);
  1738. }
  1739. }
  1740. else
  1741. {
  1742. // Original data without mini second
  1743. if(strstr((char*)start, "Z") != NULL)
  1744. {
  1745. // Original data with Z
  1746. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1747. &parsingResult.year,
  1748. &parsingResult.month,
  1749. &parsingResult.mday,
  1750. &parsingResult.hour,
  1751. &parsingResult.min,
  1752. &parsingResult.sec);
  1753. }
  1754. else
  1755. {
  1756. // Original data without Z
  1757. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1758. &parsingResult.year,
  1759. &parsingResult.month,
  1760. &parsingResult.mday,
  1761. &parsingResult.hour,
  1762. &parsingResult.min,
  1763. &parsingResult.sec,
  1764. &parsingResult.tz_hour,
  1765. &parsingResult.tz_min);
  1766. }
  1767. }
  1768. if(parsingResult.scanedElement >= 6)
  1769. {
  1770. tmStart.tm_year = parsingResult.year - 1900;
  1771. tmStart.tm_mon = parsingResult.month - 1;
  1772. tmStart.tm_mday = parsingResult.mday;
  1773. tmStart.tm_hour = parsingResult.hour;
  1774. tmStart.tm_min = parsingResult.min;
  1775. tmStart.tm_sec = parsingResult.sec;
  1776. tmStart.tm_gmtoff = 0;
  1777. tbStart.time = mktime(&tmStart);
  1778. tbStart.timezone = 0;
  1779. tbStart.millitm = 0;
  1780. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1781. if(DiffTimebWithNowSec(tbStart) <= 0)
  1782. result = NO;
  1783. else
  1784. result = YES;
  1785. }
  1786. else
  1787. {
  1788. DEBUG_WARN("Start date parsing error.\n");
  1789. }
  1790. return result;
  1791. }
  1792. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1793. {
  1794. struct ParsingResult
  1795. {
  1796. int result;
  1797. int scanedElement;
  1798. int year;
  1799. int month;
  1800. int mday;
  1801. int hour;
  1802. int min;
  1803. int sec;
  1804. int tz_hour;
  1805. int tz_min;
  1806. float minSec;
  1807. };
  1808. struct ParsingResult parseStart;
  1809. struct ParsingResult parseStop;
  1810. int result = -1;
  1811. struct tm tmStart;
  1812. struct timeb tbStart;
  1813. struct tm tmStop;
  1814. struct timeb tbStop;
  1815. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1816. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1817. // Scan start & stop date time
  1818. if(strstr((char*)start, ".") != NULL)
  1819. {
  1820. // Original data with mini second
  1821. if(strstr((char*)start, "Z") != NULL)
  1822. {
  1823. // Original data with Z
  1824. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1825. &parseStart.year,
  1826. &parseStart.month,
  1827. &parseStart.mday,
  1828. &parseStart.hour,
  1829. &parseStart.min,
  1830. &parseStart.sec,
  1831. &parseStart.minSec);
  1832. }
  1833. else
  1834. {
  1835. // Original data without Z
  1836. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1837. &parseStart.year,
  1838. &parseStart.month,
  1839. &parseStart.mday,
  1840. &parseStart.hour,
  1841. &parseStart.min,
  1842. &parseStart.sec,
  1843. &parseStart.minSec,
  1844. &parseStart.tz_hour,
  1845. &parseStart.tz_min);
  1846. }
  1847. }
  1848. else
  1849. {
  1850. // Original data without mini second
  1851. if(strstr((char*)start, "Z") != NULL)
  1852. {
  1853. // Original data with Z
  1854. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1855. &parseStart.year,
  1856. &parseStart.month,
  1857. &parseStart.mday,
  1858. &parseStart.hour,
  1859. &parseStart.min,
  1860. &parseStart.sec);
  1861. }
  1862. else
  1863. {
  1864. // Original data without Z
  1865. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1866. &parseStart.year,
  1867. &parseStart.month,
  1868. &parseStart.mday,
  1869. &parseStart.hour,
  1870. &parseStart.min,
  1871. &parseStart.sec,
  1872. &parseStart.tz_hour,
  1873. &parseStart.tz_min);
  1874. }
  1875. }
  1876. if(strstr((char*)stop, ".") != NULL)
  1877. {
  1878. // Original data with mini second
  1879. if(strstr((char*)stop, "Z") != NULL)
  1880. {
  1881. // Original data with Z
  1882. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1883. &parseStop.year,
  1884. &parseStop.month,
  1885. &parseStop.mday,
  1886. &parseStop.hour,
  1887. &parseStop.min,
  1888. &parseStop.sec,
  1889. &parseStop.minSec);
  1890. }
  1891. else
  1892. {
  1893. // Original data without Z
  1894. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1895. &parseStop.year,
  1896. &parseStop.month,
  1897. &parseStop.mday,
  1898. &parseStop.hour,
  1899. &parseStop.min,
  1900. &parseStop.sec,
  1901. &parseStop.minSec,
  1902. &parseStop.tz_hour,
  1903. &parseStop.tz_min);
  1904. }
  1905. }
  1906. else
  1907. {
  1908. // Original data without mini second
  1909. if(strstr((char*)stop, "Z") != NULL)
  1910. {
  1911. // Original data with Z
  1912. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1913. &parseStop.year,
  1914. &parseStop.month,
  1915. &parseStop.mday,
  1916. &parseStop.hour,
  1917. &parseStop.min,
  1918. &parseStop.sec);
  1919. }
  1920. else
  1921. {
  1922. // Original data without Z
  1923. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1924. &parseStop.year,
  1925. &parseStop.month,
  1926. &parseStop.mday,
  1927. &parseStop.hour,
  1928. &parseStop.min,
  1929. &parseStop.sec,
  1930. &parseStop.tz_hour,
  1931. &parseStop.tz_min);
  1932. }
  1933. }
  1934. // Calculate date time difference
  1935. if((parseStart.scanedElement >=6) &&
  1936. (parseStop.scanedElement >=6))
  1937. {
  1938. //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);
  1939. //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);
  1940. tmStart.tm_year = parseStart.year - 1900;
  1941. tmStart.tm_mon = parseStart.month - 1;
  1942. tmStart.tm_mday = parseStart.mday;
  1943. tmStart.tm_hour = parseStart.hour;
  1944. tmStart.tm_min = parseStart.min;
  1945. tmStart.tm_sec = parseStart.sec;
  1946. tmStart.tm_gmtoff = 0;
  1947. tbStart.time = mktime(&tmStart);
  1948. tbStart.timezone = 0;
  1949. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1950. tmStop.tm_year = parseStop.year - 1900;
  1951. tmStop.tm_mon = parseStop.month - 1;
  1952. tmStop.tm_mday = parseStop.mday;
  1953. tmStop.tm_hour = parseStop.hour;
  1954. tmStop.tm_min = parseStop.min;
  1955. tmStop.tm_sec = parseStop.sec;
  1956. tmStop.tm_gmtoff = 0;
  1957. tbStop.time = mktime(&tmStop);
  1958. tbStop.timezone = 0;
  1959. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1960. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1961. //DEBUG_INFO("getStartStop(): %d\n", result);
  1962. }
  1963. else
  1964. {
  1965. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1966. }
  1967. return result;
  1968. }
  1969. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1970. {
  1971. FILE *fp;
  1972. char profileFileName[128];
  1973. char *line = NULL;
  1974. size_t len = 0;
  1975. time_t CurrentTime;
  1976. struct tm *tmComposite;
  1977. struct StructChargingProfile maxProfile;
  1978. struct StructChargingProfile compositeProfile;
  1979. uint8_t limitMax=0;
  1980. int compositePeriodIdx = 0;
  1981. //uint8_t isDurationNull = FALSE;
  1982. CurrentTime = time(NULL);
  1983. tmComposite=localtime(&CurrentTime);
  1984. 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);
  1985. if(isUnitA)
  1986. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1987. else
  1988. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1989. compositeProfile.ChargingSchedule.Duration = durationReq;
  1990. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1991. {
  1992. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1993. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1994. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1995. }
  1996. compositeProfile.ChargingProfileId = 0;
  1997. compositeProfile.StackLevel = 99 ;
  1998. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1999. maxProfile.ChargingProfileId = -1;
  2000. maxProfile.ChargingSchedule.Duration = -1;
  2001. system("rm -f /tmp/*.json");
  2002. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2003. // Search max profile
  2004. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2005. if((access(profileFileName, F_OK))!=-1)
  2006. {
  2007. fp = fopen(profileFileName, "r");
  2008. while(getline(&line, &len, fp) != -1)
  2009. {
  2010. json_object *obj = NULL;
  2011. obj = json_tokener_parse(line);
  2012. if(is_error(obj))
  2013. {
  2014. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2015. }
  2016. else
  2017. {
  2018. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2019. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2020. )
  2021. {
  2022. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2023. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2024. )
  2025. {
  2026. struct tm tmFrom, tmTo;
  2027. struct timeb tbFrom, tbTo;
  2028. 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) &&
  2029. (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))
  2030. {
  2031. tmFrom.tm_year -= 1900;
  2032. tmFrom.tm_mon -= 1;
  2033. tbFrom.time = mktime(&tmFrom);
  2034. tmTo.tm_year -= 1900;
  2035. tmTo.tm_mon -= 1;
  2036. tbTo.time = mktime(&tmTo);
  2037. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2038. {
  2039. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2040. {
  2041. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2042. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2043. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2044. }
  2045. if(maxProfile.ChargingProfileId == -1)
  2046. DEBUG_INFO("MaxProfile found.\n");
  2047. else
  2048. DEBUG_INFO("MaxProfile updated.\n");
  2049. // Required item
  2050. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2051. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2052. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2053. if(isUnitA)
  2054. {
  2055. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2056. 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++)
  2057. {
  2058. 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"));
  2059. 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?
  2060. 3:
  2061. 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")));
  2062. 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")));
  2063. }
  2064. }
  2065. else
  2066. {
  2067. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2068. 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++)
  2069. {
  2070. 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"));
  2071. 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?
  2072. 3:
  2073. 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")));
  2074. 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));
  2075. }
  2076. }
  2077. // Optional item
  2078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2079. {
  2080. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2081. }
  2082. else
  2083. {
  2084. sprintf((char*)maxProfile.ValidFrom, " ");
  2085. }
  2086. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2087. {
  2088. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2089. }
  2090. else
  2091. {
  2092. sprintf((char*)maxProfile.ValidTo, " ");
  2093. }
  2094. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2095. {
  2096. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2097. }
  2098. else
  2099. {
  2100. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2101. }
  2102. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2103. {
  2104. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2105. }
  2106. else
  2107. {
  2108. maxProfile.TransactionId = -1;
  2109. }
  2110. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2111. {
  2112. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2113. }
  2114. else
  2115. {
  2116. maxProfile.ChargingSchedule.Duration = 86400;
  2117. //isDurationNull = TRUE;
  2118. }
  2119. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2120. {
  2121. 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")));
  2122. }
  2123. else
  2124. {
  2125. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2126. }
  2127. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2128. {
  2129. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2130. }
  2131. else
  2132. {
  2133. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2134. }
  2135. }
  2136. }
  2137. }
  2138. else
  2139. {
  2140. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2141. {
  2142. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2143. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2144. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2145. }
  2146. if(maxProfile.ChargingProfileId == -1)
  2147. DEBUG_INFO("MaxProfile found.\n");
  2148. else
  2149. DEBUG_INFO("MaxProfile updated.\n");
  2150. // Required item
  2151. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2152. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2153. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2154. if(isUnitA)
  2155. {
  2156. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2157. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2158. {
  2159. 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"));
  2160. 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?
  2161. 3:
  2162. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2163. 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")));
  2164. }
  2165. }
  2166. else
  2167. {
  2168. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2169. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2170. {
  2171. 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"));
  2172. 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?
  2173. 3:
  2174. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2175. 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));
  2176. }
  2177. }
  2178. // Optional item
  2179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2180. {
  2181. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2182. }
  2183. else
  2184. {
  2185. sprintf((char*)maxProfile.ValidFrom, " ");
  2186. }
  2187. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2188. {
  2189. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2190. }
  2191. else
  2192. {
  2193. sprintf((char*)maxProfile.ValidTo, " ");
  2194. }
  2195. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2196. {
  2197. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2198. }
  2199. else
  2200. {
  2201. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2202. }
  2203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2204. {
  2205. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2206. }
  2207. else
  2208. {
  2209. maxProfile.TransactionId = -1;
  2210. }
  2211. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2212. {
  2213. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2214. }
  2215. else
  2216. {
  2217. maxProfile.ChargingSchedule.Duration = 86400;
  2218. //isDurationNull = TRUE;
  2219. }
  2220. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2221. {
  2222. 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")));
  2223. }
  2224. else
  2225. {
  2226. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2227. }
  2228. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2229. {
  2230. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2231. }
  2232. else
  2233. {
  2234. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2235. }
  2236. }
  2237. }
  2238. }
  2239. json_object_put(obj);
  2240. }
  2241. fclose(fp);
  2242. /*
  2243. if(maxProfile.ChargingProfileId !=-1)
  2244. {
  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", maxProfile.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. }
  2266. else
  2267. DEBUG_INFO("MaxProfile not found.\n");
  2268. DEBUG_INFO("------------------------------------\n");*/
  2269. }
  2270. if(maxProfile.ChargingProfileId != -1)
  2271. {
  2272. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2273. {
  2274. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2275. {
  2276. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2277. 0:
  2278. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2279. }
  2280. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2281. {
  2282. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2283. {
  2284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2285. 0:
  2286. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2287. if(idxPeriod > 0)
  2288. {
  2289. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2290. {
  2291. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2292. }
  2293. }
  2294. }
  2295. }
  2296. }
  2297. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2298. {
  2299. if(maxProfile.ChargingSchedule.Duration != -1)
  2300. {
  2301. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2302. }
  2303. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2304. {
  2305. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2306. {
  2307. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2308. if(idxPeriod > 0)
  2309. {
  2310. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2311. {
  2312. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. else
  2319. {
  2320. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2321. {
  2322. if(maxProfile.ChargingSchedule.Duration != -1)
  2323. {
  2324. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2325. 0:
  2326. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2327. }
  2328. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2329. {
  2330. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2331. {
  2332. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2333. 0:
  2334. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2335. if(idxPeriod > 0)
  2336. {
  2337. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2338. {
  2339. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. else
  2346. {
  2347. if(maxProfile.ChargingSchedule.Duration != -1)
  2348. {
  2349. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2350. 0:
  2351. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2352. }
  2353. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2354. {
  2355. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2356. {
  2357. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2358. 0:
  2359. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2360. if(idxPeriod > 0)
  2361. {
  2362. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2363. {
  2364. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2365. }
  2366. }
  2367. }
  2368. }
  2369. }
  2370. }
  2371. /*
  2372. DEBUG_INFO("MaxProfile after align.\n");
  2373. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2374. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2375. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2376. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2377. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2378. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2379. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2380. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2381. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2382. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2383. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2384. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2385. {
  2386. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2387. {
  2388. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2389. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2390. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2391. }
  2392. }
  2393. DEBUG_INFO("------------------------------------\n");*/
  2394. }
  2395. // Find each profile period quantity
  2396. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2397. {
  2398. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2399. limitMax = idx+1;
  2400. }
  2401. if(maxProfile.ChargingProfileId != -1)
  2402. {
  2403. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2404. {
  2405. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2406. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2407. (maxProfile.ChargingSchedule.Duration > 0))
  2408. {
  2409. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2410. {
  2411. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2412. compositePeriodIdx++;
  2413. }
  2414. else
  2415. {
  2416. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2417. }
  2418. }
  2419. }
  2420. }
  2421. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2422. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2423. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2424. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2425. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2426. {
  2427. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2428. {
  2429. compositeProfile.ChargingProfileId = 1;
  2430. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2431. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2432. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2433. }
  2434. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2435. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2436. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2437. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2438. }
  2439. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2440. if(line)
  2441. free(line);
  2442. }
  2443. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2444. {
  2445. FILE *fp;
  2446. char profileFileName[128];
  2447. char *line = NULL;
  2448. size_t len = 0;
  2449. time_t CurrentTime;
  2450. struct tm *tmComposite;
  2451. struct StructChargingProfile maxProfile;
  2452. struct StructChargingProfile defaultTxProfile;
  2453. struct StructChargingProfile txProfile;
  2454. struct StructChargingProfile compositeProfile;
  2455. struct StructChargingSchedulePeriod tmpPeriod;
  2456. uint8_t limitMax=0;
  2457. uint8_t limitDef=0;
  2458. uint8_t limitTx=0;
  2459. int compositePeriodIdx = 0;
  2460. CurrentTime = time(NULL);
  2461. tmComposite=localtime(&CurrentTime);
  2462. 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);
  2463. if(isUnitA)
  2464. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2465. else
  2466. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2467. compositeProfile.ChargingSchedule.Duration = durationReq;
  2468. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2469. {
  2470. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2471. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2472. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2473. }
  2474. compositeProfile.ChargingProfileId = 0;
  2475. compositeProfile.StackLevel = 99 ;
  2476. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2477. maxProfile.ChargingProfileId = -1;
  2478. defaultTxProfile.ChargingProfileId = -1;
  2479. txProfile.ChargingProfileId = -1;
  2480. maxProfile.ChargingSchedule.Duration = -1;
  2481. defaultTxProfile.ChargingSchedule.Duration = -1;
  2482. txProfile.ChargingSchedule.Duration = -1;
  2483. system("rm -f /tmp/*.json");
  2484. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2485. /*
  2486. * Search valid charging profile
  2487. */
  2488. //DEBUG_INFO("====================================\n");
  2489. // Search tx profile
  2490. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2491. if((access(profileFileName, F_OK))!=-1)
  2492. {
  2493. fp = fopen(profileFileName, "r");
  2494. while(getline(&line, &len, fp) != -1)
  2495. {
  2496. json_object *obj = NULL;
  2497. obj = json_tokener_parse(line);
  2498. if(is_error(obj))
  2499. {
  2500. DEBUG_ERROR("Parse txProfile from file error.\n");
  2501. }
  2502. else
  2503. {
  2504. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2505. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2506. )
  2507. {
  2508. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2509. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2510. )
  2511. {
  2512. struct tm tmFrom, tmTo;
  2513. struct timeb tbFrom, tbTo;
  2514. 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) &&
  2515. (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))
  2516. {
  2517. tmFrom.tm_year -= 1900;
  2518. tmFrom.tm_mon -= 1;
  2519. tbFrom.time = mktime(&tmFrom);
  2520. tmTo.tm_year -= 1900;
  2521. tmTo.tm_mon -= 1;
  2522. tbTo.time = mktime(&tmTo);
  2523. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2524. {
  2525. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2526. {
  2527. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2528. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2529. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2530. }
  2531. if(txProfile.ChargingProfileId == -1)
  2532. DEBUG_INFO("TxProfile found.\n");
  2533. else
  2534. DEBUG_INFO("TxProfile updated.\n");
  2535. // Required item
  2536. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2537. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2538. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2539. if(isUnitA)
  2540. {
  2541. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2542. 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++)
  2543. {
  2544. 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"));
  2545. 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?
  2546. 3:
  2547. 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")));
  2548. 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")));
  2549. }
  2550. }
  2551. else
  2552. {
  2553. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2554. 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++)
  2555. {
  2556. 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"));
  2557. 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?
  2558. 3:
  2559. 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")));
  2560. 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));
  2561. }
  2562. }
  2563. // Optional item
  2564. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2565. {
  2566. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2567. }
  2568. else
  2569. {
  2570. sprintf((char*)txProfile.ValidFrom, " ");
  2571. }
  2572. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2573. {
  2574. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2575. }
  2576. else
  2577. {
  2578. sprintf((char*)txProfile.ValidTo, " ");
  2579. }
  2580. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2581. {
  2582. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2583. }
  2584. else
  2585. {
  2586. sprintf((char*)txProfile.RecurrencyKind, " ");
  2587. }
  2588. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2589. {
  2590. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2591. }
  2592. else
  2593. {
  2594. txProfile.TransactionId = -1;
  2595. }
  2596. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2597. {
  2598. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2599. }
  2600. else
  2601. {
  2602. txProfile.ChargingSchedule.Duration = 86400;
  2603. }
  2604. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2605. {
  2606. 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")));
  2607. }
  2608. else
  2609. {
  2610. 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));
  2611. }
  2612. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2613. {
  2614. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2615. }
  2616. else
  2617. {
  2618. txProfile.ChargingSchedule.MinChargingRate = -1;
  2619. }
  2620. }
  2621. }
  2622. }
  2623. else
  2624. {
  2625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2626. {
  2627. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2628. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2629. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2630. }
  2631. if(txProfile.ChargingProfileId == -1)
  2632. DEBUG_INFO("TxProfile found.\n");
  2633. else
  2634. DEBUG_INFO("TxProfile updated.\n");
  2635. // Required item
  2636. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2637. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2638. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2639. if(isUnitA)
  2640. {
  2641. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2642. 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++)
  2643. {
  2644. 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"));
  2645. 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?
  2646. 3:
  2647. 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")));
  2648. 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")));
  2649. }
  2650. }
  2651. else
  2652. {
  2653. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2654. 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++)
  2655. {
  2656. 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"));
  2657. 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?
  2658. 3:
  2659. 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")));
  2660. 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));
  2661. }
  2662. }
  2663. // Optional item
  2664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2665. {
  2666. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2667. }
  2668. else
  2669. {
  2670. sprintf((char*)txProfile.ValidFrom, " ");
  2671. }
  2672. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2673. {
  2674. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2675. }
  2676. else
  2677. {
  2678. sprintf((char*)txProfile.ValidTo, " ");
  2679. }
  2680. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2681. {
  2682. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2683. }
  2684. else
  2685. {
  2686. sprintf((char*)txProfile.RecurrencyKind, " ");
  2687. }
  2688. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2689. {
  2690. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2691. }
  2692. else
  2693. {
  2694. txProfile.TransactionId = -1;
  2695. }
  2696. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2697. {
  2698. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2699. }
  2700. else
  2701. {
  2702. txProfile.ChargingSchedule.Duration = 86400;
  2703. }
  2704. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2705. {
  2706. 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")));
  2707. }
  2708. else
  2709. {
  2710. 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));
  2711. }
  2712. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2713. {
  2714. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2715. }
  2716. else
  2717. {
  2718. txProfile.ChargingSchedule.MinChargingRate = -1;
  2719. }
  2720. }
  2721. }
  2722. }
  2723. json_object_put(obj);
  2724. }
  2725. fclose(fp);
  2726. /*
  2727. if(txProfile.ChargingProfileId != -1)
  2728. {
  2729. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2730. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2731. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2732. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2733. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2734. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2735. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2736. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2737. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2738. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2739. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2740. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2741. {
  2742. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2743. {
  2744. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2745. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2746. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2747. }
  2748. }
  2749. }
  2750. else
  2751. DEBUG_INFO("TxProfile not found.\n");*/
  2752. }
  2753. // Search default tx profile
  2754. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2755. if((access(profileFileName, F_OK))==-1)
  2756. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2757. if((access(profileFileName, F_OK))!=-1)
  2758. {
  2759. fp = fopen(profileFileName, "r");
  2760. while(getline(&line, &len, fp) != -1)
  2761. {
  2762. json_object *obj = NULL;
  2763. obj = json_tokener_parse(line);
  2764. if(is_error(obj))
  2765. {
  2766. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2767. }
  2768. else
  2769. {
  2770. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2771. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2772. )
  2773. {
  2774. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2775. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2776. )
  2777. {
  2778. struct tm tmFrom, tmTo;
  2779. struct timeb tbFrom, tbTo;
  2780. 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) &&
  2781. (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))
  2782. {
  2783. tmFrom.tm_year -= 1900;
  2784. tmFrom.tm_mon -= 1;
  2785. tbFrom.time = mktime(&tmFrom);
  2786. tmTo.tm_year -= 1900;
  2787. tmTo.tm_mon -= 1;
  2788. tbTo.time = mktime(&tmTo);
  2789. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2790. {
  2791. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2792. {
  2793. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2794. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2795. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2796. }
  2797. if(defaultTxProfile.ChargingProfileId == -1)
  2798. DEBUG_INFO("TxDefaultProfile found.\n");
  2799. else
  2800. DEBUG_INFO("TxDefaultProfile updated.\n");
  2801. // Required item
  2802. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2803. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2804. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2805. if(isUnitA)
  2806. {
  2807. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2808. 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++)
  2809. {
  2810. 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"));
  2811. 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?
  2812. 3:
  2813. 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")));
  2814. 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")));
  2815. }
  2816. }
  2817. else
  2818. {
  2819. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2820. 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++)
  2821. {
  2822. 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"));
  2823. 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?
  2824. 3:
  2825. 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")));
  2826. 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));
  2827. }
  2828. }
  2829. // Optional item
  2830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2831. {
  2832. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2833. }
  2834. else
  2835. {
  2836. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2837. }
  2838. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2839. {
  2840. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2841. }
  2842. else
  2843. {
  2844. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2845. }
  2846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2847. {
  2848. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2849. }
  2850. else
  2851. {
  2852. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2853. }
  2854. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2855. {
  2856. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2857. }
  2858. else
  2859. {
  2860. defaultTxProfile.TransactionId = -1;
  2861. }
  2862. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2863. {
  2864. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2865. }
  2866. else
  2867. {
  2868. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2869. }
  2870. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2871. {
  2872. 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")));
  2873. }
  2874. else
  2875. {
  2876. 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));
  2877. }
  2878. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2879. {
  2880. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2881. }
  2882. else
  2883. {
  2884. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2885. }
  2886. }
  2887. }
  2888. }
  2889. else
  2890. {
  2891. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2892. {
  2893. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2894. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2895. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2896. }
  2897. if(defaultTxProfile.ChargingProfileId == -1)
  2898. DEBUG_INFO("TxDefaultProfile found.\n");
  2899. else
  2900. DEBUG_INFO("TxDefaultProfile updated.\n");
  2901. // Required item
  2902. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2903. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2904. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2905. if(isUnitA)
  2906. {
  2907. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2908. 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++)
  2909. {
  2910. 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"));
  2911. 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?
  2912. 3:
  2913. 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")));
  2914. 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")));
  2915. }
  2916. }
  2917. else
  2918. {
  2919. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2920. 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++)
  2921. {
  2922. 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"));
  2923. 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?
  2924. 3:
  2925. 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")));
  2926. 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));
  2927. }
  2928. }
  2929. // Optional item
  2930. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2931. {
  2932. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2933. }
  2934. else
  2935. {
  2936. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2937. }
  2938. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2939. {
  2940. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2941. }
  2942. else
  2943. {
  2944. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2945. }
  2946. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2947. {
  2948. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2949. }
  2950. else
  2951. {
  2952. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2953. }
  2954. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2955. {
  2956. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2957. }
  2958. else
  2959. {
  2960. defaultTxProfile.TransactionId = -1;
  2961. }
  2962. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2963. {
  2964. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2965. }
  2966. else
  2967. {
  2968. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2969. }
  2970. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2971. {
  2972. 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")));
  2973. }
  2974. else
  2975. {
  2976. 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));
  2977. }
  2978. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2979. {
  2980. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2981. }
  2982. else
  2983. {
  2984. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2985. }
  2986. }
  2987. }
  2988. }
  2989. json_object_put(obj);
  2990. }
  2991. fclose(fp);
  2992. /*
  2993. if(defaultTxProfile.ChargingProfileId != -1)
  2994. {
  2995. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2996. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2997. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2998. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2999. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3000. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3001. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3002. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  3003. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3004. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3005. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3006. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3007. {
  3008. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3009. {
  3010. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3011. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3012. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3013. }
  3014. }
  3015. }
  3016. else
  3017. DEBUG_INFO("TxDefaultProfile not found.\n");
  3018. DEBUG_INFO("------------------------------------\n");*/
  3019. }
  3020. // Search max profile
  3021. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3022. if((access(profileFileName, F_OK))!=-1)
  3023. {
  3024. fp = fopen(profileFileName, "r");
  3025. while(getline(&line, &len, fp) != -1)
  3026. {
  3027. json_object *obj = NULL;
  3028. obj = json_tokener_parse(line);
  3029. if(is_error(obj))
  3030. {
  3031. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3032. }
  3033. else
  3034. {
  3035. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3036. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3037. )
  3038. {
  3039. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3040. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3041. )
  3042. {
  3043. struct tm tmFrom, tmTo;
  3044. struct timeb tbFrom, tbTo;
  3045. 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) &&
  3046. (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))
  3047. {
  3048. tmFrom.tm_year -= 1900;
  3049. tmFrom.tm_mon -= 1;
  3050. tbFrom.time = mktime(&tmFrom);
  3051. tmTo.tm_year -= 1900;
  3052. tmTo.tm_mon -= 1;
  3053. tbTo.time = mktime(&tmTo);
  3054. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3055. {
  3056. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3057. {
  3058. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3059. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3060. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3061. }
  3062. if(maxProfile.ChargingProfileId == -1)
  3063. DEBUG_INFO("MaxProfile found.\n");
  3064. else
  3065. DEBUG_INFO("MaxProfile updated.\n");
  3066. // Required item
  3067. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3068. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3069. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3070. if(isUnitA)
  3071. {
  3072. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3073. 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++)
  3074. {
  3075. 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"));
  3076. 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?
  3077. 3:
  3078. 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")));
  3079. 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")));
  3080. }
  3081. }
  3082. else
  3083. {
  3084. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3085. 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++)
  3086. {
  3087. 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"));
  3088. 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?
  3089. 3:
  3090. 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")));
  3091. 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));
  3092. }
  3093. }
  3094. // Optional item
  3095. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3096. {
  3097. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3098. }
  3099. else
  3100. {
  3101. sprintf((char*)maxProfile.ValidFrom, " ");
  3102. }
  3103. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3104. {
  3105. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3106. }
  3107. else
  3108. {
  3109. sprintf((char*)maxProfile.ValidTo, " ");
  3110. }
  3111. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3112. {
  3113. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3114. }
  3115. else
  3116. {
  3117. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3118. }
  3119. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3120. {
  3121. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3122. }
  3123. else
  3124. {
  3125. maxProfile.TransactionId = -1;
  3126. }
  3127. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3128. {
  3129. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3130. }
  3131. else
  3132. {
  3133. maxProfile.ChargingSchedule.Duration = 86400;
  3134. }
  3135. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3136. {
  3137. 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")));
  3138. }
  3139. else
  3140. {
  3141. 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));
  3142. }
  3143. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3144. {
  3145. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3146. }
  3147. else
  3148. {
  3149. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3150. }
  3151. }
  3152. }
  3153. }
  3154. else
  3155. {
  3156. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3157. {
  3158. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3159. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3160. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3161. }
  3162. if(maxProfile.ChargingProfileId == -1)
  3163. DEBUG_INFO("MaxProfile found.\n");
  3164. else
  3165. DEBUG_INFO("MaxProfile updated.\n");
  3166. // Required item
  3167. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3168. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3169. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3170. if(isUnitA)
  3171. {
  3172. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3173. 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++)
  3174. {
  3175. 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"));
  3176. 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?
  3177. 3:
  3178. 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")));
  3179. 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")));
  3180. }
  3181. }
  3182. else
  3183. {
  3184. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3185. 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++)
  3186. {
  3187. 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"));
  3188. 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?
  3189. 3:
  3190. 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")));
  3191. 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));
  3192. }
  3193. }
  3194. // Optional item
  3195. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3196. {
  3197. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3198. }
  3199. else
  3200. {
  3201. sprintf((char*)maxProfile.ValidFrom, " ");
  3202. }
  3203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3204. {
  3205. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3206. }
  3207. else
  3208. {
  3209. sprintf((char*)maxProfile.ValidTo, " ");
  3210. }
  3211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3212. {
  3213. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3214. }
  3215. else
  3216. {
  3217. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3218. }
  3219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3220. {
  3221. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3222. }
  3223. else
  3224. {
  3225. maxProfile.TransactionId = -1;
  3226. }
  3227. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3228. {
  3229. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3230. }
  3231. else
  3232. {
  3233. maxProfile.ChargingSchedule.Duration = 86400;
  3234. }
  3235. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3236. {
  3237. 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")));
  3238. }
  3239. else
  3240. {
  3241. 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));
  3242. }
  3243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3244. {
  3245. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3246. }
  3247. else
  3248. {
  3249. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3250. }
  3251. }
  3252. }
  3253. }
  3254. json_object_put(obj);
  3255. }
  3256. fclose(fp);
  3257. /*
  3258. if(maxProfile.ChargingProfileId !=-1)
  3259. {
  3260. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3261. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3262. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3263. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3264. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3265. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3266. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3267. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3268. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3269. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3270. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3271. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3272. {
  3273. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3274. {
  3275. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3276. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3277. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3278. }
  3279. }
  3280. }
  3281. else
  3282. DEBUG_INFO("MaxProfile not found.\n");
  3283. DEBUG_INFO("------------------------------------\n");*/
  3284. }
  3285. /*
  3286. * Align found profile start schedule & periods
  3287. */
  3288. //DEBUG_INFO("====================================\n");
  3289. /*
  3290. // For local test usage, force modify found profile start schedule info
  3291. 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);
  3292. 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);
  3293. 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);
  3294. */
  3295. if(txProfile.ChargingProfileId != -1)
  3296. {
  3297. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3298. {
  3299. if(txProfile.ChargingSchedule.Duration != -1)
  3300. {
  3301. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3302. 0:
  3303. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3304. }
  3305. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3306. {
  3307. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3308. {
  3309. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3310. 0:
  3311. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3312. if(idxPeriod > 0)
  3313. {
  3314. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3315. {
  3316. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3317. }
  3318. }
  3319. }
  3320. }
  3321. }
  3322. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3323. {
  3324. if(txProfile.ChargingSchedule.Duration != -1)
  3325. {
  3326. 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?
  3327. 0:
  3328. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3329. }
  3330. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3331. {
  3332. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3333. {
  3334. 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?
  3335. 0:
  3336. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3337. if(idxPeriod > 0)
  3338. {
  3339. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3340. {
  3341. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3342. }
  3343. }
  3344. }
  3345. }
  3346. }
  3347. else
  3348. {
  3349. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3350. {
  3351. if(txProfile.ChargingSchedule.Duration != -1)
  3352. {
  3353. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3354. 0:
  3355. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3356. }
  3357. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3358. {
  3359. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3360. {
  3361. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3362. 0:
  3363. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3364. if(idxPeriod > 0)
  3365. {
  3366. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3367. {
  3368. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3369. }
  3370. }
  3371. }
  3372. }
  3373. }
  3374. else
  3375. {
  3376. if(txProfile.ChargingSchedule.Duration != -1)
  3377. {
  3378. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3379. 0:
  3380. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3381. }
  3382. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3383. {
  3384. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3385. {
  3386. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3387. 0:
  3388. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3389. if(idxPeriod > 0)
  3390. {
  3391. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3392. {
  3393. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3394. }
  3395. }
  3396. }
  3397. }
  3398. }
  3399. }
  3400. /*
  3401. DEBUG_INFO("txProfile after align.\n");
  3402. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3403. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3404. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3405. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3406. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3407. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3408. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3409. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3410. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3411. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3412. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3413. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3414. {
  3415. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3416. {
  3417. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3418. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3419. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3420. }
  3421. }*/
  3422. }
  3423. if(defaultTxProfile.ChargingProfileId != -1)
  3424. {
  3425. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3426. {
  3427. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3428. {
  3429. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3430. 0:
  3431. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3432. }
  3433. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3434. {
  3435. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3436. {
  3437. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3438. 0:
  3439. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3440. if(idxPeriod > 0)
  3441. {
  3442. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3443. {
  3444. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3445. }
  3446. }
  3447. }
  3448. }
  3449. }
  3450. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3451. {
  3452. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3453. {
  3454. 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?
  3455. 0:
  3456. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3457. }
  3458. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3459. {
  3460. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3461. {
  3462. 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?
  3463. 0:
  3464. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3465. if(idxPeriod > 0)
  3466. {
  3467. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3468. {
  3469. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3470. }
  3471. }
  3472. }
  3473. }
  3474. }
  3475. else
  3476. {
  3477. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3478. {
  3479. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3480. {
  3481. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3482. 0:
  3483. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3484. }
  3485. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3486. {
  3487. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3488. {
  3489. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3490. 0:
  3491. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3492. if(idxPeriod > 0)
  3493. {
  3494. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3495. {
  3496. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3497. }
  3498. }
  3499. }
  3500. }
  3501. }
  3502. else
  3503. {
  3504. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3505. {
  3506. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3507. 0:
  3508. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3509. }
  3510. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3511. {
  3512. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3513. {
  3514. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3515. 0:
  3516. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3517. if(idxPeriod > 0)
  3518. {
  3519. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3520. {
  3521. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3522. }
  3523. }
  3524. }
  3525. }
  3526. }
  3527. }
  3528. /*
  3529. DEBUG_INFO("defaultTxProfile after align.\n");
  3530. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3531. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3532. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3533. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3534. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3535. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3536. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3537. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3538. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3539. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3540. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3541. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3542. {
  3543. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3544. {
  3545. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3546. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3547. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3548. }
  3549. }
  3550. DEBUG_INFO("------------------------------------\n");*/
  3551. }
  3552. if(maxProfile.ChargingProfileId != -1)
  3553. {
  3554. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3555. {
  3556. if(maxProfile.ChargingSchedule.Duration != -1)
  3557. {
  3558. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3559. 0:
  3560. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3561. }
  3562. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3563. {
  3564. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3565. {
  3566. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3567. 0:
  3568. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3569. if(idxPeriod > 0)
  3570. {
  3571. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3572. {
  3573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3574. }
  3575. }
  3576. }
  3577. }
  3578. }
  3579. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3580. {
  3581. if(maxProfile.ChargingSchedule.Duration != -1)
  3582. {
  3583. 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?
  3584. 0:
  3585. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3586. }
  3587. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3588. {
  3589. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3590. {
  3591. 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?
  3592. 0:
  3593. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3594. if(idxPeriod > 0)
  3595. {
  3596. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3597. {
  3598. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3599. }
  3600. }
  3601. }
  3602. }
  3603. }
  3604. else
  3605. {
  3606. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3607. {
  3608. if(maxProfile.ChargingSchedule.Duration != -1)
  3609. {
  3610. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3611. 0:
  3612. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3613. }
  3614. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3615. {
  3616. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3617. {
  3618. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3619. 0:
  3620. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3621. if(idxPeriod > 0)
  3622. {
  3623. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3624. {
  3625. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3626. }
  3627. }
  3628. }
  3629. }
  3630. }
  3631. else
  3632. {
  3633. if(maxProfile.ChargingSchedule.Duration != -1)
  3634. {
  3635. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3636. 0:
  3637. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3638. }
  3639. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3640. {
  3641. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3642. {
  3643. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3644. 0:
  3645. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3646. if(idxPeriod > 0)
  3647. {
  3648. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3649. {
  3650. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3651. }
  3652. }
  3653. }
  3654. }
  3655. }
  3656. }
  3657. /*
  3658. DEBUG_INFO("MaxProfile after align.\n");
  3659. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3660. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3661. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3662. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3663. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3664. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3665. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3666. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3667. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3668. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3669. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3670. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3671. {
  3672. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3673. {
  3674. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3675. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3676. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3677. }
  3678. }
  3679. DEBUG_INFO("------------------------------------\n");*/
  3680. }
  3681. /*
  3682. * Merge to conposite schedule
  3683. */
  3684. //DEBUG_INFO("====================================\n");
  3685. // Find each profile period quantity
  3686. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3687. {
  3688. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3689. limitMax = idx+1;
  3690. }
  3691. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3692. {
  3693. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3694. limitDef = idx+1;
  3695. }
  3696. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3697. {
  3698. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3699. limitTx = idx+1;
  3700. }
  3701. // TxProfile found, composite schedule based on it
  3702. if(txProfile.ChargingProfileId != -1)
  3703. {
  3704. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3705. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3706. {
  3707. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3708. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3709. (txProfile.ChargingSchedule.Duration > 0))
  3710. {
  3711. if(maxProfile.ChargingProfileId != -1)
  3712. {
  3713. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3714. {
  3715. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3716. {
  3717. if((maxProfile.ChargingSchedule.Duration > 0))
  3718. {
  3719. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3720. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3721. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3722. }
  3723. else
  3724. {
  3725. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3726. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3727. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3728. }
  3729. }
  3730. if(idxMaxPeriod == (limitMax-1))
  3731. {
  3732. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3733. {
  3734. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3735. {
  3736. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3737. compositePeriodIdx++;
  3738. }
  3739. else
  3740. {
  3741. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3742. }
  3743. }
  3744. }
  3745. }
  3746. }
  3747. else
  3748. {
  3749. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3750. {
  3751. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3752. compositePeriodIdx++;
  3753. }
  3754. else
  3755. {
  3756. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3757. }
  3758. }
  3759. }
  3760. if(idxTxPeriod == (limitTx-1))
  3761. {
  3762. if(defaultTxProfile.ChargingProfileId != -1)
  3763. {
  3764. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3765. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3766. {
  3767. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3768. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3769. (defaultTxProfile.ChargingSchedule.Duration>0))
  3770. {
  3771. if(maxProfile.ChargingProfileId != -1)
  3772. {
  3773. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3774. {
  3775. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3776. {
  3777. if((maxProfile.ChargingSchedule.Duration > 0))
  3778. {
  3779. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3780. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3781. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3782. }
  3783. else
  3784. {
  3785. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3786. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3787. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3788. }
  3789. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3790. {
  3791. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3792. {
  3793. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3794. compositePeriodIdx++;
  3795. }
  3796. else
  3797. {
  3798. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3799. }
  3800. }
  3801. // Delete duplicate period
  3802. if(compositePeriodIdx > 1)
  3803. {
  3804. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3805. {
  3806. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3807. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3808. compositePeriodIdx -= 1;
  3809. }
  3810. }
  3811. }
  3812. else
  3813. {
  3814. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3815. {
  3816. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3817. compositePeriodIdx++;
  3818. }
  3819. else
  3820. {
  3821. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3822. }
  3823. break;
  3824. }
  3825. }
  3826. }
  3827. else
  3828. {
  3829. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3830. {
  3831. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3832. compositePeriodIdx++;
  3833. }
  3834. else
  3835. {
  3836. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3837. }
  3838. }
  3839. }
  3840. }
  3841. }
  3842. }
  3843. }
  3844. }
  3845. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3846. else if(defaultTxProfile.ChargingProfileId != -1)
  3847. {
  3848. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3849. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3850. {
  3851. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3852. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3853. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3854. {
  3855. if(maxProfile.ChargingProfileId != -1)
  3856. {
  3857. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3858. {
  3859. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3860. {
  3861. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3862. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3863. if((maxProfile.ChargingSchedule.Duration > 0))
  3864. {
  3865. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3866. }
  3867. else
  3868. {
  3869. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3870. }
  3871. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3872. {
  3873. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3874. {
  3875. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3876. compositePeriodIdx++;
  3877. }
  3878. else
  3879. {
  3880. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3881. }
  3882. }
  3883. // Delete duplicate period
  3884. if(compositePeriodIdx > 1)
  3885. {
  3886. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3887. {
  3888. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3889. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3890. compositePeriodIdx -= 1;
  3891. }
  3892. }
  3893. }
  3894. else
  3895. {
  3896. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3897. {
  3898. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3899. compositePeriodIdx++;
  3900. }
  3901. else
  3902. {
  3903. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3904. }
  3905. break;
  3906. }
  3907. }
  3908. }
  3909. else
  3910. {
  3911. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3912. {
  3913. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3914. compositePeriodIdx++;
  3915. }
  3916. else
  3917. {
  3918. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3919. }
  3920. }
  3921. }
  3922. }
  3923. }
  3924. // Fill other period by MaxProfile
  3925. if(maxProfile.ChargingProfileId != -1)
  3926. {
  3927. if(compositePeriodIdx==0)
  3928. {
  3929. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3930. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3931. {
  3932. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3933. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3934. (maxProfile.ChargingSchedule.Duration > 0))
  3935. {
  3936. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3937. {
  3938. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3939. compositePeriodIdx++;
  3940. }
  3941. else
  3942. {
  3943. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3944. }
  3945. }
  3946. }
  3947. }
  3948. else
  3949. {
  3950. int lastCompositePeriodIdx = compositePeriodIdx;
  3951. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3952. {
  3953. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3954. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3955. (maxProfile.ChargingSchedule.Duration > 0))
  3956. {
  3957. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3958. {
  3959. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3960. {
  3961. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3962. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3963. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3964. }
  3965. else
  3966. {
  3967. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3968. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3969. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3970. }
  3971. }
  3972. if(tmpPeriod.Limit != -1)
  3973. {
  3974. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3975. {
  3976. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3977. {
  3978. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3979. compositePeriodIdx++;
  3980. }
  3981. else
  3982. {
  3983. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3984. }
  3985. }
  3986. // Delete duplicate period
  3987. if(compositePeriodIdx > 1)
  3988. {
  3989. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3990. {
  3991. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3992. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3993. compositePeriodIdx -= 1;
  3994. }
  3995. }
  3996. }
  3997. }
  3998. }
  3999. }
  4000. }
  4001. compositeProfile.ChargingSchedule.Duration = durationReq;
  4002. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4003. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4004. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4005. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4006. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4007. {
  4008. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4009. {
  4010. compositeProfile.ChargingProfileId = 1;
  4011. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4012. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4013. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4014. }
  4015. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4016. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4017. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4018. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4019. }
  4020. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4021. if(line)
  4022. free(line);
  4023. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4024. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4025. }
  4026. //==========================================
  4027. // Init all share memory
  4028. //==========================================
  4029. int InitShareMemory()
  4030. {
  4031. int result = PASS;
  4032. int MeterSMId;
  4033. //creat ShmSysConfigAndInfo
  4034. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4035. {
  4036. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4037. result = FAIL;
  4038. }
  4039. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4040. {
  4041. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4042. result = FAIL;
  4043. }
  4044. else
  4045. {}
  4046. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4047. {
  4048. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4049. result = FAIL;
  4050. }
  4051. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4052. {
  4053. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4054. result = FAIL;
  4055. }
  4056. else
  4057. {}
  4058. //creat ShmPsuData
  4059. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4060. {
  4061. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4062. result = FAIL;
  4063. }
  4064. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4065. {
  4066. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4067. result = FAIL;
  4068. }
  4069. else
  4070. {}
  4071. //creat ShmOCPP16Data
  4072. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4073. {
  4074. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4075. result = FAIL;
  4076. }
  4077. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4078. {
  4079. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4080. result = FAIL;
  4081. }
  4082. else
  4083. {}
  4084. /****************************** For Initial Settings************************************************/
  4085. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4086. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4087. // allocate Configuration memory address
  4088. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4089. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4090. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4091. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4092. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4093. //offline MeterValue Interval
  4094. TempMeterValueInterval = 0;
  4095. return result;
  4096. }
  4097. int ProcessShareMemory()
  4098. {
  4099. int result = PASS;
  4100. if(InitShareMemory() == FAIL)
  4101. {
  4102. DEBUG_ERROR("InitShareMemory NG\n");
  4103. if(ShmStatusCodeData!=NULL)
  4104. {
  4105. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4106. }
  4107. result = FAIL;
  4108. }
  4109. // Model name parsing
  4110. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4111. {
  4112. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4113. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4114. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4115. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4116. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  4117. ) // 'D' means DC
  4118. {
  4119. // DO series
  4120. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4121. {
  4122. gunTotalNumber += 1;
  4123. gunType[gun_index] = GUN_TYPE_DO;
  4124. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4125. {
  4126. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4127. {
  4128. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4129. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4130. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4131. }
  4132. }
  4133. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4134. {
  4135. case Gun_Type_Chademo:
  4136. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4137. break;
  4138. case Gun_Type_CCS_2:
  4139. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4140. break;
  4141. case Gun_Type_GB:
  4142. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4143. break;
  4144. case Gun_Type_AC:
  4145. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4146. break;
  4147. default:
  4148. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4149. break;
  4150. }
  4151. }
  4152. }
  4153. else
  4154. {
  4155. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4156. {
  4157. gunTotalNumber += 1;
  4158. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4159. {
  4160. case Gun_Type_Chademo:
  4161. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4162. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4163. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4164. {
  4165. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4166. {
  4167. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4168. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4169. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4170. }
  4171. }
  4172. break;
  4173. case Gun_Type_CCS_2:
  4174. gunType[gun_index] = GUN_TYPE_CCS;
  4175. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4176. for (int index = 0; index < CCS_QUANTITY; index++)
  4177. {
  4178. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4179. {
  4180. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4181. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4182. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4183. }
  4184. }
  4185. break;
  4186. case Gun_Type_GB:
  4187. gunType[gun_index] = GUN_TYPE_GBT;
  4188. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4189. for (int index = 0; index < GB_QUANTITY; index++)
  4190. {
  4191. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4192. {
  4193. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4194. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4195. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4196. }
  4197. }
  4198. break;
  4199. case Gun_Type_AC:
  4200. gunType[gun_index] = GUN_TYPE_AC;
  4201. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4202. for (int index = 0; index < AC_QUANTITY; index++)
  4203. {
  4204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4205. {
  4206. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4207. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4208. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4209. }
  4210. }
  4211. break;
  4212. default:
  4213. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4214. break;
  4215. }
  4216. }
  4217. }
  4218. }
  4219. else
  4220. {
  4221. DEBUG_ERROR("Model name parsing fail.\n");
  4222. result = FAIL;
  4223. }
  4224. if(result != PASS)sleep(5);
  4225. return result;
  4226. }
  4227. void checkRemoteStart(uint8_t connectorIdInt)
  4228. {
  4229. uint8_t tempIndex;
  4230. int result = PASS;
  4231. char cmdBuf[512];
  4232. //check Transaction active
  4233. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4234. {
  4235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4236. {
  4237. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4238. }
  4239. else
  4240. {
  4241. tempIndex = connectorIdInt -1;
  4242. }
  4243. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4244. {
  4245. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4246. {
  4247. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4248. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4249. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4250. {
  4251. //Reserved
  4252. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4253. }
  4254. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4255. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4256. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4257. {
  4258. //Reserved
  4259. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4260. result = FAIL;
  4261. goto end;
  4262. }
  4263. else
  4264. {
  4265. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4266. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4267. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4268. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4269. {
  4270. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4271. result = FAIL;
  4272. goto end;
  4273. }
  4274. }//END FOR ELSE
  4275. }
  4276. }// END FOR CHAdeMO_QUANTITY
  4277. }
  4278. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4279. {
  4280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4281. {
  4282. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4283. }
  4284. else
  4285. {
  4286. tempIndex = connectorIdInt -1;
  4287. }
  4288. for (int index = 0; index < CCS_QUANTITY; index++)
  4289. {
  4290. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4291. {
  4292. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4293. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4294. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4295. {
  4296. //Reserved
  4297. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4298. }
  4299. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4300. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4301. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4302. {
  4303. //Reserved
  4304. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4305. result = FAIL;
  4306. goto end;
  4307. }
  4308. else
  4309. {
  4310. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4311. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4312. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4313. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4314. {
  4315. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4316. result = FAIL;
  4317. goto end;
  4318. }
  4319. }// END FOR ELSE
  4320. }
  4321. }// END FOR CCS_QUANTITY
  4322. }
  4323. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4324. {
  4325. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4326. {
  4327. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4328. }
  4329. else
  4330. {
  4331. tempIndex = connectorIdInt -1;
  4332. }
  4333. for (int index = 0; index < GB_QUANTITY; index++)
  4334. {
  4335. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4336. {
  4337. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4338. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4339. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4340. {
  4341. //Reserved
  4342. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4343. }
  4344. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4345. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4346. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4347. {
  4348. //Reserved
  4349. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4350. result = FAIL;
  4351. goto end;
  4352. }
  4353. else
  4354. {
  4355. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4356. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4357. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4358. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4359. {
  4360. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4361. result = FAIL;
  4362. goto end;
  4363. }
  4364. }// END FOR ELSE
  4365. }
  4366. } // END FOR GB_QUANTITY
  4367. }
  4368. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4369. {
  4370. tempIndex = connectorIdInt -1;
  4371. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4372. {
  4373. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4374. {
  4375. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4376. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4377. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4378. {
  4379. //Reserved
  4380. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4381. }
  4382. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4383. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4384. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4385. {
  4386. //Reserved
  4387. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4388. result = FAIL;
  4389. goto end;
  4390. }
  4391. else
  4392. {
  4393. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4394. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4395. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4396. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4397. {
  4398. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4399. result = FAIL;
  4400. goto end;
  4401. }
  4402. }// END FOR ELSE
  4403. }
  4404. } // END FOR GB_QUANTITY
  4405. }
  4406. else
  4407. {
  4408. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4409. {
  4410. tempIndex = 2;
  4411. }
  4412. else
  4413. {
  4414. tempIndex = connectorIdInt -1;
  4415. }
  4416. for (int index = 0; index < AC_QUANTITY; index++)
  4417. {
  4418. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4419. {
  4420. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4421. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4422. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4423. {
  4424. //Reserved
  4425. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4426. }
  4427. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4428. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4429. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4430. {
  4431. //Reserved
  4432. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4433. result = FAIL;
  4434. goto end;
  4435. }
  4436. else
  4437. {
  4438. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4439. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4440. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4441. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4442. {
  4443. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4444. result = FAIL;
  4445. goto end;
  4446. }
  4447. }//END FOR ELSE
  4448. }
  4449. }// END FOR AC_QUANTITY
  4450. }
  4451. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4452. {
  4453. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4454. {
  4455. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4456. {
  4457. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4458. system(cmdBuf);
  4459. }
  4460. }
  4461. else
  4462. {
  4463. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4464. result = FAIL;
  4465. }
  4466. }
  4467. end:
  4468. if(result == PASS)
  4469. {
  4470. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4471. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4472. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4473. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4474. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4475. }
  4476. }
  4477. void CheckSystemValue(void)
  4478. {
  4479. char filenmae[100]={0};
  4480. char str[100]={0};
  4481. int tempIndex = 0;
  4482. //===============================
  4483. // send Heartbeat
  4484. //===============================
  4485. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4486. {
  4487. //parameter for test
  4488. sendHeartbeatRequest(0);
  4489. //===========================
  4490. // Reset Waiting Time
  4491. //===========================
  4492. HeartBeatWithNOResponse += 1;
  4493. }
  4494. //===============================
  4495. // Credit deduct report
  4496. //===============================
  4497. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4498. {
  4499. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4500. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4501. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4502. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4503. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4504. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4505. }
  4506. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4507. {
  4508. OCPP_query_deduct_info();
  4509. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4510. }
  4511. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4512. {
  4513. // ClockAlign MeterValue
  4514. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4515. {
  4516. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4517. {
  4518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4519. {
  4520. tempIndex = ((gun_index==2) ? 1: 0);
  4521. }
  4522. else
  4523. {
  4524. tempIndex = gun_index;
  4525. }
  4526. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4527. {
  4528. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4529. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4530. {
  4531. reqClockAlignMeter[gun_index] = 1;
  4532. }
  4533. }// End for CHAdeMO
  4534. }
  4535. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4536. {
  4537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4538. {
  4539. tempIndex = ((gun_index==2) ? 1: 0);
  4540. }
  4541. else
  4542. {
  4543. tempIndex = gun_index;
  4544. }
  4545. for (int index = 0; index < CCS_QUANTITY; index++)
  4546. {
  4547. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4548. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4549. {
  4550. reqClockAlignMeter[gun_index] = 1;
  4551. }
  4552. } // End for CCS
  4553. }
  4554. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4555. {
  4556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4557. {
  4558. tempIndex = ((gun_index==2) ? 1: 0);
  4559. }
  4560. else
  4561. {
  4562. tempIndex = gun_index;
  4563. }
  4564. for (int index = 0; index < GB_QUANTITY; index++)
  4565. {
  4566. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4567. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4568. {
  4569. reqClockAlignMeter[gun_index] = 1;
  4570. }
  4571. }// End for GB
  4572. }
  4573. else if(gunType[gun_index] == GUN_TYPE_DO)
  4574. {
  4575. tempIndex = gun_index;
  4576. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4577. {
  4578. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4579. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4580. {
  4581. reqClockAlignMeter[gun_index] = 1;
  4582. }
  4583. }
  4584. }
  4585. else
  4586. {
  4587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4588. {
  4589. tempIndex = 2;
  4590. }
  4591. else
  4592. {
  4593. tempIndex = gun_index;
  4594. }
  4595. for (int index = 0; index < AC_QUANTITY; index++)
  4596. {
  4597. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4598. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4599. {
  4600. reqClockAlignMeter[gun_index] = 1;
  4601. }
  4602. }//End for AC
  4603. }
  4604. }
  4605. }
  4606. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4607. {
  4608. //==========================================
  4609. // Check remote start without connector id
  4610. //==========================================
  4611. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4612. {
  4613. int connectorIdInt = -1;
  4614. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4615. {
  4616. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4617. {
  4618. connectorIdInt = (gun_index+1);
  4619. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4620. checkRemoteStart(connectorIdInt);
  4621. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4622. break;
  4623. }
  4624. }
  4625. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4626. {
  4627. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4628. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4629. }
  4630. }
  4631. //==========================================
  4632. // csu trigger DataTransferReq
  4633. //==========================================
  4634. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4635. {
  4636. sendDataTransferRequest(gun_index);
  4637. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4638. }
  4639. //==========================================
  4640. // CSU Trigger Authorize Request
  4641. //==========================================
  4642. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4643. {
  4644. sendAuthorizeRequest(0);
  4645. authorizeRetryTimes = authorizeRetryTimes + 1;
  4646. if(authorizeRetryTimes < 3)
  4647. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4648. }
  4649. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4650. {
  4651. authorizeRetryTimes = 0;
  4652. SetOcppConnStatus(FALSE);
  4653. server_sign = FALSE;
  4654. }
  4655. 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))
  4656. {
  4657. sendAuthorizeRequest(0);
  4658. }
  4659. //==========================================
  4660. // Charger start transaction
  4661. //==========================================
  4662. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4663. {
  4664. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4665. sendStartTransactionRequest(gun_index);
  4666. refreshStartTimer(&clientTime.StartTransaction);
  4667. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4668. storeTempStopTransaction(gun_index);
  4669. }
  4670. //==========================================
  4671. // Charger stop transaction
  4672. //==========================================
  4673. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4674. {
  4675. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4676. sendStopTransactionRequest(gun_index);
  4677. OCPP_updatePeriodEnergy(gun_index);
  4678. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4679. refreshStartTimer(&clientTime.StopTransaction);
  4680. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4681. }
  4682. //==========================================
  4683. // Charger OCMF message
  4684. //==========================================
  4685. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  4686. {
  4687. sendOcmfByDataTransferRequest(gun_index);
  4688. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  4689. }
  4690. //==========================================
  4691. // Charger status report
  4692. //==========================================
  4693. //--- Check Mode Change ---//
  4694. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4695. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4696. {
  4697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4698. {
  4699. tempIndex = ((gun_index==2) ? 1: 0);
  4700. }
  4701. else
  4702. {
  4703. tempIndex = gun_index;
  4704. }
  4705. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4706. {
  4707. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4708. {
  4709. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4710. {
  4711. // Sent unplug message for California pricing logic
  4712. 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])
  4713. {
  4714. uint8_t ts[36];
  4715. getNowDatetime(ts);
  4716. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4717. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4718. if(strcmp((char*)dmsVersion, "2.0")==0)
  4719. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4720. else
  4721. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4722. sendUnplugByDataTransferRequest(gun_index);
  4723. interLock.isSentUnplug[gun_index] = 1;
  4724. }
  4725. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4726. {
  4727. interLock.isSentUnplug[gun_index] = 0;
  4728. }
  4729. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4730. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4731. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4732. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4733. {
  4734. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4735. if((access(filenmae,F_OK))!=-1)
  4736. {
  4737. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4738. sprintf(str,"rm -f %s",filenmae);
  4739. system(str);
  4740. }
  4741. }
  4742. }
  4743. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4744. #if 1 // for TempStopTransaction
  4745. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4746. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4747. {
  4748. checkTempStopTransaction(gun_index);
  4749. }
  4750. #endif
  4751. }
  4752. }
  4753. }
  4754. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4755. {
  4756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4757. {
  4758. tempIndex = ((gun_index==2) ? 1: 0);
  4759. }
  4760. else
  4761. {
  4762. tempIndex = gun_index;
  4763. }
  4764. for (int index = 0; index < CCS_QUANTITY; index++)
  4765. {
  4766. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4767. {
  4768. 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]*/ )
  4769. {
  4770. // Sent unplug message for California pricing logic
  4771. 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])
  4772. {
  4773. uint8_t ts[36];
  4774. getNowDatetime(ts);
  4775. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4776. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4777. if(strcmp((char*)dmsVersion, "2.0")==0)
  4778. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4779. else
  4780. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4781. sendUnplugByDataTransferRequest(gun_index);
  4782. interLock.isSentUnplug[gun_index] = 1;
  4783. }
  4784. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4785. {
  4786. interLock.isSentUnplug[gun_index] = 0;
  4787. }
  4788. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4789. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4790. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4791. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4792. {
  4793. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4794. if((access(filenmae,F_OK))!=-1)
  4795. {
  4796. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4797. sprintf(str,"rm -f %s",filenmae);
  4798. system(str);
  4799. }
  4800. }
  4801. }
  4802. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4803. #if 1 // for TempStopTransaction
  4804. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4805. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4806. {
  4807. checkTempStopTransaction(gun_index);
  4808. }
  4809. #endif
  4810. }
  4811. }
  4812. }
  4813. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4814. {
  4815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4816. {
  4817. tempIndex = ((gun_index==2) ? 1: 0);
  4818. }
  4819. else
  4820. {
  4821. tempIndex = gun_index;
  4822. }
  4823. for (int index = 0; index < GB_QUANTITY; index++)
  4824. {
  4825. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4826. {
  4827. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4828. {
  4829. // Sent unplug message for California pricing logic
  4830. 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])
  4831. {
  4832. uint8_t ts[36];
  4833. getNowDatetime(ts);
  4834. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4835. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4836. if(strcmp((char*)dmsVersion, "2.0")==0)
  4837. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4838. else
  4839. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4840. sendUnplugByDataTransferRequest(gun_index);
  4841. interLock.isSentUnplug[gun_index] = 1;
  4842. }
  4843. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4844. {
  4845. interLock.isSentUnplug[gun_index] = 0;
  4846. }
  4847. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4848. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4849. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4850. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4851. {
  4852. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4853. if((access(filenmae,F_OK))!=-1)
  4854. {
  4855. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4856. sprintf(str,"rm -f %s",filenmae);
  4857. system(str);
  4858. }
  4859. }
  4860. }
  4861. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4862. #if 1 // for TempStopTransaction
  4863. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4864. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4865. {
  4866. checkTempStopTransaction(gun_index);
  4867. }
  4868. #endif
  4869. }
  4870. }
  4871. }
  4872. else if(gunType[gun_index] == GUN_TYPE_DO)
  4873. {
  4874. tempIndex = gun_index;
  4875. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4876. {
  4877. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4878. {
  4879. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4880. {
  4881. // Sent unplug message for California pricing logic
  4882. 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])
  4883. {
  4884. uint8_t ts[36];
  4885. getNowDatetime(ts);
  4886. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4887. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4888. if(strcmp((char*)dmsVersion, "2.0")==0)
  4889. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4890. else
  4891. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4892. sendUnplugByDataTransferRequest(gun_index);
  4893. interLock.isSentUnplug[gun_index] = 1;
  4894. }
  4895. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4896. {
  4897. interLock.isSentUnplug[gun_index] = 0;
  4898. }
  4899. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4900. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4901. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4902. 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
  4903. {
  4904. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4905. if((access(filenmae,F_OK))!=-1)
  4906. {
  4907. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4908. sprintf(str,"rm -f %s",filenmae);
  4909. system(str);
  4910. }
  4911. }
  4912. }
  4913. 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);
  4914. #if 1 // for TempStopTransaction
  4915. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4916. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4917. {
  4918. checkTempStopTransaction(gun_index);
  4919. }
  4920. #endif
  4921. }
  4922. }
  4923. }
  4924. else
  4925. {
  4926. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4927. {
  4928. tempIndex = 2;
  4929. }
  4930. else
  4931. {
  4932. tempIndex = gun_index;
  4933. }
  4934. for (int index = 0; index < AC_QUANTITY; index++)
  4935. {
  4936. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4937. {
  4938. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4939. {
  4940. // Sent unplug message for California pricing logic
  4941. 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])
  4942. {
  4943. uint8_t ts[36];
  4944. getNowDatetime(ts);
  4945. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4946. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4947. if(strcmp((char*)dmsVersion, "2.0")==0)
  4948. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4949. else
  4950. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4951. sendUnplugByDataTransferRequest(gun_index);
  4952. interLock.isSentUnplug[gun_index] = 1;
  4953. }
  4954. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4955. {
  4956. interLock.isSentUnplug[gun_index] = 0;
  4957. }
  4958. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4959. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4960. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4961. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4962. {
  4963. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4964. if((access(filenmae,F_OK))!=-1)
  4965. {
  4966. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4967. sprintf(str,"rm -f %s",filenmae);
  4968. system(str);
  4969. }
  4970. }
  4971. }
  4972. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4973. #if 1 // for TempStopTransaction
  4974. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4975. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4976. {
  4977. checkTempStopTransaction(gun_index);
  4978. }
  4979. #endif
  4980. }
  4981. }// END
  4982. }
  4983. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  4984. (
  4985. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4986. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4987. )
  4988. )
  4989. {
  4990. sendStatusNotificationRequest(gun_index);
  4991. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4992. }
  4993. //==============================================
  4994. // TCCI reader status report
  4995. //==============================================
  4996. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4997. {
  4998. reportReaderStatus(gun_index);
  4999. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5000. }
  5001. //==============================================
  5002. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5003. //==============================================
  5004. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5005. ((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))))
  5006. {
  5007. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5008. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5009. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5010. }
  5011. //==============================================
  5012. // Meter report
  5013. //==============================================
  5014. // Trigger MeterValue
  5015. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5016. {
  5017. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5018. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5019. }
  5020. // Clock-aligned Meter value
  5021. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5022. {
  5023. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5024. reqClockAlignMeter[gun_index] = 0;
  5025. }
  5026. // Sample period MeterValue
  5027. 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))))
  5028. {
  5029. //check Transaction active
  5030. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5031. {
  5032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5033. {
  5034. tempIndex = ((gun_index==2) ? 1: 0);
  5035. }
  5036. else
  5037. {
  5038. tempIndex = gun_index;
  5039. }
  5040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5041. {
  5042. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5043. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5044. {
  5045. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5046. {
  5047. reqSampleMeter[gun_index] = 1;
  5048. }
  5049. }
  5050. }// End for CHAdeMO
  5051. }
  5052. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5053. {
  5054. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5055. {
  5056. tempIndex = ((gun_index==2) ? 1: 0);
  5057. }
  5058. else
  5059. {
  5060. tempIndex = gun_index;
  5061. }
  5062. for (int index = 0; index < CCS_QUANTITY; index++)
  5063. {
  5064. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5065. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5066. {
  5067. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5068. {
  5069. reqSampleMeter[gun_index] = 1;
  5070. }
  5071. }
  5072. } // End for CCS
  5073. }
  5074. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5075. {
  5076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5077. {
  5078. tempIndex = ((gun_index==2) ? 1: 0);
  5079. }
  5080. else
  5081. {
  5082. tempIndex = gun_index;
  5083. }
  5084. for (int index = 0; index < GB_QUANTITY; index++)
  5085. {
  5086. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5087. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5088. {
  5089. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5090. {
  5091. reqSampleMeter[gun_index] = 1;
  5092. }
  5093. }
  5094. }// End for GB
  5095. }
  5096. else if(gunType[gun_index] == GUN_TYPE_DO)
  5097. {
  5098. tempIndex = gun_index;
  5099. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5100. {
  5101. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5102. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5103. {
  5104. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5105. {
  5106. reqSampleMeter[gun_index] = 1;
  5107. }
  5108. }
  5109. }
  5110. }
  5111. else
  5112. {
  5113. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5114. {
  5115. tempIndex = 2;
  5116. }
  5117. else
  5118. {
  5119. tempIndex = gun_index;
  5120. }
  5121. for (int index = 0; index < AC_QUANTITY; index++)
  5122. {
  5123. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5124. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5125. {
  5126. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5127. {
  5128. reqSampleMeter[gun_index] = 1;
  5129. }
  5130. }
  5131. }//End for AC
  5132. }
  5133. if(reqSampleMeter[gun_index] == 1)
  5134. {
  5135. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5136. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5137. storeTempStopTransaction(gun_index);
  5138. reqSampleMeter[gun_index] = 0;
  5139. }
  5140. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5141. }
  5142. //==============================================
  5143. // Check Connector reserved
  5144. //==============================================
  5145. //===============================
  5146. // Check if Reserve is expired
  5147. //===============================
  5148. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5149. {
  5150. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5151. {
  5152. DEBUG_INFO("reserve expired.\n");
  5153. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5154. }
  5155. }//END OF Check if Reserve is expired
  5156. //==========================================
  5157. // csu trigger FirmwareStatusNotificationReq
  5158. //==========================================
  5159. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5160. {
  5161. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5162. }
  5163. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5164. {
  5165. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5166. }
  5167. //==========================================
  5168. // csu trigger DiagnosticsStatusNotificationReq
  5169. //==========================================
  5170. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5171. {
  5172. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5173. }
  5174. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5175. {
  5176. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5177. }
  5178. //==========================================
  5179. // csu trigger CancelReservationConf
  5180. //==========================================
  5181. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5182. {
  5183. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5184. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5185. }
  5186. //==========================================
  5187. // csu trigger ChangeAvailabilityConf
  5188. //==========================================
  5189. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5190. {
  5191. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5192. }
  5193. //==========================================
  5194. // csu trigger UnlockConnectorConf
  5195. //==========================================
  5196. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5197. {
  5198. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5199. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5200. }
  5201. //==========================================
  5202. // csu trigger ReserveNowConf
  5203. //==========================================
  5204. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5205. {
  5206. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5207. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5208. }
  5209. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5210. {
  5211. sendSignCertificateRequest();
  5212. }
  5213. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5214. {
  5215. sendSecurityEventNotificationRequest();
  5216. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5217. }
  5218. // Support 15118
  5219. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5220. {
  5221. json_object *data = json_object_new_object();
  5222. // Read csr file content
  5223. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5224. FILE *fp=fopen(CSR_V2G,"r");
  5225. char *line = NULL;
  5226. size_t len = 0;
  5227. while(getline(&line, &len, fp) != -1)
  5228. {
  5229. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5230. {
  5231. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5232. }
  5233. }
  5234. fclose(fp);
  5235. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5236. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5237. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5238. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5239. json_object_put(data);
  5240. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5241. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5242. }
  5243. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5244. {
  5245. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5246. int parseCertResult = FAIL;
  5247. json_object *data = json_object_new_object();
  5248. json_object *idToken = json_object_new_object();
  5249. json_object *iso15118CertificateHashData = json_object_new_array();
  5250. // Read CERTIFICATE_PnCAuth file content
  5251. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5252. {
  5253. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5254. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5255. char *line = NULL;
  5256. size_t len = 0;
  5257. while(getline(&line, &len, fp) != -1)
  5258. {
  5259. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5260. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5261. }
  5262. fclose(fp);
  5263. }
  5264. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5265. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5266. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5267. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5268. json_object_object_add(data, "idToken", idToken);
  5269. char parseData[512] = {0};
  5270. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5271. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5272. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5273. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5274. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5275. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5276. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5277. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5278. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5279. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5280. for(int idx=0; idx < 4; idx++)
  5281. {
  5282. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5283. {
  5284. json_object *OCSPRequestDataType = json_object_new_object();
  5285. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5286. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5287. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5288. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5289. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5290. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5291. parseCertResult = PASS;
  5292. }
  5293. }
  5294. if(parseCertResult == PASS)
  5295. {
  5296. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5297. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5298. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5299. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5300. json_object_put(data);
  5301. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5302. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5303. }
  5304. else
  5305. {
  5306. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5307. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5308. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5309. }
  5310. }
  5311. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5312. {
  5313. json_object *data = json_object_new_object();
  5314. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5315. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5316. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5317. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5318. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5319. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5320. json_object_put(data);
  5321. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5322. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5323. }
  5324. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5325. {
  5326. json_object *data = json_object_new_object();
  5327. json_object *OCSPRequestDataType = json_object_new_object();
  5328. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5329. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5330. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5331. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5332. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5333. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5334. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5335. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5336. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5337. json_object_put(data);
  5338. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5339. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5340. }
  5341. }
  5342. }
  5343. //==========================================
  5344. // send request routine
  5345. //==========================================
  5346. int sendAuthorizeRequest(int gun_index)
  5347. {
  5348. mtrace();
  5349. int result = FAIL;
  5350. char message[100]={0};
  5351. char guid[37];
  5352. char tempdata[65]={0};
  5353. DEBUG_INFO("sendAuthorizeRequest...\n");
  5354. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5355. //Local Authorize
  5356. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5357. {
  5358. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5359. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5360. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5361. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5362. result = PASS;
  5363. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5364. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5365. authorizeRetryTimes = 0;
  5366. return result;
  5367. }
  5368. 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))||
  5369. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5370. {
  5371. // Query from cache
  5372. DEBUG_INFO("Authorize from cache.\n");
  5373. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5374. // Query from list
  5375. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5376. {
  5377. DEBUG_INFO("Authorize from list.\n");
  5378. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5379. }
  5380. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5381. {
  5382. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5383. {
  5384. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5385. }
  5386. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5387. {
  5388. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5389. }
  5390. if(!GetOcppConnStatus())
  5391. {
  5392. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5393. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5394. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5395. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5396. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5397. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5398. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5399. authorizeRetryTimes = 0;
  5400. return result;
  5401. }
  5402. }
  5403. else
  5404. {
  5405. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5406. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5407. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5408. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5409. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5410. else
  5411. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5412. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5413. result = PASS;
  5414. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5415. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5416. authorizeRetryTimes = 0;
  5417. return result;
  5418. }
  5419. }
  5420. //initialize struct Authorize
  5421. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5422. //get data from shared memory
  5423. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5424. random_uuid(guid);
  5425. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5426. LWS_Send(message);
  5427. sprintf(tempdata, "Authorize,%d", gun_index);
  5428. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5429. {
  5430. result = PASS;
  5431. DEBUG_INFO("Authorize mapItem pass\n");
  5432. }
  5433. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5434. return result;
  5435. }
  5436. int sendBootNotificationRequest(void)
  5437. {
  5438. mtrace();
  5439. int result = FAIL;
  5440. char message[500]={0}, payload[700]={0};
  5441. char guid[37]={0};
  5442. char tempdata[65]={0};
  5443. // Fill BootNotification fields
  5444. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5445. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5446. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5447. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5448. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5449. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5450. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5451. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5452. ShmOCPP16Data->ChargeBoxId
  5453. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5454. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5455. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5456. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5457. ,ShmOCPP16Data->BootNotification.CpIccid
  5458. ,ShmOCPP16Data->BootNotification.CpImsi);
  5459. random_uuid(guid);
  5460. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5461. LWS_Send(message);
  5462. sprintf(tempdata, "BootNotification,0");
  5463. 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*/)
  5464. {
  5465. result = PASS;
  5466. }
  5467. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5468. strcpy(queuedata,message);
  5469. return result;
  5470. }
  5471. int sendDataTransferRequest(int gun_index)
  5472. {
  5473. mtrace();
  5474. char message[10240]={0};
  5475. char guid[37]={0};
  5476. char tempdata[65]={0};
  5477. int result = FAIL;
  5478. json_object *DataTransfer = json_object_new_object();
  5479. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5480. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5481. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5482. random_uuid(guid);
  5483. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5484. guid,
  5485. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5486. json_object_put(DataTransfer);
  5487. LWS_Send(message);
  5488. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5489. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5490. {
  5491. result = PASS;
  5492. DEBUG_INFO("DataTransfer mapItem pass\n");
  5493. }
  5494. return result;
  5495. }
  5496. int sendUnplugByDataTransferRequest(int gun_index)
  5497. {
  5498. mtrace();
  5499. char message[10752]={0};
  5500. char guid[37]={0};
  5501. char tempdata[65]={0};
  5502. int result = FAIL;
  5503. random_uuid(guid);
  5504. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5505. (gun_index+1),
  5506. MESSAGE_TYPE_CALL,
  5507. guid,
  5508. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5509. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5510. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5511. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5512. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5513. {
  5514. result = PASS;
  5515. DEBUG_INFO("DataTransfer mapItem pass\n");
  5516. }
  5517. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5518. return result;
  5519. }
  5520. int sendOcmfByDataTransferRequest(int gun_index)
  5521. {
  5522. mtrace();
  5523. json_object *DataTransfer = json_object_new_object();
  5524. json_object *data = json_object_new_object();
  5525. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5526. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5527. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5528. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5529. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5530. json_object_object_add(DataTransfer, "data", data);
  5531. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5532. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5533. char message[3000]={0};
  5534. char guid[37]={0};
  5535. char tempdata[65]={0};
  5536. int result = FAIL;
  5537. random_uuid(guid);
  5538. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5539. (gun_index+1),
  5540. MESSAGE_TYPE_CALL,
  5541. guid,
  5542. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5543. json_object_put(DataTransfer);
  5544. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5545. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5546. {
  5547. result = PASS;
  5548. DEBUG_INFO("DataTransfer mapItem pass\n");
  5549. }
  5550. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5551. return result;
  5552. }
  5553. int sendDiagnosticsStatusNotificationRequest(char *status)
  5554. {
  5555. mtrace();
  5556. int result = FAIL;
  5557. char message[110]={0};
  5558. char guid[37]={0};
  5559. char tempdata[65]={0};
  5560. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5561. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5562. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5563. random_uuid(guid);
  5564. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5565. LWS_SendNow(message);
  5566. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5567. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5568. {
  5569. result = PASS;
  5570. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5571. }
  5572. //#ifdef SystemLogMessage
  5573. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5574. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5575. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5576. //#endif
  5577. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5578. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5579. //record status
  5580. if(strcmp(status,"Idle")==0)
  5581. {
  5582. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5583. }
  5584. else if(strcmp(status,"Uploaded")==0)
  5585. {
  5586. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5587. }
  5588. else if(strcmp(status,"UploadFailed")==0)
  5589. {
  5590. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5591. }
  5592. else if(strcmp(status,"Uploading")==0)
  5593. {
  5594. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5595. }
  5596. return result;
  5597. }
  5598. int sendFirmwareStatusNotificationRequest(char *status)
  5599. {
  5600. mtrace();
  5601. int result = FAIL;
  5602. char message[110]={0};
  5603. char guid[37]={0};
  5604. char tempdata[65]={0};
  5605. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5606. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5607. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5608. random_uuid(guid);
  5609. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5610. LWS_SendNow(message);
  5611. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5612. 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*/)
  5613. {
  5614. result = PASS;
  5615. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5616. }
  5617. //#ifdef SystemLogMessage
  5618. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5619. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5620. //#endif
  5621. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5622. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5623. //record status
  5624. if(strcmp(status,"Downloaded")==0)
  5625. {
  5626. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5627. }
  5628. else if(strcmp(status,"DownloadFailed")==0)
  5629. {
  5630. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5631. }
  5632. else if(strcmp(status,"Downloading")==0)
  5633. {
  5634. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5635. }
  5636. else if(strcmp(status,"Idle")==0)
  5637. {
  5638. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5639. }
  5640. else if(strcmp(status,"InstallationFailed")==0)
  5641. {
  5642. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5643. }
  5644. else if(strcmp(status,"Installing")==0)
  5645. {
  5646. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5647. }
  5648. else if(strcmp(status,"Installed")==0)
  5649. {
  5650. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5651. }
  5652. return result;
  5653. }
  5654. int sendHeartbeatRequest(int gun_index)
  5655. {
  5656. mtrace();
  5657. int result = FAIL;
  5658. char message[80]={0};
  5659. char guid[37]={0};
  5660. char tempdata[65]={0};
  5661. random_uuid(guid);
  5662. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5663. , MESSAGE_TYPE_CALL
  5664. , guid );
  5665. LWS_Send(message);
  5666. sprintf(tempdata, "Heartbeat,%d", 0);
  5667. 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*/)
  5668. {
  5669. result = PASS;
  5670. }
  5671. return result;
  5672. }
  5673. int sendStartTransactionRequest(int gun_index)
  5674. {
  5675. mtrace();
  5676. int result = FAIL;
  5677. char message[250]={0};
  5678. char guid[37]={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. DEBUG_INFO("sendStartTransactionRequest...\n");
  5685. gettimeofday(&tmnow, NULL);
  5686. time_t t;
  5687. t = time(NULL);
  5688. /*UTC time and date*/
  5689. tm = gmtime(&t);
  5690. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5691. #if 0 // remove temporally
  5692. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5693. strcat(buf,".");
  5694. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5695. strcat(buf,usec_buf);
  5696. #endif
  5697. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5698. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5699. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5700. // clear StartTransaction Response
  5701. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5702. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5703. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5704. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5705. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5706. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5707. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5708. {
  5709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5710. {
  5711. tempIndex = ((gun_index==2) ? 1: 0);
  5712. }
  5713. else
  5714. {
  5715. tempIndex = gun_index;
  5716. }
  5717. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5718. {
  5719. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5720. {
  5721. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5722. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5723. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5724. }
  5725. }
  5726. }
  5727. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5728. {
  5729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5730. {
  5731. tempIndex = ((gun_index==2) ? 1: 0);
  5732. }
  5733. else
  5734. {
  5735. tempIndex = gun_index;
  5736. }
  5737. for (int index = 0; index < CCS_QUANTITY; index++)
  5738. {
  5739. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5740. {
  5741. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5742. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5743. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5744. }
  5745. }
  5746. }
  5747. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5748. {
  5749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5750. {
  5751. tempIndex = ((gun_index==2) ? 1: 0);
  5752. }
  5753. else
  5754. {
  5755. tempIndex = gun_index;
  5756. }
  5757. for (int index = 0; index < GB_QUANTITY; index++)
  5758. {
  5759. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5760. {
  5761. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5762. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5763. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5764. }
  5765. }
  5766. }
  5767. else if(gunType[gun_index] == GUN_TYPE_DO)
  5768. {
  5769. tempIndex = gun_index;
  5770. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5771. {
  5772. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5773. {
  5774. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5775. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5776. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5777. }
  5778. }
  5779. }
  5780. else
  5781. {
  5782. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5783. {
  5784. tempIndex = 2;
  5785. }
  5786. else
  5787. {
  5788. tempIndex = gun_index;
  5789. }
  5790. for (int index = 0; index < AC_QUANTITY; index++)
  5791. {
  5792. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5793. {
  5794. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5795. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5796. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5797. }
  5798. }
  5799. }
  5800. random_uuid(guid);
  5801. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5802. {
  5803. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5804. , gun_index +1
  5805. , MESSAGE_TYPE_CALL
  5806. , guid
  5807. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5808. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5809. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5810. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5811. }
  5812. else
  5813. {
  5814. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5815. , gun_index +1
  5816. , MESSAGE_TYPE_CALL
  5817. , guid
  5818. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5819. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5820. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5821. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5822. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5823. }
  5824. #if 1
  5825. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5826. 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*/)
  5827. {
  5828. result = PASS;
  5829. }
  5830. #endif
  5831. strcpy(queuedata, message);
  5832. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5833. OCPP_insert_transaction_msg(YES, queuedata);
  5834. return result;
  5835. }
  5836. int sendStatusNotificationRequest(int gun_index)
  5837. {
  5838. mtrace();
  5839. int result = FAIL;
  5840. char message[600]={0};
  5841. char guid[37];
  5842. int currentStatus = 0;
  5843. struct timeval tmnow;
  5844. struct tm *tm;
  5845. char buf[28];//, usec_buf[6];
  5846. char tempdata[65]={0};
  5847. int tempIndex = 0;
  5848. uint8_t isStateChanged = TRUE;
  5849. uint8_t isContentIllegal = TRUE;
  5850. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5851. gettimeofday(&tmnow, NULL);
  5852. time_t t;
  5853. t = time(NULL);
  5854. /*UTC time and date*/
  5855. tm = gmtime(&t);
  5856. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5857. #if 0 // remove temporally
  5858. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5859. strcat(buf,".");
  5860. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5861. strcat(buf,usec_buf);
  5862. #endif
  5863. //printf("%s",buf);
  5864. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5865. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5866. // it's option
  5867. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5868. /*
  5869. enum _SYSTEM_STATUS
  5870. {
  5871. S_BOOTING = 0,
  5872. S_IDLE, = 1
  5873. S_AUTHORIZING, =2
  5874. S_REASSIGN_CHECK, =3
  5875. S_REASSIGN, =4
  5876. S_PRECHARGE, =5
  5877. S_PREPARING_FOR_EV, =6
  5878. S_PREPARING_FOR_EVSE, =7
  5879. S_CHARGING, =8
  5880. S_TERMINATING, =9
  5881. S_COMPLETE, =10
  5882. S_ALARM, =11
  5883. S_FAULT =12
  5884. }
  5885. */
  5886. //check Transaction active
  5887. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5888. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5889. {
  5890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5891. {
  5892. tempIndex = ((gun_index==2) ? 1: 0);
  5893. }
  5894. else
  5895. {
  5896. tempIndex = gun_index;
  5897. }
  5898. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5899. {
  5900. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5901. {
  5902. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5903. {
  5904. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5905. {
  5906. currentStatus = Preparing; //OCPP Status: Preparing
  5907. }
  5908. else
  5909. {
  5910. currentStatus = Available; //OCPP Status: Available
  5911. }
  5912. }
  5913. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5914. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5915. ) //S_PRECHARGE
  5916. {
  5917. currentStatus = Preparing; //OCPP Status: Preparing
  5918. }
  5919. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5920. {
  5921. currentStatus = Charging; //OCPP Status: Charging
  5922. }
  5923. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5924. {
  5925. currentStatus = Finishing; //OCPP Status: Finishing
  5926. }
  5927. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5928. {
  5929. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5930. }
  5931. 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
  5932. {
  5933. currentStatus = Unavailable; //OCPP Status: Unavailable
  5934. }
  5935. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5936. {
  5937. currentStatus = Faulted; //OCPP Status: Faulted
  5938. }
  5939. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5940. {
  5941. currentStatus = Reserved; //OCPP Status: Reserved
  5942. }
  5943. } //end of the same index
  5944. }//end of for CHAdeMO_QUANTITY
  5945. }
  5946. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5947. {
  5948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5949. {
  5950. tempIndex = ((gun_index==2) ? 1: 0);
  5951. }
  5952. else
  5953. {
  5954. tempIndex = gun_index;
  5955. }
  5956. for (int index = 0; index < CCS_QUANTITY; index++)
  5957. {
  5958. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5959. {
  5960. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5961. {
  5962. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5963. {
  5964. currentStatus = Preparing; //OCPP Status: Preparing
  5965. }
  5966. else
  5967. {
  5968. currentStatus = Available; //OCPP Status: Available
  5969. }
  5970. }
  5971. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5972. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5973. ) //S_PRECHARGE
  5974. {
  5975. currentStatus = Preparing; //OCPP Status: Preparing
  5976. }
  5977. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5978. {
  5979. currentStatus = Charging; //OCPP Status: Charging
  5980. }
  5981. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5982. {
  5983. currentStatus = Finishing; //OCPP Status: Finishing
  5984. }
  5985. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5986. {
  5987. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5988. }
  5989. 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
  5990. {
  5991. currentStatus = Unavailable; //OCPP Status : Unavailable
  5992. }
  5993. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5994. {
  5995. currentStatus = Faulted; //OCPP Status: Faulted
  5996. }
  5997. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5998. {
  5999. currentStatus = Reserved; //OCPP Status: Reserved
  6000. }
  6001. } //end of the same index
  6002. } // end of for CCS_QUANTITY
  6003. }
  6004. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6005. {
  6006. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6007. {
  6008. tempIndex = ((gun_index==2) ? 1: 0);
  6009. }
  6010. else
  6011. {
  6012. tempIndex = gun_index;
  6013. }
  6014. for (int index = 0; index < GB_QUANTITY; index++)
  6015. {
  6016. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6017. {
  6018. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6019. {
  6020. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6021. {
  6022. currentStatus = Preparing; //OCPP Status: Preparing
  6023. }
  6024. else
  6025. {
  6026. currentStatus = Available; //OCPP Status: Available
  6027. }
  6028. }
  6029. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6030. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6031. ) //S_PRECHARGE
  6032. {
  6033. currentStatus = Preparing; //OCPP Status: Preparing
  6034. }
  6035. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6036. {
  6037. currentStatus = Charging; //OCPP Status: Charging
  6038. }
  6039. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6040. {
  6041. currentStatus = Finishing; //OCPP Status: Finishing
  6042. }
  6043. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6044. {
  6045. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6046. }
  6047. 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
  6048. {
  6049. currentStatus = Unavailable; //OCPP Status: Unavailable
  6050. }
  6051. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6052. {
  6053. currentStatus = Faulted; //OCPP Status: Faulted
  6054. }
  6055. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6056. {
  6057. currentStatus = Reserved; //OCPP Status: Reserved
  6058. }
  6059. } //end of the same index
  6060. } // end of for GB_QUANTITY
  6061. }
  6062. else if(gunType[gun_index] == GUN_TYPE_DO)
  6063. {
  6064. tempIndex = gun_index;
  6065. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6066. {
  6067. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6068. {
  6069. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6070. {
  6071. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6072. {
  6073. currentStatus = Preparing; //OCPP Status: Preparing
  6074. }
  6075. else
  6076. {
  6077. currentStatus = Available; //OCPP Status: Available
  6078. }
  6079. }
  6080. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6081. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6082. ) //S_PRECHARGE
  6083. {
  6084. currentStatus = Preparing; //OCPP Status: Preparing
  6085. }
  6086. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6087. {
  6088. currentStatus = Charging; //OCPP Status: Charging
  6089. }
  6090. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6091. {
  6092. currentStatus = Finishing; //OCPP Status: Finishing
  6093. }
  6094. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6095. {
  6096. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6097. }
  6098. 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
  6099. {
  6100. currentStatus = Unavailable; //OCPP Status: Unavailable
  6101. }
  6102. 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
  6103. {
  6104. currentStatus = Faulted; //OCPP Status: Faulted
  6105. }
  6106. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6107. {
  6108. currentStatus = Reserved; //OCPP Status: Reserved
  6109. }
  6110. } //end of the same index
  6111. }
  6112. }
  6113. else
  6114. {
  6115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6116. {
  6117. tempIndex = 2;
  6118. }
  6119. else
  6120. {
  6121. tempIndex = gun_index;
  6122. }
  6123. for (int index = 0; index < AC_QUANTITY; index++)
  6124. {
  6125. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6126. {
  6127. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6128. {
  6129. 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))
  6130. {
  6131. currentStatus = Preparing; //OCPP Status: Preparing
  6132. }
  6133. else
  6134. {
  6135. currentStatus = Available; //OCPP Status: Available
  6136. }
  6137. }
  6138. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6139. {
  6140. currentStatus = Preparing; //OCPP Status: Preparing
  6141. }
  6142. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6143. {
  6144. currentStatus = Charging; //OCPP Status: Charging
  6145. }
  6146. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6147. {
  6148. currentStatus = Finishing; //OCPP Status: Finishing
  6149. }
  6150. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6151. {
  6152. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6153. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6154. else
  6155. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6156. }
  6157. 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
  6158. {
  6159. currentStatus = Unavailable; //OCPP Status: Unavailable
  6160. }
  6161. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6162. {
  6163. currentStatus = Faulted; //OCPP Status: Faulted
  6164. }
  6165. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6166. {
  6167. currentStatus = Reserved; //OCPP Status: Reserved
  6168. }
  6169. }//end of the same index
  6170. }//end of for AC_QUANTITY
  6171. }
  6172. //it's option
  6173. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6174. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6175. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6176. {
  6177. isStateChanged = FALSE;
  6178. }
  6179. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6180. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6181. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6182. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6183. isContentIllegal = TRUE;
  6184. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6185. {
  6186. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6187. {
  6188. isContentIllegal = FALSE;
  6189. break;
  6190. }
  6191. }
  6192. if(isContentIllegal)
  6193. {
  6194. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6195. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6196. }
  6197. random_uuid(guid);
  6198. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6199. , MESSAGE_TYPE_CALL
  6200. , guid
  6201. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6202. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6203. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6204. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6205. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6206. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6207. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6208. if((server_sign == TRUE) && isStateChanged)
  6209. {
  6210. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6211. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6212. LWS_Send(message);
  6213. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6214. 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*/)
  6215. {
  6216. //DEBUG_ERROR("statusNotification mapitem pass");
  6217. result = PASS;
  6218. }
  6219. }
  6220. else
  6221. {
  6222. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6223. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6224. result = PASS;
  6225. }
  6226. return result;
  6227. }
  6228. int sendStopTransactionRequest(int gun_index)
  6229. {
  6230. mtrace();
  6231. int result = FAIL;
  6232. //char message[1500]={0};
  6233. char guid[37]={0};
  6234. char tempdata[65]={0};
  6235. int tempIndex = 0;
  6236. char TempStopTransaction[256];
  6237. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6238. //int idx_sample=0;
  6239. DEBUG_INFO("sendStopTransactionRequest \n");
  6240. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6241. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6242. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6243. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6244. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6245. {
  6246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6247. {
  6248. tempIndex = ((gun_index==2) ? 1: 0);
  6249. }
  6250. else
  6251. {
  6252. tempIndex = gun_index;
  6253. }
  6254. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6255. {
  6256. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6257. {
  6258. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6259. }
  6260. }// END OF CHAdeMO_QUANTITY
  6261. }
  6262. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6263. {
  6264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6265. {
  6266. tempIndex = ((gun_index==2) ? 1: 0);
  6267. }
  6268. else
  6269. {
  6270. tempIndex = gun_index;
  6271. }
  6272. for (int index = 0; index < CCS_QUANTITY; index++)
  6273. {
  6274. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6275. {
  6276. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6277. }
  6278. }// END OF CCS_QUANTITY
  6279. }
  6280. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6281. {
  6282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6283. {
  6284. tempIndex = ((gun_index==2) ? 1: 0);
  6285. }
  6286. else
  6287. {
  6288. tempIndex = gun_index;
  6289. }
  6290. for (int index = 0; index < GB_QUANTITY; index++)
  6291. {
  6292. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6293. {
  6294. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6295. }
  6296. }// END OF GB_QUANTITY
  6297. }
  6298. else if(gunType[gun_index] == GUN_TYPE_DO)
  6299. {
  6300. tempIndex = gun_index;
  6301. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6302. {
  6303. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6304. {
  6305. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6306. }
  6307. }// END OF GB_QUANTITY
  6308. }
  6309. else
  6310. {
  6311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6312. {
  6313. tempIndex = 2;
  6314. }
  6315. else
  6316. {
  6317. tempIndex = gun_index;
  6318. }
  6319. for (int index = 0; index < AC_QUANTITY; index++)
  6320. {
  6321. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6322. {
  6323. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6324. }
  6325. }// END OF AC_QUANTITY
  6326. }
  6327. //====================================== Stop Transaction Time =====================================================
  6328. struct timeval tmnow;
  6329. struct tm *tm;
  6330. char buf[28];//, usec_buf[6];
  6331. gettimeofday(&tmnow, NULL);
  6332. time_t t;
  6333. t = time(NULL);
  6334. /*UTC time and date*/
  6335. tm = gmtime(&t);
  6336. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  6338. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6339. random_uuid(guid);
  6340. /***********************************transactionData******************************************************/
  6341. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  6342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  6343. //=================================
  6344. // Transaction_Begin
  6345. //=================================
  6346. //=================================
  6347. // Transaction_End
  6348. //=================================
  6349. // ================================= Current.Import L1 ===============================================
  6350. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6351. {
  6352. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6353. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6354. {
  6355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6356. {
  6357. tempIndex = ((gun_index==2) ? 1: 0);
  6358. }
  6359. else
  6360. {
  6361. tempIndex = gun_index;
  6362. }
  6363. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6364. {
  6365. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6366. {
  6367. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6368. }
  6369. }// End of for CHAdeMO_QUANTITY
  6370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6371. }
  6372. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6373. {
  6374. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6375. {
  6376. tempIndex = ((gun_index==2) ? 1: 0);
  6377. }
  6378. else
  6379. {
  6380. tempIndex = gun_index;
  6381. }
  6382. for (int index = 0; index < CCS_QUANTITY; index++)
  6383. {
  6384. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6385. {
  6386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6387. }
  6388. }// End of for CCS_QUANTITY
  6389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6390. }
  6391. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6392. {
  6393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6394. {
  6395. tempIndex = ((gun_index==2) ? 1: 0);
  6396. }
  6397. else
  6398. {
  6399. tempIndex = gun_index;
  6400. }
  6401. for (int index = 0; index < GB_QUANTITY; index++)
  6402. {
  6403. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6404. {
  6405. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6406. }
  6407. }// End of for GB_QUANTITY
  6408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6409. }
  6410. else if(gunType[gun_index] == GUN_TYPE_DO)
  6411. {
  6412. tempIndex = gun_index;
  6413. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6414. {
  6415. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6416. {
  6417. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6418. }
  6419. }
  6420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6421. }
  6422. else
  6423. {
  6424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6425. {
  6426. tempIndex = 2;
  6427. }
  6428. else
  6429. {
  6430. tempIndex = gun_index;
  6431. }
  6432. for (int index = 0; index < AC_QUANTITY; index++)
  6433. {
  6434. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6435. {
  6436. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6437. }
  6438. }// End of for AC_QUANTITY
  6439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6440. }
  6441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6446. }
  6447. // ================================= Energy.Active.Import.Interval ==============================================
  6448. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6449. {
  6450. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6451. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6452. {
  6453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6454. {
  6455. tempIndex = ((gun_index==2) ? 1: 0);
  6456. }
  6457. else
  6458. {
  6459. tempIndex = gun_index;
  6460. }
  6461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6462. {
  6463. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6464. {
  6465. 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
  6466. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6467. }
  6468. }// END OF CHAdeMO_QUANTITY
  6469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6470. }
  6471. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6472. {
  6473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6474. {
  6475. tempIndex = ((gun_index==2) ? 1: 0);
  6476. }
  6477. else
  6478. {
  6479. tempIndex = gun_index;
  6480. }
  6481. for (int index = 0; index < CCS_QUANTITY; index++)
  6482. {
  6483. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6484. {
  6485. 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
  6486. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6487. }
  6488. }// END OF CCS_QUANTITY
  6489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6490. }
  6491. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6492. {
  6493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6494. {
  6495. tempIndex = ((gun_index==2) ? 1: 0);
  6496. }
  6497. else
  6498. {
  6499. tempIndex = gun_index;
  6500. }
  6501. for (int index = 0; index < GB_QUANTITY; index++)
  6502. {
  6503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6504. {
  6505. 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
  6506. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6507. }
  6508. }// END OF GB_QUANTITY
  6509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6510. }
  6511. else if(gunType[gun_index] == GUN_TYPE_DO)
  6512. {
  6513. tempIndex = gun_index;
  6514. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6515. {
  6516. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6517. {
  6518. 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
  6519. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6520. }
  6521. }
  6522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6523. }
  6524. else
  6525. {
  6526. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6527. {
  6528. tempIndex = 2;
  6529. }
  6530. else
  6531. {
  6532. tempIndex = gun_index;
  6533. }
  6534. for (int index = 0; index < AC_QUANTITY; index++)
  6535. {
  6536. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6537. {
  6538. 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
  6539. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6540. }
  6541. }// END OF AC_QUANTITY
  6542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6543. }
  6544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6549. }
  6550. //=================================== Power.Active.Import ==================================================
  6551. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6552. {
  6553. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6554. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6555. {
  6556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6557. {
  6558. tempIndex = ((gun_index==2) ? 1: 0);
  6559. }
  6560. else
  6561. {
  6562. tempIndex = gun_index;
  6563. }
  6564. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6567. {
  6568. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6569. }
  6570. } // End for CHAdeMO_QUANTITY
  6571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6572. }
  6573. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6574. {
  6575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6576. {
  6577. tempIndex = ((gun_index==2) ? 1: 0);
  6578. }
  6579. else
  6580. {
  6581. tempIndex = gun_index;
  6582. }
  6583. for (int index = 0; index < CCS_QUANTITY; index++)
  6584. {
  6585. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6586. {
  6587. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6588. }
  6589. } // END for CCS_QUANTITY
  6590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6591. }
  6592. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6593. {
  6594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6595. {
  6596. tempIndex = ((gun_index==2) ? 1: 0);
  6597. }
  6598. else
  6599. {
  6600. tempIndex = gun_index;
  6601. }
  6602. for (int index = 0; index < GB_QUANTITY; index++)
  6603. {
  6604. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6605. {
  6606. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6607. }
  6608. }// END for GB_QUANTITY
  6609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6610. }
  6611. else if(gunType[gun_index] == GUN_TYPE_DO)
  6612. {
  6613. tempIndex = gun_index;
  6614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6615. {
  6616. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6617. {
  6618. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6619. }
  6620. }
  6621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6622. }
  6623. else
  6624. {
  6625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6626. {
  6627. tempIndex = 2;
  6628. }
  6629. else
  6630. {
  6631. tempIndex = gun_index;
  6632. }
  6633. for (int index = 0; index < AC_QUANTITY; index++)
  6634. {
  6635. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6636. {
  6637. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6638. }
  6639. } // END for AC_QUANTITY
  6640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6641. }
  6642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6647. }
  6648. //============================ Voltage L1 ====================================
  6649. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6650. {
  6651. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6652. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6653. {
  6654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6655. {
  6656. tempIndex = ((gun_index==2) ? 1: 0);
  6657. }
  6658. else
  6659. {
  6660. tempIndex = gun_index;
  6661. }
  6662. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6663. {
  6664. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6665. {
  6666. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6667. }
  6668. } // END OF FOR CHAdeMO_QUANTITY
  6669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6670. }
  6671. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6672. {
  6673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6674. {
  6675. tempIndex = ((gun_index==2) ? 1: 0);
  6676. }
  6677. else
  6678. {
  6679. tempIndex = gun_index;
  6680. }
  6681. for (int index = 0; index < CCS_QUANTITY; index++)
  6682. {
  6683. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6684. {
  6685. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6686. }
  6687. } // END OF FOR CCS_QUANTITY
  6688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6689. }
  6690. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6691. {
  6692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6693. {
  6694. tempIndex = ((gun_index==2) ? 1: 0);
  6695. }
  6696. else
  6697. {
  6698. tempIndex = gun_index;
  6699. }
  6700. for (int index = 0; index < GB_QUANTITY; index++)
  6701. {
  6702. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6703. {
  6704. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6705. }
  6706. } // END OF FOR GB_QUANTITY
  6707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6708. }
  6709. else if(gunType[gun_index] == GUN_TYPE_DO)
  6710. {
  6711. tempIndex = gun_index;
  6712. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6713. {
  6714. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6715. {
  6716. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6717. }
  6718. }
  6719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6720. }
  6721. else
  6722. {
  6723. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6724. {
  6725. tempIndex = 2;
  6726. }
  6727. else
  6728. {
  6729. tempIndex = gun_index;
  6730. }
  6731. for (int index = 0; index < AC_QUANTITY; index++)
  6732. {
  6733. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6734. {
  6735. 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
  6736. }
  6737. } // END OF FOR AC_QUANTITY
  6738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6739. }
  6740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6745. }
  6746. //====================== End SoC ================================
  6747. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6748. {
  6749. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6750. 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))
  6751. {
  6752. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6753. {
  6754. tempIndex = ((gun_index==2) ? 1: 0);
  6755. }
  6756. else
  6757. {
  6758. tempIndex = gun_index;
  6759. }
  6760. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6761. {
  6762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6763. {
  6764. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6765. {
  6766. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6767. }
  6768. }
  6769. }
  6770. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6771. {
  6772. for (int index = 0; index < CCS_QUANTITY; index++)
  6773. {
  6774. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6775. {
  6776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6777. }
  6778. }
  6779. }
  6780. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6781. {
  6782. for (int index = 0; index < GB_QUANTITY; index++)
  6783. {
  6784. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6785. {
  6786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6787. }
  6788. }
  6789. }
  6790. else if(gunType[gun_index] == GUN_TYPE_DO)
  6791. {
  6792. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6793. {
  6794. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6795. {
  6796. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6797. }
  6798. }
  6799. }
  6800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6806. } // END FOR DC CASE
  6807. }
  6808. // ================================= Current.Import L2 ===============================================
  6809. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6810. {
  6811. // AC 3 phse L2 current
  6812. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6813. {
  6814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6815. {
  6816. tempIndex = 2;
  6817. }
  6818. else
  6819. {
  6820. tempIndex = gun_index;
  6821. }
  6822. for (int index = 0; index < AC_QUANTITY; index++)
  6823. {
  6824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6825. {
  6826. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6827. }
  6828. }// End of for AC_QUANTITY
  6829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6830. }
  6831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6836. }
  6837. // ================================= Current.Import L3 ===============================================
  6838. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6839. {
  6840. // AC 3 phse L3 current
  6841. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6842. {
  6843. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6844. {
  6845. tempIndex = 2;
  6846. }
  6847. else
  6848. {
  6849. tempIndex = gun_index;
  6850. }
  6851. for (int index = 0; index < AC_QUANTITY; index++)
  6852. {
  6853. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6854. {
  6855. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6856. }
  6857. }// End of for AC_QUANTITY
  6858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6859. }
  6860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6865. }
  6866. //============================ Voltage L2 ====================================
  6867. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6868. {
  6869. // AC 3 phse L2 voltage
  6870. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6871. {
  6872. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6873. {
  6874. tempIndex = 2;
  6875. }
  6876. else
  6877. {
  6878. tempIndex = gun_index;
  6879. }
  6880. for (int index = 0; index < AC_QUANTITY; index++)
  6881. {
  6882. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6883. {
  6884. 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
  6885. }
  6886. } // END OF FOR AC_QUANTITY
  6887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6888. }
  6889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6894. }
  6895. //============================ Voltage L3 ====================================
  6896. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6897. {
  6898. // AC 3 phse L3 voltage
  6899. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6900. {
  6901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6902. {
  6903. tempIndex = 2;
  6904. }
  6905. else
  6906. {
  6907. tempIndex = gun_index;
  6908. }
  6909. for (int index = 0; index < AC_QUANTITY; index++)
  6910. {
  6911. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6912. {
  6913. 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
  6914. }
  6915. } // END OF FOR AC_QUANTITY
  6916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6917. }
  6918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6922. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6923. }
  6924. //====================== Start SoC ================================
  6925. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6926. {
  6927. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6928. 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))
  6929. {
  6930. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6931. {
  6932. tempIndex = ((gun_index==2) ? 1: 0);
  6933. }
  6934. else
  6935. {
  6936. tempIndex = gun_index;
  6937. }
  6938. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6939. {
  6940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6941. {
  6942. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6943. {
  6944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6945. }
  6946. }
  6947. }
  6948. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6949. {
  6950. for (int index = 0; index < CCS_QUANTITY; index++)
  6951. {
  6952. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6953. {
  6954. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6955. }
  6956. }
  6957. }
  6958. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6959. {
  6960. for (int index = 0; index < GB_QUANTITY; index++)
  6961. {
  6962. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6963. {
  6964. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6965. }
  6966. }
  6967. }
  6968. else if(gunType[gun_index] == GUN_TYPE_DO)
  6969. {
  6970. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6971. {
  6972. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6973. {
  6974. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6975. }
  6976. }
  6977. }
  6978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6984. } // END FOR DC CASE
  6985. }
  6986. //================================================ Message create ====================================================
  6987. json_object *StopTransaction = json_object_new_object();
  6988. json_object *transactionDatas = json_object_new_array();
  6989. json_object *sampledValues = json_object_new_array();
  6990. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6991. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6992. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6993. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6994. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6995. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6996. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6997. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6998. {
  6999. json_object *transactionData = json_object_new_object();
  7000. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  7001. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  7002. {
  7003. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  7004. {
  7005. json_object *sampledValue = json_object_new_object();
  7006. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  7007. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  7008. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  7009. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  7010. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  7011. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  7012. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  7013. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  7014. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  7015. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  7016. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  7017. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  7018. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  7019. json_object_array_add(sampledValues, sampledValue);
  7020. }
  7021. }
  7022. json_object_object_add(transactionData, "sampledValue", sampledValues);
  7023. json_object_array_add(transactionDatas, transactionData);
  7024. }
  7025. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  7026. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  7027. ,MESSAGE_TYPE_CALL
  7028. ,guid
  7029. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  7030. json_object_put(StopTransaction);
  7031. #if 1 // for TempStopTransaction
  7032. //Delete TempStopTransaction
  7033. if((access(TempStopTransaction,F_OK))!=-1)
  7034. {
  7035. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7036. }
  7037. #endif
  7038. #if 1
  7039. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  7040. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  7041. {
  7042. result = PASS;
  7043. //DEBUG_INFO("StopTransaction mapitem pass\n");
  7044. }
  7045. #endif
  7046. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  7047. OCPP_insert_transaction_msg(NO, queuedata);
  7048. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  7049. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  7050. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  7051. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  7052. {
  7053. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  7054. }
  7055. //for test
  7056. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  7057. return result;
  7058. }
  7059. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  7060. {
  7061. mtrace();
  7062. int result = FAIL;
  7063. char guid[37]={0};
  7064. char tempdata[65]={0};
  7065. int tempIndex = 0;
  7066. DEBUG_INFO("sendMeterValuesRequest ...\n");
  7067. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  7068. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  7069. //set value
  7070. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  7071. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  7072. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  7073. -1);
  7074. random_uuid(guid);
  7075. //UTC Date time
  7076. struct timeval tmnow;
  7077. struct tm *tm;
  7078. char buf[28];//, usec_buf[6];
  7079. gettimeofday(&tmnow, NULL);
  7080. time_t t;
  7081. t = time(NULL);
  7082. /*UTC time and date*/
  7083. tm = gmtime(&t);
  7084. if(dataType == ReadingContext_Sample_Clock)
  7085. {
  7086. struct tm *tmTarget;
  7087. struct timeb tbTarget;
  7088. tbTarget.time = mktime(tm);
  7089. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  7090. tmTarget = gmtime(&tbTarget.time);
  7091. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  7092. }
  7093. else
  7094. {
  7095. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7096. }
  7097. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  7098. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  7099. //********************************(1)Current.Import L1************************************************/
  7100. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7101. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7102. (dataType == ReadingContext_Trigger))
  7103. {
  7104. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7105. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7106. {
  7107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7108. {
  7109. tempIndex = ((gun_index==2) ? 1: 0);
  7110. }
  7111. else
  7112. {
  7113. tempIndex = gun_index;
  7114. }
  7115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7116. {
  7117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7118. {
  7119. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  7120. }
  7121. }
  7122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7123. }
  7124. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7125. {
  7126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7127. {
  7128. tempIndex = ((gun_index==2) ? 1: 0);
  7129. }
  7130. else
  7131. {
  7132. tempIndex = gun_index;
  7133. }
  7134. for (int index = 0; index < CCS_QUANTITY; index++)
  7135. {
  7136. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7137. {
  7138. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  7139. }
  7140. }
  7141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7142. }
  7143. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7144. {
  7145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7146. {
  7147. tempIndex = ((gun_index==2) ? 1: 0);
  7148. }
  7149. else
  7150. {
  7151. tempIndex = gun_index;
  7152. }
  7153. for (int index = 0; index < GB_QUANTITY; index++)
  7154. {
  7155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7156. {
  7157. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  7158. }
  7159. }
  7160. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7161. }
  7162. else if(gunType[gun_index] == GUN_TYPE_DO)
  7163. {
  7164. tempIndex = gun_index;
  7165. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7166. {
  7167. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7168. {
  7169. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  7170. }
  7171. }
  7172. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7173. }
  7174. else
  7175. {
  7176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7177. {
  7178. tempIndex = 2;
  7179. }
  7180. else
  7181. {
  7182. tempIndex = gun_index;
  7183. }
  7184. for (int index = 0; index < AC_QUANTITY; index++)
  7185. {
  7186. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7187. {
  7188. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  7189. }
  7190. }
  7191. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  7192. }
  7193. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  7194. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  7195. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  7196. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  7197. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7198. }
  7199. //********************************(2)Energy.Active.Import.Register ************************************************/
  7200. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  7201. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  7202. (dataType == ReadingContext_Trigger))
  7203. {
  7204. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7205. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  7216. {
  7217. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7218. {
  7219. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  7220. }
  7221. }
  7222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7223. }
  7224. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7225. {
  7226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7227. {
  7228. tempIndex = ((gun_index==2) ? 1: 0);
  7229. }
  7230. else
  7231. {
  7232. tempIndex = gun_index;
  7233. }
  7234. for (int index = 0; index < CCS_QUANTITY; index++)
  7235. {
  7236. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7237. {
  7238. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  7239. }
  7240. }
  7241. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7242. }
  7243. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7244. {
  7245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7246. {
  7247. tempIndex = ((gun_index==2) ? 1: 0);
  7248. }
  7249. else
  7250. {
  7251. tempIndex = gun_index;
  7252. }
  7253. for (int index = 0; index < GB_QUANTITY; index++)
  7254. {
  7255. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7256. {
  7257. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  7258. }
  7259. }
  7260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7261. }
  7262. else if(gunType[gun_index] == GUN_TYPE_DO)
  7263. {
  7264. tempIndex = gun_index;
  7265. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7266. {
  7267. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7268. {
  7269. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7270. }
  7271. }
  7272. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7273. }
  7274. else
  7275. {
  7276. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7277. {
  7278. tempIndex = 2;
  7279. }
  7280. else
  7281. {
  7282. tempIndex = gun_index;
  7283. }
  7284. for (int index = 0; index < AC_QUANTITY; index++)
  7285. {
  7286. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7287. {
  7288. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7289. }
  7290. }
  7291. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7292. }
  7293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7298. }
  7299. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7300. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7301. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7302. (dataType == ReadingContext_Trigger))
  7303. {
  7304. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7305. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7306. {
  7307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7308. {
  7309. tempIndex = ((gun_index==2) ? 1: 0);
  7310. }
  7311. else
  7312. {
  7313. tempIndex = gun_index;
  7314. }
  7315. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7316. {
  7317. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7318. {
  7319. if(dataType == ReadingContext_Sample_Clock)
  7320. {
  7321. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7322. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7323. }
  7324. else if(dataType == ReadingContext_Sample_Periodic)
  7325. {
  7326. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7327. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7328. }
  7329. else
  7330. {
  7331. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7332. }
  7333. }
  7334. } // END OF FOR CHAdeMO_QUANTITY
  7335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7336. }
  7337. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7338. {
  7339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7340. {
  7341. tempIndex = ((gun_index==2) ? 1: 0);
  7342. }
  7343. else
  7344. {
  7345. tempIndex = gun_index;
  7346. }
  7347. for (int index = 0; index < CCS_QUANTITY; index++)
  7348. {
  7349. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7350. {
  7351. if(dataType == ReadingContext_Sample_Clock)
  7352. {
  7353. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7354. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7355. }
  7356. else if(dataType == ReadingContext_Sample_Periodic)
  7357. {
  7358. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7359. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7360. }
  7361. else
  7362. {
  7363. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7364. }
  7365. }
  7366. } // END OF CCS_QUANTITY
  7367. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7368. }
  7369. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7370. {
  7371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7372. {
  7373. tempIndex = ((gun_index==2) ? 1: 0);
  7374. }
  7375. else
  7376. {
  7377. tempIndex = gun_index;
  7378. }
  7379. for (int index = 0; index < GB_QUANTITY; index++)
  7380. {
  7381. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7382. {
  7383. if(dataType == ReadingContext_Sample_Clock)
  7384. {
  7385. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7386. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7387. }
  7388. else if(dataType == ReadingContext_Sample_Periodic)
  7389. {
  7390. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7391. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7392. }
  7393. else
  7394. {
  7395. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7396. }
  7397. }
  7398. } // END OF GB_QUANTITY
  7399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7400. }
  7401. else if(gunType[gun_index] == GUN_TYPE_DO)
  7402. {
  7403. tempIndex = gun_index;
  7404. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7405. {
  7406. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7407. {
  7408. if(dataType == ReadingContext_Sample_Clock)
  7409. {
  7410. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7411. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7412. }
  7413. else if(dataType == ReadingContext_Sample_Periodic)
  7414. {
  7415. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7416. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7417. }
  7418. else
  7419. {
  7420. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7421. }
  7422. }
  7423. }
  7424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7425. }
  7426. else
  7427. {
  7428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7429. {
  7430. tempIndex = 2;
  7431. }
  7432. else
  7433. {
  7434. tempIndex = gun_index;
  7435. }
  7436. for (int index = 0; index < AC_QUANTITY; index++)
  7437. {
  7438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7439. {
  7440. if(dataType == ReadingContext_Sample_Clock)
  7441. {
  7442. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7443. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7444. }
  7445. else if(dataType == ReadingContext_Sample_Periodic)
  7446. {
  7447. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7448. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7449. }
  7450. else
  7451. {
  7452. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7453. }
  7454. }
  7455. }
  7456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7457. }
  7458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7459. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7462. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7463. }
  7464. //********************************(4)Power.Active.Import************************************************/
  7465. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7466. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7467. (dataType == ReadingContext_Trigger))
  7468. {
  7469. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7470. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7471. {
  7472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7473. {
  7474. tempIndex = ((gun_index==2) ? 1: 0);
  7475. }
  7476. else
  7477. {
  7478. tempIndex = gun_index;
  7479. }
  7480. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7481. {
  7482. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7483. {
  7484. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7485. }
  7486. } // END OF FOR
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7488. }
  7489. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7490. {
  7491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7492. {
  7493. tempIndex = ((gun_index==2) ? 1: 0);
  7494. }
  7495. else
  7496. {
  7497. tempIndex = gun_index;
  7498. }
  7499. for (int index = 0; index < CCS_QUANTITY; index++)
  7500. {
  7501. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7502. {
  7503. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7504. }
  7505. }
  7506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7507. }
  7508. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7509. {
  7510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7511. {
  7512. tempIndex = ((gun_index==2) ? 1: 0);
  7513. }
  7514. else
  7515. {
  7516. tempIndex = gun_index;
  7517. }
  7518. for (int index = 0; index < GB_QUANTITY; index++)
  7519. {
  7520. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7521. {
  7522. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7523. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7524. }
  7525. }
  7526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7527. }
  7528. else if(gunType[gun_index] == GUN_TYPE_DO)
  7529. {
  7530. tempIndex = gun_index;
  7531. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7532. {
  7533. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7534. {
  7535. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7536. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7537. }
  7538. }
  7539. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7540. }
  7541. else
  7542. {
  7543. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7544. {
  7545. tempIndex = 2;
  7546. }
  7547. else
  7548. {
  7549. tempIndex = gun_index;
  7550. }
  7551. for (int index = 0; index < AC_QUANTITY; index++)
  7552. {
  7553. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7554. {
  7555. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7556. }
  7557. }
  7558. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7559. }
  7560. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7565. }
  7566. //***********************************************(5)VOLTAGE L1******************************************************/
  7567. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7568. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7569. (dataType == ReadingContext_Trigger))
  7570. {
  7571. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7572. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7573. {
  7574. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7575. {
  7576. tempIndex = ((gun_index==2) ? 1: 0);
  7577. }
  7578. else
  7579. {
  7580. tempIndex = gun_index;
  7581. }
  7582. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7583. {
  7584. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7585. {
  7586. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7587. }
  7588. }
  7589. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7590. }
  7591. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7592. {
  7593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7594. {
  7595. tempIndex = ((gun_index==2) ? 1: 0);
  7596. }
  7597. else
  7598. {
  7599. tempIndex = gun_index;
  7600. }
  7601. for (int index = 0; index < CCS_QUANTITY; index++)
  7602. {
  7603. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7604. {
  7605. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7606. }
  7607. }
  7608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7609. }
  7610. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7611. {
  7612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7613. {
  7614. tempIndex = ((gun_index==2) ? 1: 0);
  7615. }
  7616. else
  7617. {
  7618. tempIndex = gun_index;
  7619. }
  7620. for (int index = 0; index < GB_QUANTITY; index++)
  7621. {
  7622. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7623. {
  7624. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7625. }
  7626. }
  7627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7628. }
  7629. else if(gunType[gun_index] == GUN_TYPE_DO)
  7630. {
  7631. tempIndex = gun_index;
  7632. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7633. {
  7634. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7635. {
  7636. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7637. }
  7638. }
  7639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7640. }
  7641. else
  7642. {
  7643. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7644. {
  7645. tempIndex = 2;
  7646. }
  7647. else
  7648. {
  7649. tempIndex = gun_index;
  7650. }
  7651. for (int index = 0; index < AC_QUANTITY; index++)
  7652. {
  7653. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7654. {
  7655. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7656. }
  7657. }
  7658. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7659. }
  7660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7662. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7665. }
  7666. //***********************************************(6)SOC******************************************************/
  7667. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7668. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7669. (dataType == ReadingContext_Trigger))
  7670. {
  7671. 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))
  7672. {
  7673. //idx_sample=5;
  7674. //sampledValue = NULL;
  7675. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7676. {
  7677. tempIndex = ((gun_index==2) ? 1: 0);
  7678. }
  7679. else
  7680. {
  7681. tempIndex = gun_index;
  7682. }
  7683. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7684. {
  7685. //tempIndex = ((gun_index==2) ? 1: 0);
  7686. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7687. {
  7688. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7689. {
  7690. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7691. }
  7692. }
  7693. }
  7694. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7695. {
  7696. //tempIndex = ((gun_index==2) ? 1: 0);
  7697. for (int index = 0; index < CCS_QUANTITY; index++)
  7698. {
  7699. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7700. {
  7701. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7702. }
  7703. }
  7704. }
  7705. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7706. {
  7707. //tempIndex = ((gun_index==2) ? 1: 0);
  7708. for (int index = 0; index < GB_QUANTITY; index++)
  7709. {
  7710. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7711. {
  7712. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7713. }
  7714. }
  7715. }
  7716. else if(gunType[gun_index] == GUN_TYPE_DO)
  7717. {
  7718. //tempIndex = ((gun_index==2) ? 1: 0);
  7719. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7720. {
  7721. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7722. {
  7723. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7724. }
  7725. }
  7726. }
  7727. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7728. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7729. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7730. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7731. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7732. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7733. }
  7734. }
  7735. //********************************(7)Current.Import L2************************************************/
  7736. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7737. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7738. (dataType == ReadingContext_Trigger))
  7739. {
  7740. // Only for AC 3 phase
  7741. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7742. {
  7743. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7744. {
  7745. tempIndex = 2;
  7746. }
  7747. else
  7748. {
  7749. tempIndex = gun_index;
  7750. }
  7751. for (int index = 0; index < AC_QUANTITY; index++)
  7752. {
  7753. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7754. {
  7755. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7756. }
  7757. }
  7758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7759. }
  7760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7761. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7762. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7763. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7764. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7765. }
  7766. //********************************(8)Current.Import L3************************************************/
  7767. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7768. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7769. (dataType == ReadingContext_Trigger))
  7770. {
  7771. // Only for AC 3 phase
  7772. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7773. {
  7774. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7775. {
  7776. tempIndex = 2;
  7777. }
  7778. else
  7779. {
  7780. tempIndex = gun_index;
  7781. }
  7782. for (int index = 0; index < AC_QUANTITY; index++)
  7783. {
  7784. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7785. {
  7786. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7787. }
  7788. }
  7789. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7790. }
  7791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7796. }
  7797. //***********************************************(9)VOLTAGE L2******************************************************/
  7798. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7799. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7800. (dataType == ReadingContext_Trigger))
  7801. {
  7802. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7803. {
  7804. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7805. {
  7806. tempIndex = 2;
  7807. }
  7808. else
  7809. {
  7810. tempIndex = gun_index;
  7811. }
  7812. for (int index = 0; index < AC_QUANTITY; index++)
  7813. {
  7814. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7815. {
  7816. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7817. }
  7818. }
  7819. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7820. }
  7821. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7822. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7823. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7824. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7825. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7826. }
  7827. //***********************************************(10)VOLTAGE L3******************************************************/
  7828. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7829. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7830. (dataType == ReadingContext_Trigger))
  7831. {
  7832. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7833. {
  7834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7835. {
  7836. tempIndex = 2;
  7837. }
  7838. else
  7839. {
  7840. tempIndex = gun_index;
  7841. }
  7842. for (int index = 0; index < AC_QUANTITY; index++)
  7843. {
  7844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7845. {
  7846. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7847. }
  7848. }
  7849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7850. }
  7851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7852. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7853. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7854. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7856. }
  7857. //***********************************************(11)Current.Offered******************************************************/
  7858. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7859. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7860. (dataType == ReadingContext_Trigger))
  7861. {
  7862. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7863. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7864. {
  7865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7866. {
  7867. tempIndex = ((gun_index==2) ? 1: 0);
  7868. }
  7869. else
  7870. {
  7871. tempIndex = gun_index;
  7872. }
  7873. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7874. {
  7875. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7876. {
  7877. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7878. }
  7879. } // END OF FOR CHAdeMO_QUANTITY
  7880. }
  7881. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7882. {
  7883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7884. {
  7885. tempIndex = ((gun_index==2) ? 1: 0);
  7886. }
  7887. else
  7888. {
  7889. tempIndex = gun_index;
  7890. }
  7891. for (int index = 0; index < CCS_QUANTITY; index++)
  7892. {
  7893. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7894. {
  7895. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7896. }
  7897. } // END OF CCS_QUANTITY
  7898. }
  7899. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7900. {
  7901. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7902. {
  7903. tempIndex = ((gun_index==2) ? 1: 0);
  7904. }
  7905. else
  7906. {
  7907. tempIndex = gun_index;
  7908. }
  7909. for (int index = 0; index < GB_QUANTITY; index++)
  7910. {
  7911. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7912. {
  7913. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7914. }
  7915. } // END OF GB_QUANTITY
  7916. }
  7917. else if(gunType[gun_index] == GUN_TYPE_DO)
  7918. {
  7919. tempIndex = gun_index;
  7920. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7921. {
  7922. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7923. {
  7924. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7925. }
  7926. }
  7927. }
  7928. else
  7929. {
  7930. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7931. {
  7932. tempIndex = 2;
  7933. }
  7934. else
  7935. {
  7936. tempIndex = gun_index;
  7937. }
  7938. for (int index = 0; index < AC_QUANTITY; index++)
  7939. {
  7940. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7941. {
  7942. uint16_t currentOffer;
  7943. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7944. {
  7945. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7946. }
  7947. else
  7948. {
  7949. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7950. }
  7951. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7952. }
  7953. }
  7954. }
  7955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7957. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7958. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7959. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7960. }
  7961. //***********************************************(12)Power.Offered******************************************************/
  7962. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7963. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7964. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7965. {
  7966. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7967. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7968. {
  7969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7970. {
  7971. tempIndex = ((gun_index==2) ? 1: 0);
  7972. }
  7973. else
  7974. {
  7975. tempIndex = gun_index;
  7976. }
  7977. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7978. {
  7979. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7980. {
  7981. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7982. }
  7983. } // END OF FOR CHAdeMO_QUANTITY
  7984. }
  7985. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7986. {
  7987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7988. {
  7989. tempIndex = ((gun_index==2) ? 1: 0);
  7990. }
  7991. else
  7992. {
  7993. tempIndex = gun_index;
  7994. }
  7995. for (int index = 0; index < CCS_QUANTITY; index++)
  7996. {
  7997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7998. {
  7999. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  8000. }
  8001. } // END OF CCS_QUANTITY
  8002. }
  8003. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8004. {
  8005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8006. {
  8007. tempIndex = ((gun_index==2) ? 1: 0);
  8008. }
  8009. else
  8010. {
  8011. tempIndex = gun_index;
  8012. }
  8013. for (int index = 0; index < GB_QUANTITY; index++)
  8014. {
  8015. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8016. {
  8017. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  8018. }
  8019. } // END OF GB_QUANTITY
  8020. }
  8021. else if(gunType[gun_index] == GUN_TYPE_DO)
  8022. {
  8023. tempIndex = gun_index;
  8024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8025. {
  8026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8027. {
  8028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  8029. }
  8030. }
  8031. }
  8032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  8033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  8034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  8035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  8036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  8037. }
  8038. // Message create ====================================================================================================
  8039. if(TRUE)
  8040. {
  8041. json_object *MeterValueReq = json_object_new_object();
  8042. json_object *MeterValues = json_object_new_array();
  8043. json_object *sampledValues = json_object_new_array();
  8044. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  8045. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  8046. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  8047. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  8048. {
  8049. json_object *MeterValue = json_object_new_object();
  8050. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  8051. {
  8052. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  8053. {
  8054. json_object *sampledValue = json_object_new_object();
  8055. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  8056. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  8057. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  8058. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  8059. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  8060. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  8061. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  8062. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  8063. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  8064. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  8065. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  8066. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  8067. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  8068. json_object_array_add(sampledValues, sampledValue);
  8069. }
  8070. }
  8071. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  8072. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  8073. json_object_array_add(MeterValues, MeterValue);
  8074. }
  8075. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  8076. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  8077. ,gun_index + 1
  8078. ,MESSAGE_TYPE_CALL
  8079. ,guid
  8080. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8081. json_object_put(MeterValueReq);
  8082. }
  8083. // Put request guid to hash map
  8084. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8085. 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*/)
  8086. {
  8087. result = PASS;
  8088. //DEBUG_INFO("MeterValues mapitem pass\n");
  8089. }
  8090. if((dataType != ReadingContext_Trigger) &&
  8091. (dataType != ReadingContext_Sample_Clock) &&
  8092. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  8093. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  8094. else
  8095. {
  8096. if(FirstHeartBeat)
  8097. LWS_Send(queuedata +2);
  8098. }
  8099. return result;
  8100. }
  8101. int sendLogStatusNotificationRequest(char *status)
  8102. {
  8103. mtrace();
  8104. int result = PASS;
  8105. char message[4096]={0};
  8106. char guid[37]={0};
  8107. char tempdata[128]={0};
  8108. json_object *LogStatusNotification = json_object_new_object();
  8109. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  8110. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  8111. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  8112. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  8113. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  8114. random_uuid(guid);
  8115. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  8116. json_object_put(LogStatusNotification);
  8117. LWS_Send(message);
  8118. sprintf(tempdata, "LogStatusNotification,%d", 0);
  8119. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8120. {
  8121. result = PASS;
  8122. }
  8123. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  8124. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  8125. return result;
  8126. }
  8127. int sendSecurityEventNotificationRequest()
  8128. {
  8129. mtrace();
  8130. int result = PASS;
  8131. char message[4096]={0};
  8132. char guid[37]={0};
  8133. char tempdata[128]={0};
  8134. json_object *SecurityEventNotification = json_object_new_object();
  8135. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  8136. //Stop Transaction Time
  8137. struct timeval tmnow;
  8138. struct tm *tm;
  8139. gettimeofday(&tmnow, NULL);
  8140. time_t t;
  8141. t = time(NULL);
  8142. /*UTC time and date*/
  8143. tm = gmtime(&t);
  8144. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  8145. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  8146. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  8147. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  8148. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  8149. random_uuid(guid);
  8150. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  8151. json_object_put(SecurityEventNotification);
  8152. LWS_Send(message);
  8153. sprintf(tempdata, "SecurityEventNotification,0");
  8154. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8155. {
  8156. result = PASS;
  8157. }
  8158. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  8159. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  8160. return result;
  8161. }
  8162. int sendSignCertificateRequest()
  8163. {
  8164. mtrace();
  8165. int result = PASS;
  8166. char message[4096]={0};
  8167. char guid[37]={0};
  8168. char tempdata[128]={0};
  8169. json_object *SignCertificate = json_object_new_object();
  8170. DEBUG_INFO("sendSignCertificateRequest...\n");
  8171. // Read csr file content
  8172. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  8173. FILE *fp=fopen(CSR_CP,"r");
  8174. char *line = NULL;
  8175. size_t len = 0;
  8176. while(getline(&line, &len, fp) != -1)
  8177. {
  8178. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  8179. {
  8180. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  8181. }
  8182. }
  8183. fclose(fp);
  8184. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  8185. random_uuid(guid);
  8186. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  8187. json_object_put(SignCertificate);
  8188. LWS_Send(message);
  8189. sprintf(tempdata, "SignCertificate,0");
  8190. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8191. {
  8192. result = PASS;
  8193. }
  8194. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  8195. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  8196. return result;
  8197. }
  8198. int sendSignedFirmwareStatusNotificationRequest(char *status)
  8199. {
  8200. mtrace();
  8201. int result = PASS;
  8202. char message[4096]={0};
  8203. char guid[37]={0};
  8204. char tempdata[128]={0};
  8205. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  8206. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  8207. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  8208. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  8209. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  8210. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  8211. random_uuid(guid);
  8212. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8213. json_object_put(SignedFirmwareStatusNotification);
  8214. LWS_Send(message);
  8215. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  8216. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8217. {
  8218. result = PASS;
  8219. }
  8220. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  8221. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  8222. return result;
  8223. }
  8224. //==========================================
  8225. // send confirm routine
  8226. //==========================================
  8227. int sendCancelReservationConfirmation(char *uuid,char *payload)
  8228. {
  8229. mtrace();
  8230. int result = FAIL;
  8231. char message[100]={0};
  8232. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8233. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8234. LWS_Send(message);
  8235. result = TRUE;
  8236. return result;
  8237. }
  8238. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8239. {
  8240. mtrace();
  8241. int result = FAIL;
  8242. char message[100]={0};
  8243. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8244. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8245. LWS_Send(message);
  8246. result = TRUE;
  8247. return result;
  8248. }
  8249. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8250. {
  8251. mtrace();
  8252. int result = FAIL;
  8253. char message[100]={0};
  8254. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8255. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8256. LWS_Send(message);
  8257. result = TRUE;
  8258. return result;
  8259. }
  8260. int sendClearCacheConfirmation(char *uuid,char *payload)
  8261. {
  8262. mtrace();
  8263. int result = FAIL;
  8264. char message[500]={0};
  8265. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8266. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8267. LWS_Send(message);
  8268. return result;
  8269. }
  8270. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8271. {
  8272. mtrace();
  8273. int result = FAIL;
  8274. char message[500]={0};
  8275. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8276. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8277. LWS_Send(message);
  8278. return result;
  8279. }
  8280. int sendDataTransferConfirmation(char *uuid,char *payload)
  8281. {
  8282. mtrace();
  8283. char statusStr[20]={0};
  8284. char dataStr[10]={0};
  8285. char sstr[20]={0};
  8286. int c = 0;
  8287. char *loc;
  8288. int result = FAIL;
  8289. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8290. /**********************status**************************/
  8291. loc = strstr(payload, "status");
  8292. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8293. c = 0;
  8294. while (loc[3+strlen("status")+c] != '\"')
  8295. {
  8296. sstr[c] = loc[3+strlen("status")+c];
  8297. c++;
  8298. }
  8299. sstr[c] = '\0';
  8300. strcpy(statusStr, sstr);
  8301. /**********************data**************************/
  8302. loc = strstr(payload, "data");
  8303. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8304. c = 0;
  8305. while (loc[3+strlen("data")+c] != '\"')
  8306. {
  8307. sstr[c] = loc[3+strlen("data")+c];
  8308. c++;
  8309. }
  8310. sstr[c] = '\0';
  8311. strcpy(dataStr, sstr);
  8312. return result;
  8313. }
  8314. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8315. {
  8316. mtrace();
  8317. int result = FAIL;
  8318. char message[1000]={0};
  8319. int CompositeScheduleIndex = 0;
  8320. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8321. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8322. if(nPeriod == 0)
  8323. {
  8324. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8325. {
  8326. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8327. ,MESSAGE_TYPE_CALLRESULT
  8328. ,uuid
  8329. ,payload
  8330. ,connectorIdInt);
  8331. }
  8332. else
  8333. {
  8334. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8335. ,MESSAGE_TYPE_CALLRESULT
  8336. ,uuid
  8337. ,payload
  8338. ,connectorIdInt
  8339. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8340. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8341. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8342. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8343. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8344. }
  8345. }
  8346. else
  8347. {
  8348. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8349. ,MESSAGE_TYPE_CALLRESULT
  8350. ,uuid
  8351. ,payload
  8352. ,connectorIdInt
  8353. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8354. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8355. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8356. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8357. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8358. {
  8359. if (idx_sample == 0)
  8360. {
  8361. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8362. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8363. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8364. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8365. }
  8366. else
  8367. {
  8368. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8369. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8370. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8371. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8372. }
  8373. }
  8374. sprintf(message + strlen(message), "]}}]");
  8375. }
  8376. LWS_Send(message);
  8377. result = TRUE;
  8378. return result;
  8379. }
  8380. int sendGetConfigurationConfirmation(char *uuid)
  8381. {
  8382. mtrace();
  8383. int result = FAIL;
  8384. int MaxKeySupported = 0;
  8385. int sentConfigurationNumber= 0;
  8386. int sentunConfigurationNumber= 0;
  8387. char message[1024*10]={0};
  8388. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8389. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8390. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8391. ,MESSAGE_TYPE_CALLRESULT
  8392. ,uuid );
  8393. //configuration key
  8394. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8395. {
  8396. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8397. {
  8398. if (sentConfigurationNumber == 0)
  8399. {
  8400. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8401. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8402. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8403. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8404. }
  8405. else
  8406. {
  8407. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8408. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8409. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8410. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8411. }
  8412. sentConfigurationNumber = sentConfigurationNumber + 1;
  8413. }
  8414. }
  8415. sprintf(message + strlen(message), "]");
  8416. if(UnknownKeynum != 0)
  8417. {
  8418. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8419. //unkown key
  8420. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8421. {
  8422. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8423. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8424. if(sentunConfigurationNumber == 0)
  8425. {
  8426. sprintf(message + strlen(message), "\"%s\""
  8427. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8428. }
  8429. else
  8430. {
  8431. sprintf(message + strlen(message), ",\"%s\""
  8432. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8433. }
  8434. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8435. }
  8436. sprintf(message + strlen(message), "]");
  8437. }
  8438. sprintf(message + strlen(message), "}]");
  8439. LWS_Send(message);
  8440. return result;
  8441. }
  8442. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8443. {
  8444. mtrace();
  8445. int result = FAIL;
  8446. char message[400]={0};
  8447. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8448. if(strcmp(payload,"")==0)
  8449. {
  8450. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8451. }
  8452. else
  8453. {
  8454. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8455. }
  8456. LWS_Send(message);
  8457. result = TRUE;
  8458. return result;
  8459. }
  8460. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8461. {
  8462. mtrace();
  8463. int result = FAIL;
  8464. char message[80]={0};
  8465. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8466. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8467. LWS_Send(message);
  8468. result = TRUE;
  8469. return result;
  8470. }
  8471. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8472. {
  8473. mtrace();
  8474. int result = FAIL;
  8475. char message[80]={0};
  8476. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8477. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8478. LWS_Send(message);
  8479. result = TRUE;
  8480. return result;
  8481. }
  8482. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8483. {
  8484. mtrace();
  8485. int result = FAIL;
  8486. char message[80]={0};
  8487. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8488. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8489. LWS_Send(message);
  8490. result = TRUE;
  8491. return result;
  8492. }
  8493. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8494. {
  8495. mtrace();
  8496. int result = FAIL;
  8497. char message[80]={0};
  8498. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8499. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8500. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8501. LWS_Send(message);
  8502. result = TRUE;
  8503. return result;
  8504. }
  8505. int sendResetConfirmation(char *uuid,char *payload)
  8506. {
  8507. mtrace();
  8508. int result = FAIL;
  8509. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8510. char message[80]={0};
  8511. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8512. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8513. LWS_Send(message);
  8514. result = TRUE;
  8515. return result;
  8516. }
  8517. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8518. {
  8519. mtrace();
  8520. int result = FAIL;
  8521. char message[500]={0};
  8522. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8523. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8524. LWS_Send(message);
  8525. result = TRUE;
  8526. return result;
  8527. }
  8528. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8529. {
  8530. mtrace();
  8531. int result = FAIL;
  8532. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8533. char message[80]={0};
  8534. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8535. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8536. LWS_Send(message);
  8537. result = TRUE;
  8538. return result;
  8539. }
  8540. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8541. {
  8542. mtrace();
  8543. int result = FAIL;
  8544. char message[80]={0};
  8545. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8546. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8547. LWS_Send(message);
  8548. result = TRUE;
  8549. return result;
  8550. }
  8551. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8552. {
  8553. mtrace();
  8554. int result = FAIL;
  8555. char message[80]={0};
  8556. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8557. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8558. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8559. LWS_Send(message);
  8560. result = TRUE;
  8561. return result;
  8562. }
  8563. int sendUpdateFirmwareConfirmation(char *uuid)
  8564. {
  8565. mtrace();
  8566. int result = FAIL;
  8567. char message[60]={0};
  8568. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8569. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8570. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8571. LWS_Send(message);
  8572. result = TRUE;
  8573. return result;
  8574. }
  8575. int sendCertificateSignedConfirmation(char *uuid)
  8576. {
  8577. mtrace();
  8578. int result = PASS;
  8579. char message[4096]={0};
  8580. json_object *CertificateSigned = json_object_new_object();
  8581. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8582. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8583. sprintf(message,"[%d,\"%s\",%s]"
  8584. ,MESSAGE_TYPE_CALLRESULT
  8585. ,uuid
  8586. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8587. json_object_put(CertificateSigned);
  8588. LWS_Send(message);
  8589. return result;
  8590. }
  8591. int sendDeleteCertificateConfirmation(char *uuid)
  8592. {
  8593. mtrace();
  8594. int result = PASS;
  8595. char message[4096]={0};
  8596. json_object *DeleteCertificate = json_object_new_object();
  8597. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8598. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8599. sprintf(message,"[%d,\"%s\",%s]"
  8600. ,MESSAGE_TYPE_CALLRESULT
  8601. ,uuid
  8602. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8603. json_object_put(DeleteCertificate);
  8604. LWS_Send(message);
  8605. return result;
  8606. }
  8607. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8608. {
  8609. mtrace();
  8610. int result = PASS;
  8611. char message[4096]={0};
  8612. json_object *ExtendedTriggerMessage = json_object_new_object();
  8613. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8614. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8615. sprintf(message,"[%d,\"%s\",%s]"
  8616. ,MESSAGE_TYPE_CALLRESULT
  8617. ,uuid
  8618. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8619. json_object_put(ExtendedTriggerMessage);
  8620. LWS_Send(message);
  8621. return result;
  8622. }
  8623. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8624. {
  8625. mtrace();
  8626. int result = PASS;
  8627. char message[4096]={0};
  8628. json_object *GetInstalledCertificateIds = json_object_new_object();
  8629. json_object *certificateHashDataDatas = json_object_new_array();
  8630. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8631. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8632. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8633. {
  8634. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8635. {
  8636. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8637. {
  8638. json_object *certificateHashData = json_object_new_object();
  8639. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8640. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8641. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8642. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8643. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8644. }
  8645. }
  8646. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8647. }
  8648. else
  8649. {
  8650. json_object_put(certificateHashDataDatas);
  8651. }
  8652. sprintf(message,"[%d,\"%s\",%s]"
  8653. ,MESSAGE_TYPE_CALLRESULT
  8654. ,uuid
  8655. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8656. json_object_put(GetInstalledCertificateIds);
  8657. LWS_Send(message);
  8658. return result;
  8659. }
  8660. int sendGetLogConfirmation(char *uuid)
  8661. {
  8662. mtrace();
  8663. int result = PASS;
  8664. char message[4096]={0};
  8665. json_object *GetLog = json_object_new_object();
  8666. DEBUG_INFO("sendGetLogConfirmation...\n");
  8667. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8668. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8669. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8670. sprintf(message,"[%d,\"%s\",%s]"
  8671. ,MESSAGE_TYPE_CALLRESULT
  8672. ,uuid
  8673. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8674. json_object_put(GetLog);
  8675. LWS_Send(message);
  8676. return result;
  8677. }
  8678. int sendInstallCertificateConfirmation(char *uuid)
  8679. {
  8680. mtrace();
  8681. int result = PASS;
  8682. char message[4096]={0};
  8683. json_object *InstallCertificate = json_object_new_object();
  8684. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8685. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8686. sprintf(message,"[%d,\"%s\",%s]"
  8687. ,MESSAGE_TYPE_CALLRESULT
  8688. ,uuid
  8689. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8690. json_object_put(InstallCertificate);
  8691. LWS_Send(message);
  8692. return result;
  8693. }
  8694. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8695. {
  8696. mtrace();
  8697. int result = PASS;
  8698. char message[4096]={0};
  8699. json_object *SignedUpdateFirmware = json_object_new_object();
  8700. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8701. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8702. sprintf(message,"[%d,\"%s\",%s]"
  8703. ,MESSAGE_TYPE_CALLRESULT
  8704. ,uuid
  8705. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8706. json_object_put(SignedUpdateFirmware);
  8707. LWS_Send(message);
  8708. return result;
  8709. }
  8710. int sendUnknownConfirmation(char *uuid)
  8711. {
  8712. mtrace();
  8713. int result = PASS;
  8714. char message[256]={0};
  8715. DEBUG_INFO("sendUnknownConfirmation...\n");
  8716. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8717. LWS_Send(message);
  8718. return result;
  8719. }
  8720. //==========================================
  8721. // Handle server request routine Start
  8722. //==========================================
  8723. int handleCancelReservationRequest(char *uuid, char *payload)
  8724. {
  8725. mtrace();
  8726. int result = FAIL;
  8727. int gunNO = 0;
  8728. int reservationIdInt = -1;
  8729. char comfirmstr[20];
  8730. DEBUG_INFO("handleCancelReservationRequest...\n");
  8731. json_object *CancelReservation;
  8732. CancelReservation = json_tokener_parse(payload);
  8733. if(!is_error(CancelReservation))
  8734. {
  8735. // Required data
  8736. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8737. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8738. }
  8739. json_object_put(CancelReservation);
  8740. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8741. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8742. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8743. if(reservationIdInt != -1)
  8744. {
  8745. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8746. //check Transaction active
  8747. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8748. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8749. {
  8750. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8751. {
  8752. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8753. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8754. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8755. {
  8756. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8757. }
  8758. else
  8759. {
  8760. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8761. }
  8762. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8763. goto end;
  8764. }
  8765. }
  8766. for (int index = 0; index < CCS_QUANTITY; index++)
  8767. {
  8768. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8769. {
  8770. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8771. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8772. if(gunType[2] == GUN_TYPE_CCS)
  8773. {
  8774. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8775. }
  8776. else
  8777. {
  8778. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8779. }
  8780. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8781. goto end;
  8782. }
  8783. }
  8784. for (int index = 0; index < GB_QUANTITY; index++)
  8785. {
  8786. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8787. {
  8788. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8789. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8790. if(gunType[2] == GUN_TYPE_GBT)
  8791. {
  8792. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8793. }
  8794. else
  8795. {
  8796. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8797. }
  8798. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8799. goto end;
  8800. }
  8801. }
  8802. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8803. {
  8804. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8805. {
  8806. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8807. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8808. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8809. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8810. goto end;
  8811. }
  8812. }
  8813. for (int index = 0; index < AC_QUANTITY; index++)
  8814. {
  8815. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8816. {
  8817. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8818. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8819. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8820. {
  8821. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8822. }
  8823. else
  8824. {
  8825. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8826. }
  8827. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8828. goto end;
  8829. }
  8830. }
  8831. }
  8832. //The reservationId does NOT match the reservationId
  8833. sendCancelReservationConfirmation(uuid, comfirmstr);
  8834. end:
  8835. // Fill in ocpp packet uuid
  8836. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8837. return result;
  8838. }
  8839. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8840. {
  8841. mtrace();
  8842. int result = FAIL;
  8843. int gunIndex = -1;
  8844. char typeStr[16]={0};
  8845. char comfirmstr[20];
  8846. int specificId = FALSE;
  8847. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8848. json_object *ChangeAvailability;
  8849. ChangeAvailability = json_tokener_parse(payload);
  8850. if(!is_error(ChangeAvailability))
  8851. {
  8852. // Required data
  8853. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8854. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8855. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8856. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8857. }
  8858. json_object_put(ChangeAvailability);
  8859. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8860. {
  8861. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8862. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8863. }
  8864. else if(gunIndex == 0)
  8865. {
  8866. for(int i=0; i < gunTotalNumber; i++)
  8867. {
  8868. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8869. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8870. }
  8871. }
  8872. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8873. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8874. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8875. {
  8876. specificId = TRUE;
  8877. }
  8878. if(specificId == FALSE)
  8879. goto end;
  8880. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8881. {
  8882. //----------------------gunIndex is 0 ------------------------------------------------//
  8883. if(gunIndex == 0)
  8884. {
  8885. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8886. {
  8887. for(int i=0; i < gunTotalNumber; i++)
  8888. {
  8889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8890. {
  8891. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8892. {
  8893. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8894. {
  8895. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8896. goto end;
  8897. }
  8898. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8899. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8900. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8901. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8902. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8903. {
  8904. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8905. goto end;
  8906. }
  8907. }
  8908. }//END FOR CHAdeMO_QUANTITY
  8909. for (int index = 0; index < CCS_QUANTITY; index++)
  8910. {
  8911. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8912. {
  8913. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8914. {
  8915. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8916. goto end;
  8917. }
  8918. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8919. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8920. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8921. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8922. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8923. {
  8924. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8925. goto end;
  8926. }
  8927. }
  8928. }//END FOR CCS_QUANTITY
  8929. for (int index = 0; index < GB_QUANTITY; index++)
  8930. {
  8931. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8932. {
  8933. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8934. {
  8935. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8936. goto end;
  8937. }
  8938. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8939. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8940. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8941. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8942. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8943. {
  8944. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8945. goto end;
  8946. }
  8947. }
  8948. }// END FOR GB_QUANTITY
  8949. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8950. {
  8951. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8952. {
  8953. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8954. {
  8955. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8956. goto end;
  8957. }
  8958. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8959. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8960. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8961. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8962. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8963. {
  8964. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8965. goto end;
  8966. }
  8967. }
  8968. }// END FOR GENERAL_GUN_QUANTITY
  8969. for (int index = 0; index < AC_QUANTITY; index++)
  8970. {
  8971. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8972. {
  8973. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8974. {
  8975. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8976. goto end;
  8977. }
  8978. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8979. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8980. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8981. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8982. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8983. {
  8984. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8985. goto end;
  8986. }
  8987. }
  8988. }//END FOR AC_QUANTITY
  8989. }// END FOR gunTotalNumber
  8990. }
  8991. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8992. {
  8993. for(int i=0; i < gunTotalNumber; i++)
  8994. {
  8995. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8996. {
  8997. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8998. goto end;
  8999. }
  9000. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9001. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  9002. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  9003. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  9004. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9005. {
  9006. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9007. goto end;
  9008. }
  9009. }
  9010. }
  9011. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9012. goto end;
  9013. }
  9014. //----------------------gunIndex is not 0 ------------------------------------------------//
  9015. //check Transaction active
  9016. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9017. {
  9018. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  9019. {
  9020. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  9021. {
  9022. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9023. goto end;
  9024. }
  9025. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9026. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9027. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9028. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9029. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9030. {
  9031. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9032. goto end;
  9033. }
  9034. else
  9035. {
  9036. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  9037. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9038. goto end;
  9039. }
  9040. }
  9041. }//END FOR CHAdeMO_QUANTITY
  9042. for (int index = 0; index < CCS_QUANTITY; index++)
  9043. {
  9044. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  9045. {
  9046. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  9047. {
  9048. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9049. goto end;
  9050. }
  9051. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9052. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9053. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9054. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9055. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9056. {
  9057. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9058. goto end;
  9059. }
  9060. else
  9061. {
  9062. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  9063. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9064. goto end;
  9065. }
  9066. }
  9067. }//END FOR CCS_QUANTITY
  9068. for (int index = 0; index < GB_QUANTITY; index++)
  9069. {
  9070. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  9071. {
  9072. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9073. {
  9074. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9075. goto end;
  9076. }
  9077. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9078. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9079. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9080. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9081. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9082. {
  9083. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9084. goto end;
  9085. }
  9086. else
  9087. {
  9088. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  9089. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9090. goto end;
  9091. }
  9092. }
  9093. }// END FOR GB_QUANTITY
  9094. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9095. {
  9096. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  9097. {
  9098. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9099. {
  9100. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9101. goto end;
  9102. }
  9103. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9104. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9105. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9106. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9107. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9108. {
  9109. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9110. goto end;
  9111. }
  9112. else
  9113. {
  9114. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  9115. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9116. goto end;
  9117. }
  9118. }
  9119. }// END FOR GENERAL_GUN_QUANTITY
  9120. for (int index = 0; index < AC_QUANTITY; index++)
  9121. {
  9122. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  9123. {
  9124. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9125. {
  9126. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9127. goto end;
  9128. }
  9129. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9130. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9131. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9132. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9133. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9134. {
  9135. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9136. goto end;
  9137. }
  9138. else
  9139. {
  9140. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  9141. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9142. goto end;
  9143. }
  9144. }
  9145. }//END FOR AC_QUANTITY
  9146. }//END FOR AvailabilityTypeStr[Inoperative]
  9147. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  9148. {
  9149. //----------------------gunIndex is 0 ------------------------------------------------//
  9150. if(gunIndex == 0)
  9151. {
  9152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9153. {
  9154. for(int i=0; i < gunTotalNumber; i++)
  9155. {
  9156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9157. {
  9158. 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
  9159. {
  9160. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9161. goto end;
  9162. }
  9163. }//END FOR CHAdeMO_QUANTITY
  9164. for (int index = 0; index < CCS_QUANTITY; index++)
  9165. {
  9166. 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
  9167. {
  9168. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9169. goto end;
  9170. }
  9171. }//END FOR CCS_QUANTITY
  9172. for (int index = 0; index < GB_QUANTITY; index++)
  9173. {
  9174. 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
  9175. {
  9176. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9177. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9178. goto end;
  9179. }
  9180. }// END FOR GB_QUANTITY
  9181. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9182. {
  9183. 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
  9184. {
  9185. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9186. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9187. goto end;
  9188. }
  9189. }// END FOR GENERAL_GUN_QUANTITY
  9190. for (int index = 0; index < AC_QUANTITY; index++)
  9191. {
  9192. 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
  9193. {
  9194. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9195. goto end;
  9196. }
  9197. }//END FOR CHAdeMO_QUANTITY
  9198. }// END FOR gunTotalNumber
  9199. }
  9200. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9201. {
  9202. for(int i=0; i < gunTotalNumber; i++)
  9203. {
  9204. for (int index = 0; index < AC_QUANTITY; index++)
  9205. {
  9206. 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
  9207. {
  9208. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9209. goto end;
  9210. }
  9211. }//END FOR CHAdeMO_QUANTITY
  9212. } // END FOR gunTotalNumber
  9213. }
  9214. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9215. goto end;
  9216. }
  9217. //----------------------gunIndex is not 0 ------------------------------------------------//
  9218. //check Transaction active
  9219. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9220. {
  9221. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9222. {
  9223. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9224. goto end;
  9225. }
  9226. }//END FOR CHAdeMO_QUANTITY
  9227. for (int index = 0; index < CCS_QUANTITY; index++)
  9228. {
  9229. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9230. {
  9231. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9232. goto end;
  9233. }
  9234. }//END FOR CCS_QUANTITY
  9235. for (int index = 0; index < GB_QUANTITY; index++)
  9236. {
  9237. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9238. {
  9239. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9240. goto end;
  9241. }
  9242. }// END FOR GB_QUANTITY
  9243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9244. {
  9245. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9246. {
  9247. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9248. goto end;
  9249. }
  9250. }// END FOR GENERAL_GUN_QUANTITY
  9251. for (int index = 0; index < AC_QUANTITY; index++)
  9252. {
  9253. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9254. {
  9255. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9256. goto end;
  9257. }
  9258. }//END FOR AC_QUANTITY
  9259. }//END FOR AvailabilityTypeStr[Operative]
  9260. end:
  9261. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9262. {
  9263. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9264. }
  9265. else
  9266. {
  9267. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9268. }
  9269. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9270. {
  9271. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9272. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9273. }
  9274. else if(gunIndex == 0)
  9275. {
  9276. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9277. {
  9278. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9279. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9280. }
  9281. }
  9282. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9283. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9284. return result;
  9285. }
  9286. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9287. {
  9288. mtrace();
  9289. int valueInvalid = NO;
  9290. int result = FAIL;
  9291. char keystr[40]={0};
  9292. char valuestr[501]={0}; //value should be limited in 500 bytes
  9293. char comfirmstr[20]={0};
  9294. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9295. json_object *ChangeConfiguration;
  9296. ChangeConfiguration = json_tokener_parse(payload);
  9297. if(!is_error(ChangeConfiguration))
  9298. {
  9299. // Required data
  9300. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9301. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9302. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9303. {
  9304. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9305. }
  9306. else
  9307. {
  9308. valueInvalid = YES;
  9309. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9310. }
  9311. }
  9312. json_object_put(ChangeConfiguration);
  9313. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9314. {
  9315. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9316. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9317. }
  9318. else
  9319. {
  9320. int status = setKeyValue(keystr, valuestr);
  9321. switch(status)
  9322. {
  9323. case ConfigurationStatus_Accepted:
  9324. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9325. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9326. StoreConfigurationTable();
  9327. break;
  9328. case RebootRequired:
  9329. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9330. StoreConfigurationTable();
  9331. break;
  9332. case NotSupported:
  9333. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9334. break;
  9335. case ConfigurationStatus_Rejected:
  9336. default:
  9337. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9338. break;
  9339. }
  9340. }
  9341. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9342. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9343. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9344. {
  9345. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9346. SetOcppConnStatus(FALSE);
  9347. }
  9348. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9349. {
  9350. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9351. }
  9352. return result;
  9353. }
  9354. int handleClearCacheRequest(char *uuid, char *payload)
  9355. {
  9356. mtrace();
  9357. int result = FAIL;
  9358. char comfirmstr[20];
  9359. char rmFileCmd[100]={0};
  9360. struct stat stats;
  9361. DEBUG_INFO("handleClearCacheRequest...\n");
  9362. stat("/Storage/OCPP", &stats);
  9363. // Check for directory existence
  9364. if (S_ISDIR(stats.st_mode) == 1)
  9365. {}
  9366. else
  9367. {
  9368. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9369. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9370. system(rmFileCmd);
  9371. }
  9372. if(OCPP_cleanLocalCache())
  9373. {
  9374. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9375. }
  9376. else
  9377. {
  9378. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9379. }
  9380. sendClearCacheConfirmation(uuid, comfirmstr);
  9381. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9382. return result;
  9383. }
  9384. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9385. {
  9386. mtrace();
  9387. int result = FAIL;
  9388. int resultRename;
  9389. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9390. char chargingProfilePurposeStr[26]={0};
  9391. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9392. char tempchargingProfilePurposeStr[26]={0};
  9393. char str[100]={0};
  9394. char fname[200]={0};
  9395. char comfirmstr[20]={0};
  9396. char word[1600]={0};
  9397. int clearflag = FALSE;
  9398. int chargingProfileIdIsNULL = FALSE;
  9399. int connectorIsNULL = FALSE;
  9400. int chargingProfilePurposeIsNULL = FALSE;
  9401. int stackLevelIsNULL = FALSE;
  9402. //int GotoEnd = FALSE;
  9403. FILE *fptr1, *fptr2;
  9404. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9405. int n_chargingProfile=0;
  9406. int isEmptyFile = FALSE;
  9407. char sLineWord[1600]={0};
  9408. char chargingProfiles[10][100]={0};
  9409. int ChargeProfileCount = 0;
  9410. int ch;
  9411. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9412. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9413. json_object *ClearChargingProfile;
  9414. ClearChargingProfile = json_tokener_parse(payload);
  9415. if(!is_error(ClearChargingProfile))
  9416. {
  9417. // Optional data
  9418. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9419. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9420. else
  9421. chargingProfileIdIsNULL = TRUE;
  9422. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9423. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9424. else
  9425. connectorIsNULL = TRUE;
  9426. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9427. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9428. else
  9429. chargingProfilePurposeIsNULL = TRUE;
  9430. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9431. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9432. else
  9433. stackLevelIsNULL = TRUE;
  9434. }
  9435. json_object_put(ClearChargingProfile);
  9436. if(connectorIsNULL == FALSE)
  9437. {
  9438. switch(connectorIdInt)
  9439. {
  9440. case 0:
  9441. if(chargingProfilePurposeIsNULL == TRUE)
  9442. {
  9443. int l = 0;
  9444. strcpy(fname, ChargePointMaxProfile_JSON);
  9445. if((access(fname,F_OK))!=-1)
  9446. {
  9447. strcpy(chargingProfiles[l], fname);
  9448. l = l + 1;
  9449. }
  9450. strcpy(fname, TxDefaultProfile_0_JSON);
  9451. if((access(fname,F_OK))!=-1)
  9452. {
  9453. strcpy(chargingProfiles[l], fname);
  9454. l = l + 1;
  9455. }
  9456. ChargeProfileCount = l;
  9457. }
  9458. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9459. {
  9460. strcpy(fname, ChargePointMaxProfile_JSON);
  9461. if((access(fname,F_OK))!=-1)
  9462. {
  9463. strcpy(chargingProfiles[0], fname);
  9464. ChargeProfileCount = 1;
  9465. }
  9466. }
  9467. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9468. {
  9469. strcpy(fname, TxDefaultProfile_0_JSON);
  9470. if((access(fname,F_OK))!=-1)
  9471. {
  9472. strcpy(chargingProfiles[0], fname);
  9473. ChargeProfileCount = 1;
  9474. }
  9475. }
  9476. break;
  9477. default:
  9478. if(chargingProfilePurposeIsNULL == TRUE)
  9479. {
  9480. int m = 0;
  9481. memset(fname, 0, ARRAY_SIZE(fname));
  9482. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9483. if((access(fname,F_OK))!=-1)
  9484. {
  9485. strcpy(chargingProfiles[m], fname);
  9486. m = m + 1;
  9487. }
  9488. memset(fname, 0, ARRAY_SIZE(fname));
  9489. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9490. if((access(fname,F_OK))!=-1)
  9491. {
  9492. strcpy(chargingProfiles[m], fname);
  9493. m = m + 1;
  9494. }
  9495. ChargeProfileCount = m;
  9496. }
  9497. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9498. {
  9499. //strcpy(fname, TxDefaultProfile_1_JSON);
  9500. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9501. if((access(fname,F_OK))!=-1)
  9502. {
  9503. strcpy(chargingProfiles[0], fname);
  9504. ChargeProfileCount = 1;
  9505. }
  9506. }
  9507. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9508. {
  9509. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9510. if((access(fname,F_OK))!=-1)
  9511. {
  9512. strcpy(chargingProfiles[0], fname);
  9513. ChargeProfileCount = 1;
  9514. }
  9515. //strcpy(fname, TxProfile_1_JSON);
  9516. }
  9517. //strcpy(fname, ChargePointMaxProfile_JSON );
  9518. break;
  9519. }
  9520. }
  9521. else // Check all Charging Profiles
  9522. {
  9523. int i = 0;
  9524. char fnametemp[200]={0};
  9525. ChargeProfileCount = 0;
  9526. //Check ChargePointMaxProfile.json exit
  9527. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9528. {
  9529. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9530. i = i + 1;
  9531. }
  9532. //Check TxDefaultProfile_0.json exit
  9533. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9534. {
  9535. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9536. i = i + 1;
  9537. }
  9538. //Check TxDefaultProfile_%d.json
  9539. for(int j=1; j <= gunTotalNumber; j++)
  9540. {
  9541. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9542. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9543. if((access(fnametemp,F_OK))!=-1)
  9544. {
  9545. strcpy(chargingProfiles[i], fnametemp);
  9546. i = i + 1;
  9547. }
  9548. }
  9549. //Check TxProfile_%d.json
  9550. for(int j=1; j <= gunTotalNumber; j++)
  9551. {
  9552. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9553. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9554. if((access(fnametemp,F_OK))!=-1)
  9555. {
  9556. strcpy(chargingProfiles[i], fnametemp);
  9557. i = i + 1;
  9558. }
  9559. }
  9560. ChargeProfileCount = i;
  9561. }// End connectorIsNULL is TRUE
  9562. if(ChargeProfileCount == 0)
  9563. {
  9564. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9565. goto end;
  9566. }
  9567. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9568. {
  9569. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9570. goto end;
  9571. }
  9572. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9573. {
  9574. memset(str, 0, ARRAY_SIZE(str));
  9575. // clear temp file
  9576. sprintf(str,"rm -f %s",temp);
  9577. system(str);
  9578. for(int k=0; k < ChargeProfileCount; k++)
  9579. {
  9580. memset(str, 0, ARRAY_SIZE(str));
  9581. //clear file in C
  9582. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9583. system(str);
  9584. }
  9585. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9586. goto end;
  9587. }
  9588. else if(connectorIsNULL == TRUE)
  9589. {
  9590. for(int k=0; k < ChargeProfileCount; k++)
  9591. {
  9592. fptr1 = fopen(chargingProfiles[k], "r");
  9593. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9594. //Check Charging Profile Count
  9595. while(fscanf(fptr1, "%s", word) != EOF)
  9596. {
  9597. //DEBUG_INFO("word=%s\n",word);
  9598. if(strstr(word, "chargingProfileId")!= NULL)
  9599. {
  9600. //DEBUG_INFO("test chargingProfileId \n");
  9601. n_chargingProfile = n_chargingProfile + 1;
  9602. //DEBUG_INFO("chargingProfileId Found\n");
  9603. }
  9604. }
  9605. rewind(fptr1);
  9606. //search Charging Profile Element
  9607. //int i= 0;
  9608. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9609. {
  9610. json_object *tmpProfilee;
  9611. tmpProfilee = json_tokener_parse(sLineWord);
  9612. if(!is_error(tmpProfilee))
  9613. {
  9614. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9615. {
  9616. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9617. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9618. }
  9619. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9620. {
  9621. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9622. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9623. }
  9624. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9625. {
  9626. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9627. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9628. }
  9629. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9630. {
  9631. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9632. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9633. }
  9634. }
  9635. json_object_put(tmpProfilee);
  9636. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9637. {
  9638. //------- not write to fptr2-------//
  9639. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9640. //clearflag = TRUE;
  9641. }
  9642. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9643. {
  9644. //------- not write to fptr2-------//
  9645. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9646. }
  9647. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9648. {
  9649. //------- not write to fptr2-------//
  9650. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9651. }
  9652. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9653. {
  9654. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9655. }
  9656. else
  9657. {
  9658. fprintf(fptr2, sLineWord);//writing data into file
  9659. }
  9660. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9661. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9662. if(clearflag == TRUE)
  9663. {
  9664. fclose(fptr1);
  9665. fclose(fptr2);
  9666. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9667. system(str);
  9668. // clear temp file
  9669. sprintf(str,"rm -f %s",temp);
  9670. system(str);
  9671. }
  9672. else
  9673. {
  9674. fclose(fptr1);
  9675. fclose(fptr2);
  9676. memset(str, 0, ARRAY_SIZE(str));
  9677. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9678. system(str);
  9679. resultRename = rename(temp, chargingProfiles[k]);
  9680. if(resultRename == 0)
  9681. {
  9682. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9683. }
  9684. else
  9685. {
  9686. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9687. }
  9688. if(comfirmstr[0]== 0)
  9689. {
  9690. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9691. }
  9692. //Check chargingProfile is empty file
  9693. /*------ Read the file ----------------*/
  9694. fptr1=fopen(chargingProfiles[k],"r");
  9695. ch=fgetc(fptr1);
  9696. rewind(fptr1);
  9697. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9698. if(ch!=EOF)
  9699. {
  9700. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9701. {
  9702. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9703. if(sLineWord[0]=='\0')
  9704. {
  9705. isEmptyFile = TRUE;
  9706. break;
  9707. }
  9708. else
  9709. {
  9710. isEmptyFile = FALSE;
  9711. break;
  9712. }
  9713. }
  9714. }
  9715. else
  9716. isEmptyFile = TRUE;
  9717. fclose(fptr1);
  9718. if(isEmptyFile == TRUE)
  9719. {
  9720. memset(str, 0, ARRAY_SIZE(str));
  9721. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9722. system(str);
  9723. }
  9724. }
  9725. }// End of while(int k=0; k < ChargePointCount; k++)
  9726. }
  9727. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9728. {
  9729. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9730. for(int k=0; k < ChargeProfileCount; k++)
  9731. {
  9732. fptr1 = fopen(chargingProfiles[k], "r");
  9733. fptr2 = fopen(temp, "w+");
  9734. //Check Charging Profile Count
  9735. while(fscanf(fptr1, "%s", word) != EOF)
  9736. {
  9737. //DEBUG_INFO("word=%s\n",word);
  9738. if(strstr(word, "chargingProfileId")!= NULL)
  9739. {
  9740. n_chargingProfile = n_chargingProfile + 1;
  9741. }
  9742. }
  9743. rewind(fptr1);
  9744. //search Charging Profile Element
  9745. //int i= 0;
  9746. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9747. {
  9748. json_object *tmpProfilee;
  9749. tmpProfilee = json_tokener_parse(sLineWord);
  9750. if(!is_error(tmpProfilee))
  9751. {
  9752. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9753. {
  9754. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9755. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9756. }
  9757. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9758. {
  9759. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9760. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9761. }
  9762. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9763. {
  9764. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9765. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9766. }
  9767. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9768. {
  9769. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9770. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9771. }
  9772. }
  9773. json_object_put(tmpProfilee);
  9774. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9775. {
  9776. //------- not write to fptr2-------//
  9777. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9778. //clearflag = TRUE;
  9779. }
  9780. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9781. {
  9782. //------- not write to fptr2-------//
  9783. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9784. }
  9785. else if(stackLevelIsNULL == TRUE)
  9786. {
  9787. //Clear Whole File
  9788. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9789. clearflag = TRUE;
  9790. break;
  9791. }
  9792. else
  9793. {
  9794. fprintf(fptr2, sLineWord);//writing data into file
  9795. }
  9796. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9797. }
  9798. if(clearflag == TRUE)
  9799. {
  9800. fclose(fptr1);
  9801. fclose(fptr2);
  9802. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9803. system(str);
  9804. // clear temp file
  9805. sprintf(str,"rm -f %s",temp);
  9806. system(str);
  9807. }
  9808. else
  9809. {
  9810. fclose(fptr1);
  9811. fclose(fptr2);
  9812. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9813. system(str);
  9814. resultRename = rename(temp, chargingProfiles[k]);
  9815. if(resultRename == 0)
  9816. {
  9817. DEBUG_INFO("File ChargingProfile renamed successfully");
  9818. }
  9819. else
  9820. {
  9821. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9822. }
  9823. if(comfirmstr[0]== 0)
  9824. {
  9825. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9826. }
  9827. //Check chargingProfile is empty file
  9828. /*------ Read the file ----------------*/
  9829. fptr1=fopen(chargingProfiles[k],"r");
  9830. ch=fgetc(fptr1);
  9831. rewind(fptr1);
  9832. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9833. if(ch!=EOF)
  9834. {
  9835. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9836. {
  9837. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9838. if(sLineWord[0]=='\0')
  9839. {
  9840. isEmptyFile = TRUE;
  9841. break;
  9842. }
  9843. else
  9844. {
  9845. isEmptyFile = FALSE;
  9846. break;
  9847. }
  9848. }
  9849. }
  9850. else
  9851. isEmptyFile = TRUE;
  9852. fclose(fptr1);
  9853. if(isEmptyFile == TRUE)
  9854. {
  9855. memset(str, 0, ARRAY_SIZE(str));
  9856. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9857. system(str);
  9858. }
  9859. /*------- End of reading ---------------*/
  9860. }
  9861. } // while(int k=0; k < ChargeProfileCount; k++)
  9862. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9863. end:
  9864. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9865. {
  9866. if(connectorIdInt == 0)
  9867. {
  9868. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9869. {
  9870. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9871. }
  9872. }
  9873. else
  9874. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9875. }
  9876. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9877. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9878. return result;
  9879. }
  9880. void createFirmwareVersionByDataTransfer(void)
  9881. {
  9882. json_object *FirmwareDataTransfer = json_object_new_object();
  9883. // AC & DC model
  9884. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9885. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9886. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9887. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9888. // DC model
  9889. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9890. {
  9891. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9892. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9893. (gunType[3] != GUN_TYPE_UNKNOWN))
  9894. {
  9895. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9896. }
  9897. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9898. {
  9899. // DS DM DW
  9900. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9901. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9902. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9903. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9904. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9905. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9906. }
  9907. else
  9908. {
  9909. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9910. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9911. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9912. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9913. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9914. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9915. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9916. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9917. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9918. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9919. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9920. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9921. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9922. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9923. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9924. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9925. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9926. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9927. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9928. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9929. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9930. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9931. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9932. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9933. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9934. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9935. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9936. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9937. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9938. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9939. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9940. }
  9941. }
  9942. // 4G model
  9943. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9944. {
  9945. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9946. }
  9947. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9948. json_object_put(FirmwareDataTransfer);
  9949. }
  9950. int handleDataTransferRequest(char *uuid, char *payload)
  9951. {
  9952. mtrace();
  9953. json_object *response = json_object_new_object();
  9954. int result = FAIL;
  9955. char tempvendorId[255]={0};
  9956. char tempmessageId[50]={0};
  9957. char tempdata[10240]={0};
  9958. char message[20480]={0};
  9959. DEBUG_INFO("handleDataTransferRequest...\n");
  9960. if((uuid != NULL) && (payload != NULL))
  9961. {
  9962. json_object *DataTransfer;
  9963. DataTransfer = json_tokener_parse(payload);
  9964. if(!is_error(DataTransfer))
  9965. {
  9966. // Required data
  9967. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9968. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9969. // Optional data
  9970. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9971. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9972. if(json_object_object_get(DataTransfer, "data") != NULL)
  9973. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9974. result = PASS;
  9975. }
  9976. json_object_put(DataTransfer);
  9977. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9978. {
  9979. // Send all moudle firmware version on EVSE
  9980. createFirmwareVersionByDataTransfer();
  9981. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9982. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9983. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9984. json_object_put(response);
  9985. }
  9986. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9987. {
  9988. system("/usr/bin/run_tmate_restart.sh &");
  9989. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9990. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9991. json_object_put(response);
  9992. }
  9993. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9994. {
  9995. json_object *data;
  9996. data = json_tokener_parse(tempdata);
  9997. if(!is_error(data))
  9998. {
  9999. 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))
  10000. {
  10001. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10002. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  10003. if(json_object_object_get(data, "SOC") != NULL)
  10004. {
  10005. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  10006. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  10007. }
  10008. if(json_object_object_get(data, "Energy") != NULL)
  10009. {
  10010. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  10011. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  10012. }
  10013. if(json_object_object_get(data, "Duration") != NULL)
  10014. {
  10015. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  10016. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  10017. }
  10018. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10019. }
  10020. else
  10021. {
  10022. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10023. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  10024. }
  10025. }
  10026. else
  10027. {
  10028. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10029. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10030. }
  10031. json_object_put(data);
  10032. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10033. json_object_put(response);
  10034. }
  10035. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  10036. {
  10037. json_object *data;
  10038. data = json_tokener_parse(tempdata);
  10039. if(!is_error(data))
  10040. {
  10041. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  10042. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  10043. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  10044. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  10045. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  10046. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  10047. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  10048. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  10049. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  10050. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  10051. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10052. }
  10053. else
  10054. {
  10055. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10056. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10057. }
  10058. json_object_put(data);
  10059. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10060. json_object_put(response);
  10061. }
  10062. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  10063. {
  10064. json_object *data;
  10065. data = json_tokener_parse(tempdata);
  10066. if(!is_error(data))
  10067. {
  10068. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  10069. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10070. if(json_object_object_get(data, "idToken") != NULL)
  10071. {
  10072. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  10073. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  10074. }
  10075. else
  10076. {
  10077. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10078. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  10079. }
  10080. if(json_object_object_get(data, "price") != NULL) //v1.0
  10081. {
  10082. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  10083. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  10084. }
  10085. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  10086. {
  10087. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10088. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  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("price or priceText not found."));
  10094. }
  10095. }
  10096. else
  10097. {
  10098. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10099. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10100. }
  10101. json_object_put(data);
  10102. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10103. json_object_put(response);
  10104. }
  10105. else if(strstr(tempmessageId, "RunningCost") != NULL)
  10106. {
  10107. json_object *data;
  10108. data = json_tokener_parse(tempdata);
  10109. if(!is_error(data))
  10110. {
  10111. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10112. if(json_object_object_get(data, "txId") != NULL)
  10113. {
  10114. // California pricing V1.0
  10115. DEBUG_INFO("California pricing V1.0\n");
  10116. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10117. sprintf((char*)dmsVersion, "1.0");
  10118. for(int idx = 0;idx<gunTotalNumber;idx++)
  10119. {
  10120. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10121. {
  10122. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  10123. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10124. if(json_object_object_get(data, "description") != NULL)
  10125. {
  10126. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10127. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10128. }
  10129. else
  10130. {
  10131. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10132. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10133. }
  10134. }
  10135. }
  10136. }
  10137. else if(json_object_object_get(data, "transactionId") != NULL)
  10138. {
  10139. // California pricing V2.0
  10140. DEBUG_INFO("California pricing V2.0\n");
  10141. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10142. sprintf((char*)dmsVersion, "2.0");
  10143. for(int idx=0;idx<gunTotalNumber;idx++)
  10144. {
  10145. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10146. {
  10147. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10148. if(json_object_object_get(data, "timestamp") != NULL)
  10149. {
  10150. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  10151. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  10152. }
  10153. else
  10154. {
  10155. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10156. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  10157. }
  10158. if(json_object_object_get(data, "meterValue") != NULL)
  10159. {
  10160. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  10161. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  10162. }
  10163. else
  10164. {
  10165. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10166. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  10167. }
  10168. if(json_object_object_get(data, "cost") != NULL)
  10169. {
  10170. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  10171. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10172. }
  10173. else
  10174. {
  10175. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10176. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10177. }
  10178. if(json_object_object_get(data, "state") != NULL)
  10179. {
  10180. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  10181. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  10182. }
  10183. else
  10184. {
  10185. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10186. json_object_object_add(response, "data", json_object_new_string("state not found."));
  10187. }
  10188. if(json_object_object_get(data, "chargingPrice") != NULL)
  10189. {
  10190. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  10191. {
  10192. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  10193. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  10194. }
  10195. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  10196. {
  10197. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  10198. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  10199. }
  10200. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  10201. {
  10202. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  10203. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  10204. }
  10205. }
  10206. else
  10207. {
  10208. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10209. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10210. }
  10211. if(json_object_object_get(data, "idlePrice") != NULL)
  10212. {
  10213. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  10214. {
  10215. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  10216. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  10217. }
  10218. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  10219. {
  10220. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  10221. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  10222. }
  10223. }
  10224. if(json_object_object_get(data, "nextPeriod") != NULL)
  10225. {
  10226. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  10227. {
  10228. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  10229. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  10230. }
  10231. else
  10232. {
  10233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10234. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  10235. }
  10236. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  10237. {
  10238. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  10239. {
  10240. 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")));
  10241. 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"));
  10242. }
  10243. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  10244. {
  10245. 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")));
  10246. 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"));
  10247. }
  10248. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  10249. {
  10250. 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")));
  10251. 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"));
  10252. }
  10253. }
  10254. else
  10255. {
  10256. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10257. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10258. }
  10259. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10260. {
  10261. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10262. {
  10263. 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")));
  10264. 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"));
  10265. }
  10266. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10267. {
  10268. 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")));
  10269. 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"));
  10270. }
  10271. }
  10272. }
  10273. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10274. {
  10275. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10276. {
  10277. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10278. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10279. }
  10280. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10281. {
  10282. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10283. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10284. }
  10285. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10286. {
  10287. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10288. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10289. }
  10290. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10291. {
  10292. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10293. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10294. }
  10295. }
  10296. }
  10297. }
  10298. }
  10299. else
  10300. {
  10301. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10302. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10303. }
  10304. }
  10305. else
  10306. {
  10307. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10308. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10309. }
  10310. json_object_put(data);
  10311. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10312. json_object_put(response);
  10313. }
  10314. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10315. {
  10316. json_object *data;
  10317. data = json_tokener_parse(tempdata);
  10318. if(!is_error(data))
  10319. {
  10320. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10321. if(json_object_object_get(data, "txId") != NULL)
  10322. {
  10323. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10324. for(int idx = 0;idx<gunTotalNumber;idx++)
  10325. {
  10326. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10327. {
  10328. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10329. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10330. if(json_object_object_get(data, "description") != NULL)
  10331. {
  10332. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10333. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10334. }
  10335. else
  10336. {
  10337. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10338. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10339. }
  10340. }
  10341. }
  10342. }
  10343. else if(json_object_object_get(data, "transactionId") != NULL)
  10344. {
  10345. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10346. for(int idx = 0;idx<gunTotalNumber;idx++)
  10347. {
  10348. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10349. {
  10350. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10351. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10352. if(json_object_object_get(data, "cost") != NULL)
  10353. {
  10354. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10355. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10356. }
  10357. else
  10358. {
  10359. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10360. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10361. }
  10362. if(json_object_object_get(data, "priceText") != NULL)
  10363. {
  10364. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10365. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10366. }
  10367. else
  10368. {
  10369. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10370. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10371. }
  10372. if(json_object_object_get(data, "qrCodeText") != NULL)
  10373. {
  10374. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10375. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10376. }
  10377. }
  10378. }
  10379. }
  10380. else
  10381. {
  10382. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10383. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10384. }
  10385. }
  10386. else
  10387. {
  10388. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10389. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10390. }
  10391. json_object_put(data);
  10392. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10393. json_object_put(response);
  10394. }
  10395. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10396. {
  10397. json_object *data;
  10398. data = json_tokener_parse(tempdata);
  10399. if(!is_error(data))
  10400. {
  10401. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10402. if(json_object_object_get(data, "Content_Type") != NULL)
  10403. {
  10404. 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))
  10405. {
  10406. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10407. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10408. {
  10409. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10410. }
  10411. }
  10412. else
  10413. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10414. }
  10415. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10416. }
  10417. else
  10418. {
  10419. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10420. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10421. }
  10422. json_object_put(data);
  10423. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10424. json_object_put(response);
  10425. }
  10426. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10427. {
  10428. json_object *data;
  10429. data = json_tokener_parse(tempdata);
  10430. if(!is_error(data))
  10431. {
  10432. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10433. if(json_object_object_get(data, "ConnectorId") != NULL)
  10434. {
  10435. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10436. }
  10437. if(json_object_object_get(data, "SerialNo") != NULL)
  10438. {
  10439. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10440. }
  10441. if(json_object_object_get(data, "Page_Index") != NULL)
  10442. {
  10443. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10444. }
  10445. if(json_object_object_get(data, "Duration") != NULL)
  10446. {
  10447. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10448. }
  10449. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10450. }
  10451. else
  10452. {
  10453. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10454. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10455. }
  10456. json_object_put(data);
  10457. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10458. json_object_put(response);
  10459. }
  10460. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10461. {
  10462. json_object *data;
  10463. data = json_tokener_parse(tempdata);
  10464. if(!is_error(data))
  10465. {
  10466. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10467. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10468. {
  10469. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10470. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10471. else
  10472. {
  10473. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10474. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10475. }
  10476. }
  10477. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10478. {
  10479. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10480. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10481. else
  10482. {
  10483. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10484. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10485. }
  10486. }
  10487. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10488. {
  10489. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10490. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  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("Configuration content something wrong."));
  10495. }
  10496. }
  10497. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10498. {
  10499. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10500. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10501. else
  10502. {
  10503. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10504. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10505. }
  10506. }
  10507. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10508. {
  10509. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10510. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10511. else
  10512. {
  10513. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10514. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10515. }
  10516. }
  10517. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10518. {
  10519. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10520. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10521. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10522. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10523. else
  10524. {
  10525. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10526. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10527. }
  10528. }
  10529. if(json_object_object_get(data, "isAuthentication") != NULL)
  10530. {
  10531. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10532. {
  10533. case 0:
  10534. case 1:
  10535. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10536. break;
  10537. default:
  10538. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10539. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10540. break;
  10541. }
  10542. }
  10543. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10544. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10545. }
  10546. else
  10547. {
  10548. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10549. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10550. }
  10551. json_object_put(data);
  10552. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10553. json_object_put(response);
  10554. }
  10555. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10556. {
  10557. json_object *data;
  10558. data = json_tokener_parse(tempdata);
  10559. if(!is_error(data))
  10560. {
  10561. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10562. {
  10563. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10564. {
  10565. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10566. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10567. }
  10568. else
  10569. {
  10570. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10571. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10572. }
  10573. }
  10574. else
  10575. {
  10576. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10577. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10578. }
  10579. }
  10580. else
  10581. {
  10582. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10583. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10584. }
  10585. json_object_put(data);
  10586. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10587. json_object_put(response);
  10588. }
  10589. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10590. {
  10591. json_object *data;
  10592. data = json_tokener_parse(tempdata);
  10593. if(!is_error(data))
  10594. {
  10595. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10596. if(json_object_object_get(data, "stationName") != NULL)
  10597. {
  10598. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10599. }
  10600. else
  10601. {
  10602. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10603. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10604. }
  10605. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10606. {
  10607. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10608. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10609. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10610. }
  10611. }
  10612. else
  10613. {
  10614. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10615. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10616. }
  10617. json_object_put(data);
  10618. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10619. json_object_put(response);
  10620. }
  10621. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10622. {
  10623. json_object *data;
  10624. data = json_tokener_parse(tempdata);
  10625. if(!is_error(data))
  10626. {
  10627. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10628. if(json_object_object_get(data, "weatherId") != NULL)
  10629. {
  10630. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10631. }
  10632. else
  10633. {
  10634. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10635. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10636. }
  10637. if(json_object_object_get(data, "Temperature") != NULL)
  10638. {
  10639. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10640. }
  10641. else
  10642. {
  10643. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10644. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10645. }
  10646. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10647. {
  10648. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10649. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10650. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10651. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10652. );
  10653. }
  10654. }
  10655. else
  10656. {
  10657. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10658. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10659. }
  10660. json_object_put(data);
  10661. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10662. json_object_put(response);
  10663. }
  10664. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10665. {
  10666. json_object *data;
  10667. data = json_tokener_parse(tempdata);
  10668. if(!is_error(data))
  10669. {
  10670. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10671. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10672. {
  10673. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10674. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10675. }
  10676. else
  10677. {
  10678. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10679. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10680. }
  10681. }
  10682. else
  10683. {
  10684. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10685. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10686. }
  10687. json_object_put(data);
  10688. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10689. json_object_put(response);
  10690. }
  10691. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10692. {
  10693. json_object *data;
  10694. data = json_tokener_parse(tempdata);
  10695. if(!is_error(data))
  10696. {
  10697. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10698. {
  10699. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10700. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10701. if(gun_index < gunTotalNumber)
  10702. {
  10703. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10704. {
  10705. json_object *responsedata = json_object_new_object();
  10706. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10707. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10708. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10709. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10710. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10711. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10712. }
  10713. else
  10714. {
  10715. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10716. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10717. }
  10718. }
  10719. else
  10720. {
  10721. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10722. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10723. }
  10724. }
  10725. else
  10726. {
  10727. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10728. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10729. }
  10730. }
  10731. else
  10732. {
  10733. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10734. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10735. }
  10736. json_object_put(data);
  10737. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10738. json_object_put(response);
  10739. }
  10740. // Support ISO-15118 related message
  10741. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10742. {
  10743. char cmdBuf[1024]={0};
  10744. 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);
  10745. system(cmdBuf);
  10746. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10747. json_object *responsedata = json_object_new_object();
  10748. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10749. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10750. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10751. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10752. json_object_put(response);
  10753. }
  10754. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10755. {
  10756. json_object *data;
  10757. data = json_tokener_parse(tempdata);
  10758. if(!is_error(data))
  10759. {
  10760. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10761. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10762. fclose(fp);
  10763. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10764. json_object *responsedata = json_object_new_object();
  10765. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10766. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10767. else
  10768. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10769. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10770. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10771. }
  10772. else
  10773. {
  10774. json_object *responsedata = json_object_new_object();
  10775. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10776. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10777. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10778. }
  10779. json_object_put(data);
  10780. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10781. json_object_put(response);
  10782. }
  10783. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10784. {
  10785. json_object *data;
  10786. data = json_tokener_parse(tempdata);
  10787. DEBUG_INFO("DeleteCertificate processing...\n");
  10788. if(!is_error(data))
  10789. {
  10790. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10791. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10792. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10793. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10794. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10795. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10796. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10797. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10798. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10799. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10800. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10801. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10802. char temp[256] = {0};
  10803. char compareData[256] = {0};
  10804. int isMatch = TRUE;
  10805. // Check certV2G
  10806. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10807. {
  10808. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10809. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10810. isMatch = FALSE;
  10811. if(isMatch == TRUE)
  10812. {
  10813. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10814. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10815. isMatch = FALSE;
  10816. }
  10817. if(isMatch == TRUE)
  10818. {
  10819. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10820. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10821. isMatch = FALSE;
  10822. }
  10823. if(isMatch == TRUE)
  10824. {
  10825. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10826. system(temp);
  10827. json_object *responsedata = json_object_new_object();
  10828. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10829. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10830. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10831. }
  10832. else
  10833. {
  10834. json_object *responsedata = json_object_new_object();
  10835. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10836. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10837. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10838. }
  10839. }
  10840. else
  10841. {
  10842. json_object *responsedata = json_object_new_object();
  10843. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10844. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10845. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10846. }
  10847. }
  10848. else
  10849. {
  10850. json_object *responsedata = json_object_new_object();
  10851. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10852. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10853. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10854. }
  10855. json_object_put(data);
  10856. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10857. json_object_put(response);
  10858. }
  10859. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10860. {
  10861. json_object *data;
  10862. data = json_tokener_parse(tempdata);
  10863. if(!is_error(data))
  10864. {
  10865. /*
  10866. * TODO:
  10867. * 1. Query certificate to response
  10868. */
  10869. json_object *responsedata = json_object_new_object();
  10870. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10871. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10872. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10873. }
  10874. else
  10875. {
  10876. json_object *responsedata = json_object_new_object();
  10877. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10878. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10879. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10880. }
  10881. json_object_put(data);
  10882. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10883. json_object_put(response);
  10884. }
  10885. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10886. {
  10887. json_object *data;
  10888. data = json_tokener_parse(tempdata);
  10889. if(!is_error(data))
  10890. {
  10891. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10892. if(json_object_object_get(data, "certificateType") != NULL)
  10893. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10894. if(json_object_object_get(data, "certificate") != NULL)
  10895. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10896. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10897. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10898. char temp[1024];
  10899. FILE *fp = fopen(tempCert, "w");
  10900. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10901. fclose(fp);
  10902. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10903. char strExpDate[30];
  10904. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10905. fp = popen(temp, "r");
  10906. if(fp)
  10907. {
  10908. while(fgets(temp, sizeof(temp), fp) != NULL)
  10909. {
  10910. if(strstr(temp, "notAfter=") != NULL)
  10911. {
  10912. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10913. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10914. break;
  10915. }
  10916. }
  10917. }
  10918. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10919. struct tm tmExpDate;
  10920. struct timeb tbExpDate;
  10921. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10922. tbExpDate.time = mktime(&tmExpDate);
  10923. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10924. {
  10925. DEBUG_INFO("The enddate is already expired...\n");
  10926. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10927. }
  10928. else
  10929. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10930. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10931. {
  10932. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10933. {
  10934. if(access(ROOTCA_V2G,F_OK) != -1)
  10935. {
  10936. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10937. rename(ROOTCA_V2G, "/Storage/OCPP/rootCaV2g_fallback.pem");
  10938. rename(tempCert, ROOTCA_V2G);
  10939. }
  10940. else
  10941. {
  10942. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10943. rename(tempCert, ROOTCA_V2G);
  10944. }
  10945. json_object *responsedata = json_object_new_object();
  10946. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10947. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10948. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10949. }
  10950. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10951. {
  10952. if(access(ROOTCA_MO,F_OK) != -1)
  10953. {
  10954. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10955. rename(ROOTCA_MO, "/Storage/OCPP/rootCaMo_fallback.pem");
  10956. rename(tempCert, ROOTCA_MO);
  10957. }
  10958. else
  10959. {
  10960. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10961. rename(tempCert, ROOTCA_MO);
  10962. }
  10963. json_object *responsedata = json_object_new_object();
  10964. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10965. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10966. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10967. }
  10968. else
  10969. {
  10970. json_object *responsedata = json_object_new_object();
  10971. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10972. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10973. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10974. }
  10975. }
  10976. else
  10977. {
  10978. json_object *responsedata = json_object_new_object();
  10979. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10980. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10981. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10982. }
  10983. }
  10984. else
  10985. {
  10986. json_object *responsedata = json_object_new_object();
  10987. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10988. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10989. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10990. }
  10991. json_object_put(data);
  10992. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10993. json_object_put(response);
  10994. }
  10995. else
  10996. {
  10997. // Can not find valid message id
  10998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10999. }
  11000. }
  11001. else
  11002. {
  11003. // Payload is null
  11004. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  11005. }
  11006. LWS_Send(message);
  11007. return result;
  11008. }
  11009. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  11010. {
  11011. mtrace();
  11012. int result = FAIL;
  11013. int connectorIdInt, durationInt;
  11014. char chargingRateUnitStr[4]={0};
  11015. char comfirmstr[20];
  11016. int confirmPeriods = 0;
  11017. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  11018. json_object *GetCompositeSchedule;
  11019. GetCompositeSchedule = json_tokener_parse(payload);
  11020. if(!is_error(GetCompositeSchedule))
  11021. {
  11022. // Required data
  11023. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  11024. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  11025. else
  11026. connectorIdInt = -1;
  11027. if(json_object_object_get(GetCompositeSchedule, "duration"))
  11028. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  11029. else
  11030. durationInt = 86400;
  11031. // Optional data
  11032. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  11033. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  11034. }
  11035. json_object_put(GetCompositeSchedule);
  11036. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  11037. if((connectorIdInt == 0) ||
  11038. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  11039. {
  11040. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  11041. struct StructChargingProfile tmpProfile[1];
  11042. if(strstr(chargingRateUnitStr, "W") != NULL)
  11043. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  11044. else
  11045. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  11046. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  11047. {
  11048. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  11049. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  11050. }
  11051. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  11052. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  11053. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  11054. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  11055. {
  11056. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  11057. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  11058. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  11059. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  11060. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  11061. {
  11062. confirmPeriods = idx;
  11063. break;
  11064. }
  11065. }
  11066. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  11067. {
  11068. confirmPeriods += 1;
  11069. }
  11070. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  11071. }
  11072. else
  11073. {
  11074. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  11075. }
  11076. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  11077. return result;
  11078. }
  11079. int handleGetConfigurationRequest(char *uuid, char *payload)
  11080. {
  11081. mtrace();
  11082. int result = FAIL;
  11083. int MaxKeySupported = 0;
  11084. int n_keys = 0;
  11085. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  11086. DEBUG_INFO("handleGetConfigurationRequest...\n");
  11087. json_object *GetConfiguration;
  11088. GetConfiguration = json_tokener_parse(payload);
  11089. if(!is_error(GetConfiguration))
  11090. {
  11091. // Optional data
  11092. if(json_object_object_get(GetConfiguration, "key") != NULL)
  11093. {
  11094. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  11095. {
  11096. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  11097. n_keys = idx + 1;
  11098. }
  11099. }
  11100. }
  11101. json_object_put(GetConfiguration);
  11102. UnknownKeynum = 0;
  11103. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  11104. MaxKeySupported = GetConfigurationMaxKeysNUM;
  11105. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  11106. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  11107. if(n_keys != 0)
  11108. {
  11109. for(int i=0;i<n_keys;i++)
  11110. {
  11111. getKeyValue(requestKey[i]);
  11112. }
  11113. }
  11114. else
  11115. {
  11116. DEBUG_INFO("There is no key in Message, get all configuration\n");
  11117. getKeyValue("");
  11118. }
  11119. processUnkownKey();
  11120. sendGetConfigurationConfirmation(uuid);
  11121. return result;
  11122. }
  11123. static char fnamePlusPath[100]={0};
  11124. static char fnamePWithNoPath[60]={0};
  11125. void checkUploadLog(void)
  11126. {
  11127. FILE *fp;
  11128. /* Open the command for reading. */
  11129. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  11130. if (fp == NULL) {
  11131. DEBUG_WARN("Failed to run command\n" );
  11132. exit(1);
  11133. }
  11134. int ftppathlen = 0;
  11135. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  11136. int i = 0;
  11137. /* Read the output a line at a time - output it. */
  11138. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  11139. if(i==0)
  11140. {
  11141. ftppathlen = strlen(fnamePlusPath);
  11142. DEBUG_INFO("%s\n", fnamePlusPath);
  11143. fnamePlusPath[ftppathlen]='\0';
  11144. break;
  11145. }
  11146. i= i+1;
  11147. }
  11148. /* close */
  11149. pclose(fp);
  11150. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  11151. {
  11152. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  11153. {
  11154. fnamePlusPath[k]='\0';
  11155. }
  11156. }
  11157. i=1;
  11158. //char fname[60]={0};
  11159. while(i < ftppathlen)
  11160. {
  11161. int len=ftppathlen-i;
  11162. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  11163. {
  11164. DEBUG_INFO("compare '/' all right\n");
  11165. break;
  11166. }
  11167. i=i+1;
  11168. }
  11169. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11170. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11171. fnamePWithNoPath[i+1] = '\0';
  11172. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11173. {
  11174. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11175. {
  11176. fnamePWithNoPath[j]='\0';
  11177. }
  11178. }
  11179. FILE* fp1 = fopen(fnamePlusPath, "r");
  11180. if (fp1)
  11181. {
  11182. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11183. // file exists
  11184. fclose(fp1);
  11185. }
  11186. else
  11187. {
  11188. // file doesn't exist
  11189. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11190. }
  11191. }
  11192. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11193. {
  11194. mtrace();
  11195. int result = FAIL;
  11196. time_t CurrentTime;
  11197. struct tm *tm;
  11198. pthread_t th_Status;
  11199. CurrentTime = time(NULL);
  11200. tm = localtime(&CurrentTime);
  11201. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11202. 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);
  11203. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11204. if(!interLock.isGetDiagnosticGoing)
  11205. {
  11206. interLock.isGetDiagnosticGoing = 1;
  11207. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11208. sleep(1);
  11209. }
  11210. else
  11211. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11212. return result;
  11213. }
  11214. void* GetDiagnosticsProcess(void* data)
  11215. {
  11216. pthread_detach(pthread_self());
  11217. mtrace();
  11218. int retriesInt=0, retryIntervalInt=0;
  11219. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11220. 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};
  11221. int port=0;
  11222. int isSuccess = FALSE;
  11223. char cmdBuf[2048];
  11224. struct tm *tmNow;
  11225. time_t CurrentTime;
  11226. struct tm tmStart;
  11227. struct tm tmStop;
  11228. CurrentTime = time(NULL);
  11229. tmNow=localtime(&CurrentTime);
  11230. uint16_t targetYear, targetMonth;
  11231. json_object *GetDiagnostics;
  11232. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11233. GetDiagnostics = json_tokener_parse(data);
  11234. if(!is_error(GetDiagnostics))
  11235. {
  11236. // Required data
  11237. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11238. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11239. // Optional data
  11240. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11241. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11242. else
  11243. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11244. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11245. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11246. else
  11247. retryIntervalInt = 30;
  11248. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11249. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11250. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11251. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11252. }
  11253. json_object_put(GetDiagnostics);
  11254. // Pack log to compress file
  11255. 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) &&
  11256. (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))
  11257. {
  11258. // Pack system log
  11259. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11260. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11261. targetYear = tmStart.tm_year;
  11262. targetMonth = tmStart.tm_mon;
  11263. do
  11264. {
  11265. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11266. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11267. if(targetMonth+1>=13)
  11268. {
  11269. targetYear += 1;
  11270. targetMonth = 1;
  11271. }
  11272. else
  11273. {
  11274. targetMonth += 1;
  11275. }
  11276. }while((targetYear < (tmNow->tm_year+1900)) ||
  11277. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11278. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11279. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11280. system(cmdBuf);
  11281. // Pack charging & event log
  11282. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11283. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11284. targetYear = tmStart.tm_year;
  11285. targetMonth = tmStart.tm_mon;
  11286. do
  11287. {
  11288. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11289. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  11290. if(targetMonth+1>=13)
  11291. {
  11292. targetYear += 1;
  11293. targetMonth = 1;
  11294. }
  11295. else
  11296. {
  11297. targetMonth += 1;
  11298. }
  11299. }while((targetYear < (tmNow->tm_year+1900)) ||
  11300. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11301. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11302. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11303. system(cmdBuf);
  11304. // Combine log file
  11305. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11306. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11307. }
  11308. else
  11309. {
  11310. system("exec /root/logPackTools 'log' 6");
  11311. }
  11312. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11313. system(cmdBuf);
  11314. checkUploadLog();
  11315. //****************location*******************/
  11316. if(strcmp(locationstr,"")==0)
  11317. {
  11318. DEBUG_INFO("location is <Empty>!\n");
  11319. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11320. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11321. goto end;
  11322. }
  11323. memset(protocol, 0, ARRAY_SIZE(protocol));
  11324. memset(user, 0, ARRAY_SIZE(user) );
  11325. memset(password, 0, ARRAY_SIZE(password));
  11326. memset(host, 0, ARRAY_SIZE(host));
  11327. memset(path, 0, ARRAY_SIZE(path));
  11328. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11329. memset(host1, 0, ARRAY_SIZE(host1));
  11330. memset(path1, 0, ARRAY_SIZE(path1));
  11331. /*location: ftp://user:password@host:port/path*/
  11332. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11333. if((access(fnamePlusPath,F_OK))!=-1)
  11334. {
  11335. DEBUG_INFO("fnamePlusPath exist.\n");
  11336. }
  11337. else
  11338. {
  11339. DEBUG_INFO("fnamePlusPath not exist!\n");
  11340. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11341. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11342. goto end;
  11343. }
  11344. if(strchr(locationstr,'@')==NULL)
  11345. {
  11346. sscanf(locationstr,
  11347. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11348. protocol, host, &port, path);
  11349. strcpy(user,"anonymous");
  11350. strcpy(password,"");
  11351. }
  11352. else
  11353. {
  11354. //DEBUG_INFO("pch=%s\n", pch);
  11355. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11356. protocol, user, password, host, &port, path);
  11357. }
  11358. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11359. {
  11360. DEBUG_INFO("protocol is not ftp/http ! \n");
  11361. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11362. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11363. goto end;
  11364. }
  11365. if(strncmp(locationstr,"http", 4) == 0)
  11366. {
  11367. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11368. sprintf(ftppath,"/%s", path);
  11369. do
  11370. {
  11371. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11372. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11373. sleep(3);
  11374. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11375. if(!isSuccess)
  11376. {
  11377. DEBUG_INFO("Diagnostics fail.\n");
  11378. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11379. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11380. sleep(retryIntervalInt);
  11381. }
  11382. else
  11383. {
  11384. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11385. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11386. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11387. }
  11388. retriesInt--;
  11389. }while((isSuccess == 0)&&(retriesInt >= 0));
  11390. }
  11391. else
  11392. {
  11393. sscanf(host,"%[^/]%s",host1, path1);
  11394. if(strlen(path) > 0)
  11395. sprintf(ftppath,"/%s", path);
  11396. else
  11397. sprintf(ftppath,"/%s", path1);
  11398. int ftppathlen=strlen(ftppath);
  11399. int i=1;
  11400. char filenametemp[50];
  11401. while(i < ftppathlen)
  11402. {
  11403. int len=ftppathlen-i;
  11404. if(ftppath[len]== 47) // '/' ascll code: 47
  11405. {
  11406. DEBUG_INFO("find '/' all right\n");
  11407. break;
  11408. }
  11409. i=i+1;
  11410. }
  11411. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11412. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11413. filenametemp[i+1] = 0;
  11414. if(port == 0)
  11415. port = 21;
  11416. do
  11417. {
  11418. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11419. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11420. sleep(3);
  11421. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11422. if(!isSuccess)
  11423. {
  11424. DEBUG_INFO("Diagnostics fail.\n");
  11425. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11426. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11427. sleep(retryIntervalInt);
  11428. }
  11429. else
  11430. {
  11431. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11432. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11433. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11434. }
  11435. retriesInt--;
  11436. }while((!isSuccess)&&(retriesInt >= 0));
  11437. }
  11438. end:
  11439. system("rm -f /mnt/*");
  11440. sleep(5);
  11441. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11442. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11443. interLock.isGetDiagnosticGoing = 0;
  11444. pthread_exit(NULL);
  11445. }
  11446. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11447. {
  11448. mtrace();
  11449. int result = FAIL;
  11450. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11451. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11452. {
  11453. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11454. locallistVersion = -1;
  11455. }
  11456. else
  11457. {
  11458. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11459. locallistVersion = 0;
  11460. OCPP_getListVerion();
  11461. }
  11462. //from db.OCPP_getListVerion
  11463. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11464. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11465. sendGetLocalListVersionConfirmation(uuid,"");
  11466. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11467. return result;
  11468. }
  11469. int handleRemoteStartRequest(char *uuid, char *payload)
  11470. {
  11471. mtrace();
  11472. int result = PASS;
  11473. int connectorIdInt=-1;
  11474. int tempIndex = 0;
  11475. char comfirmstr[20]={0};
  11476. char cmdBuf[512];
  11477. json_object *RemoteStartTransaction;
  11478. FILE *fp;
  11479. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11480. if(server_pending == TRUE)
  11481. {
  11482. result = FAIL;
  11483. }
  11484. RemoteStartTransaction = json_tokener_parse(payload);
  11485. if(!is_error(RemoteStartTransaction))
  11486. {
  11487. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11488. {
  11489. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11490. }
  11491. else
  11492. {
  11493. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11494. {
  11495. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11496. {
  11497. connectorIdInt = (gun_index+1);
  11498. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11499. break;
  11500. }
  11501. }
  11502. }
  11503. if(connectorIdInt == 0)
  11504. {
  11505. DEBUG_WARN("Connector id shall not equal 0.\n");
  11506. result = FAIL;
  11507. }
  11508. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11509. {
  11510. DEBUG_WARN("idTag should not be NULL.\n");
  11511. result = FAIL;
  11512. }
  11513. else if(connectorIdInt == -1)
  11514. {
  11515. DEBUG_INFO("Connector id does not specific.\n");
  11516. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11517. {
  11518. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11519. // Required data
  11520. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11521. // Optional data
  11522. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11523. {
  11524. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11525. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11526. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11527. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11528. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11529. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11530. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11531. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11532. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11533. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11534. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11535. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11536. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11537. {
  11538. 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")));
  11539. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11540. 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"));
  11541. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11542. 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"));
  11543. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11544. 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")));
  11545. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11546. {
  11547. 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++)
  11548. {
  11549. 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"));
  11550. 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"));
  11551. 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)
  11552. 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"));
  11553. }
  11554. }
  11555. }
  11556. }
  11557. else
  11558. {
  11559. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11560. }
  11561. }
  11562. }
  11563. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11564. {
  11565. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11566. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11567. // Required data
  11568. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11569. // Optional data
  11570. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11571. {
  11572. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11573. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11574. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11575. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11576. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11577. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11578. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11579. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11580. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11581. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11582. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11583. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11584. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11585. {
  11586. 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")));
  11587. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11588. 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"));
  11589. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11590. 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"));
  11591. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11592. 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")));
  11593. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11594. {
  11595. 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++)
  11596. {
  11597. 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"));
  11598. 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"));
  11599. 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)
  11600. 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"));
  11601. }
  11602. }
  11603. }
  11604. }
  11605. else
  11606. {
  11607. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11608. }
  11609. }
  11610. else
  11611. {
  11612. DEBUG_WARN("Connector id is over maximun value.\n");
  11613. result = FAIL;
  11614. }
  11615. }
  11616. if(result == PASS)
  11617. {
  11618. if(connectorIdInt > 0)
  11619. {
  11620. //check Transaction active
  11621. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11622. {
  11623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11624. {
  11625. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11626. }
  11627. else
  11628. {
  11629. tempIndex = connectorIdInt -1;
  11630. }
  11631. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11632. {
  11633. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11634. {
  11635. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11636. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11637. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11638. {
  11639. //Reserved
  11640. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11641. }
  11642. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11643. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11644. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11645. {
  11646. //Reserved
  11647. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11648. {
  11649. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11650. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11651. goto end;
  11652. }
  11653. }
  11654. else
  11655. {
  11656. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11657. {
  11658. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11659. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11660. goto end;
  11661. }
  11662. }//END FOR ELSE
  11663. }
  11664. }// END FOR CHAdeMO_QUANTITY
  11665. }
  11666. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11667. {
  11668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11669. {
  11670. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11671. }
  11672. else
  11673. {
  11674. tempIndex = connectorIdInt -1;
  11675. }
  11676. for (int index = 0; index < CCS_QUANTITY; index++)
  11677. {
  11678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11679. {
  11680. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11681. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11682. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11683. {
  11684. //Reserved
  11685. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11686. }
  11687. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11688. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11689. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11690. {
  11691. //Reserved
  11692. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11693. {
  11694. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11695. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11696. goto end;
  11697. }
  11698. }
  11699. else
  11700. {
  11701. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11702. {
  11703. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11704. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11705. goto end;
  11706. }
  11707. }// END FOR ELSE
  11708. }
  11709. }// END FOR CCS_QUANTITY
  11710. }
  11711. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11712. {
  11713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11714. {
  11715. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11716. }
  11717. else
  11718. {
  11719. tempIndex = connectorIdInt -1;
  11720. }
  11721. for (int index = 0; index < GB_QUANTITY; index++)
  11722. {
  11723. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11724. {
  11725. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11726. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11727. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11728. {
  11729. //Reserved
  11730. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11731. }
  11732. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11733. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11734. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11735. {
  11736. //Reserved
  11737. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11738. {
  11739. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11740. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11741. goto end;
  11742. }
  11743. }
  11744. else
  11745. {
  11746. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11747. {
  11748. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11749. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11750. goto end;
  11751. }
  11752. }// END FOR ELSE
  11753. }
  11754. } // END FOR GB_QUANTITY
  11755. }
  11756. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11757. {
  11758. tempIndex = connectorIdInt -1;
  11759. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11760. {
  11761. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11762. {
  11763. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11764. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11765. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11766. {
  11767. //Reserved
  11768. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11769. }
  11770. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11771. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11772. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11773. {
  11774. //Reserved
  11775. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11776. {
  11777. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11778. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11779. goto end;
  11780. }
  11781. }
  11782. else
  11783. {
  11784. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11785. {
  11786. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11787. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11788. goto end;
  11789. }
  11790. }// END FOR ELSE
  11791. }
  11792. } // END FOR GB_QUANTITY
  11793. }
  11794. else
  11795. {
  11796. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11797. {
  11798. tempIndex = 2;
  11799. }
  11800. else
  11801. {
  11802. tempIndex = connectorIdInt -1;
  11803. }
  11804. for (int index = 0; index < AC_QUANTITY; index++)
  11805. {
  11806. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11807. {
  11808. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11809. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11810. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11811. {
  11812. //Reserved
  11813. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11814. }
  11815. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11816. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11817. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11818. {
  11819. //Reserved
  11820. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11821. {
  11822. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11823. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11824. goto end;
  11825. }
  11826. }
  11827. else
  11828. {
  11829. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11830. {
  11831. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11832. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11833. goto end;
  11834. }
  11835. }//END FOR ELSE
  11836. }
  11837. }// END FOR AC_QUANTITY
  11838. }
  11839. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11840. {
  11841. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11842. {
  11843. // Save profile to file
  11844. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11845. system(cmdBuf);
  11846. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11847. fp = fopen(cmdBuf, "w");
  11848. 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));
  11849. fclose(fp);
  11850. }
  11851. else
  11852. {
  11853. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11854. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11855. goto end;
  11856. }
  11857. }
  11858. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11859. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11860. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11861. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11862. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11863. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11864. }
  11865. else
  11866. {
  11867. uint8_t isHasIdleConnector = FALSE;
  11868. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11869. {
  11870. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11871. {
  11872. isHasIdleConnector = TRUE;
  11873. break;
  11874. }
  11875. }
  11876. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11877. {
  11878. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11879. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11880. {
  11881. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11882. {
  11883. // Save profile to file
  11884. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11885. system(cmdBuf);
  11886. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11887. fp = fopen(cmdBuf, "w");
  11888. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11889. fclose(fp);
  11890. refreshStartTimer(&clientTime.RemoteStartWait);
  11891. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11892. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11893. }
  11894. else
  11895. {
  11896. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11897. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11898. }
  11899. }
  11900. else
  11901. {
  11902. refreshStartTimer(&clientTime.RemoteStartWait);
  11903. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11904. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11905. }
  11906. }
  11907. else
  11908. {
  11909. DEBUG_INFO("There is not any connector is idle.\n");
  11910. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11911. }
  11912. }
  11913. }
  11914. else
  11915. {
  11916. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11917. }
  11918. end:
  11919. json_object_put(RemoteStartTransaction);
  11920. sendRemoteStartConfirmation(uuid, comfirmstr);
  11921. return result;
  11922. }
  11923. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11924. {
  11925. mtrace();
  11926. int result = FAIL;
  11927. int match = FALSE;
  11928. int GunNO = 0;
  11929. int tempIndex = 0;
  11930. int transactionIdInt=0;
  11931. int transactionIdIsNULL= TRUE;
  11932. char comfirmstr[20];
  11933. json_object *RemoteStopTransaction;
  11934. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11935. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11936. if(server_pending == TRUE)
  11937. {
  11938. return 0;
  11939. }
  11940. RemoteStopTransaction = json_tokener_parse(payload);
  11941. if(!is_error(RemoteStopTransaction))
  11942. {
  11943. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11944. {
  11945. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11946. transactionIdIsNULL = FALSE;
  11947. }
  11948. }
  11949. json_object_put(RemoteStopTransaction);
  11950. if(transactionIdIsNULL == FALSE)
  11951. {
  11952. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11953. {
  11954. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11955. {
  11956. //check Transaction active
  11957. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11958. {
  11959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11960. {
  11961. tempIndex = ((gun_index==2) ? 1: 0);
  11962. }
  11963. else
  11964. {
  11965. tempIndex = gun_index;
  11966. }
  11967. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11968. {
  11969. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11970. {
  11971. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11972. {
  11973. match = TRUE;
  11974. GunNO = gun_index;
  11975. }
  11976. }
  11977. }// END FOR CHAdeMO_QUANTITY
  11978. }
  11979. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11980. {
  11981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11982. {
  11983. tempIndex = ((gun_index==2) ? 1: 0);
  11984. }
  11985. else
  11986. {
  11987. tempIndex = gun_index;
  11988. }
  11989. for (int index = 0; index < CCS_QUANTITY; index++)
  11990. {
  11991. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11992. {
  11993. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11994. {
  11995. match = TRUE;
  11996. GunNO = gun_index;
  11997. }
  11998. }
  11999. }// END FOR CCS_QUANTITY
  12000. }
  12001. else if(gunType[gun_index] == GUN_TYPE_GBT)
  12002. {
  12003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12004. {
  12005. tempIndex = ((gun_index==2) ? 1: 0);
  12006. }
  12007. else
  12008. {
  12009. tempIndex = gun_index;
  12010. }
  12011. for (int index = 0; index < GB_QUANTITY; index++)
  12012. {
  12013. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12014. {
  12015. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12016. {
  12017. match = TRUE;
  12018. GunNO = gun_index;
  12019. }
  12020. }
  12021. }// END FOR GB_QUANTITY
  12022. }
  12023. else if(gunType[gun_index] == GUN_TYPE_DO)
  12024. {
  12025. tempIndex = gun_index;
  12026. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12027. {
  12028. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12029. {
  12030. 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
  12031. {
  12032. match = TRUE;
  12033. GunNO = gun_index;
  12034. }
  12035. }
  12036. }// END FOR GB_QUANTITY
  12037. }
  12038. else
  12039. {
  12040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12041. {
  12042. tempIndex = 2;
  12043. }
  12044. else
  12045. {
  12046. tempIndex = gun_index;
  12047. }
  12048. for (int index = 0; index < AC_QUANTITY; index++)
  12049. {
  12050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12051. {
  12052. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12053. {
  12054. match = TRUE;
  12055. GunNO = gun_index;
  12056. }
  12057. }
  12058. }// END FOR CHAdeMO_QUANTITY
  12059. } // END FOR AC ELSE
  12060. }// CHECK IF ResponseTransactionId == transactionIdInt
  12061. }//END FOR
  12062. if( match == TRUE)
  12063. {
  12064. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  12065. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  12066. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  12067. }
  12068. else
  12069. {
  12070. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12071. }
  12072. }
  12073. else
  12074. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12075. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  12076. return result;
  12077. }
  12078. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  12079. {
  12080. mtrace();
  12081. int result = FAIL;
  12082. int connectorIdInt=0, reservationIdInt=0;
  12083. int tempIndex = 0;
  12084. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  12085. char comfirmstr[20]={0};
  12086. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  12087. int c = 0;
  12088. char *loc;
  12089. //char *ptr;
  12090. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  12091. strcpy(sstrtemp, stringtrimspace(payload));
  12092. //***(1)connectorId ****/
  12093. c=0;
  12094. loc = strstr(sstrtemp, "connectorId");
  12095. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12096. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  12097. {
  12098. sstr[c] = loc[strlen("connectorId")+2+c];
  12099. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12100. c++;
  12101. }
  12102. sstr[c] = '\0';
  12103. connectorIdInt = atoi(sstr);
  12104. //***(2)expiryDate ****/
  12105. loc = strstr(sstrtemp, "expiryDate");
  12106. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12107. c = 0;
  12108. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  12109. {
  12110. sstr[c] = loc[3+strlen("expiryDate")+c];
  12111. c++;
  12112. }
  12113. sstr[c] = '\0';
  12114. strcpy(expiryDatestr, sstr);
  12115. //***(3)idTag ****/
  12116. loc = strstr(sstrtemp, "idTag");
  12117. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12118. c = 0;
  12119. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  12120. {
  12121. sstr[c] = loc[3+strlen("idTag")+c];
  12122. c++;
  12123. }
  12124. sstr[c] = '\0';
  12125. strcpy(idTagstr, sstr);
  12126. //***(4)parentIdTag ****/
  12127. loc = strstr(sstrtemp, "parentIdTag");
  12128. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12129. c = 0;
  12130. if(loc == NULL)
  12131. {
  12132. strcpy(parentIdTagstr, "");
  12133. }
  12134. else
  12135. {
  12136. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  12137. {
  12138. sstr[c] = loc[3+strlen("parentIdTag")+c];
  12139. c++;
  12140. }
  12141. sstr[c] = '\0';
  12142. strcpy(parentIdTagstr, sstr);
  12143. }
  12144. //***(5)reservationId ****/
  12145. c=0;
  12146. loc = strstr(sstrtemp, "reservationId");
  12147. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12148. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  12149. {
  12150. sstr[c] = loc[strlen("reservationId")+2+c];
  12151. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12152. c++;
  12153. }
  12154. sstr[c] = '\0';
  12155. reservationIdInt = atoi(sstr);
  12156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12157. /*
  12158. enum SYSTEM_STATUS
  12159. {
  12160. SYS_MODE_BOOTING = 0,
  12161. SYS_MODE_IDLE = 1,
  12162. SYS_MODE_AUTHORIZING = 2,
  12163. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12164. SYS_MODE_REASSIGN = 4,
  12165. SYS_MODE_PREPARING = 5,
  12166. SYS_MODE_PREPARE_FOR_EV = 6,
  12167. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12168. SYS_MODE_CHARGING = 8,
  12169. SYS_MODE_TERMINATING = 9,
  12170. SYS_MODE_COMPLETE = 10,
  12171. SYS_MODE_ALARM = 11,
  12172. SYS_MODE_FAULT = 12,
  12173. SYS_MODE_RESERVATION = 13,
  12174. SYS_MODE_BOOKING = 14,
  12175. SYS_MODE_MAINTAIN = 15,
  12176. SYS_MODE_DEBUG = 16,
  12177. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12178. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12179. SYS_MODE_UPDATE = 19
  12180. };
  12181. */
  12182. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12183. {
  12184. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12185. goto end;
  12186. }
  12187. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12188. {
  12189. //check Transaction active
  12190. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12191. {
  12192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12193. {
  12194. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12195. }
  12196. else
  12197. {
  12198. tempIndex = connectorIdInt -1;
  12199. }
  12200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12201. {
  12202. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12203. {
  12204. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12205. {
  12206. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12207. {
  12208. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12209. {
  12210. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12211. {
  12212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12213. }
  12214. else
  12215. {
  12216. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12218. }
  12219. }
  12220. 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'))
  12221. {
  12222. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12223. }
  12224. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12225. {
  12226. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12227. }
  12228. else
  12229. {
  12230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12231. }
  12232. }
  12233. 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
  12234. {
  12235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12236. }
  12237. }
  12238. else
  12239. {
  12240. //replace reservation
  12241. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12242. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12243. }
  12244. }
  12245. } // END FOR CHAdeMO_QUANTITY
  12246. }
  12247. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12248. {
  12249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12250. {
  12251. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12252. }
  12253. else
  12254. {
  12255. tempIndex = connectorIdInt -1;
  12256. }
  12257. for (int index = 0; index < CCS_QUANTITY; index++)
  12258. {
  12259. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12260. {
  12261. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12262. {
  12263. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12264. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12265. {
  12266. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12267. {
  12268. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12269. {
  12270. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12271. }
  12272. else
  12273. {
  12274. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12276. }
  12277. }
  12278. 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'))
  12279. {
  12280. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12281. }
  12282. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12283. {
  12284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12285. }
  12286. else
  12287. {
  12288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12289. }
  12290. }
  12291. 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
  12292. {
  12293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12294. }
  12295. }
  12296. else
  12297. {
  12298. //replace reservation
  12299. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12300. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12301. }
  12302. }
  12303. } // END FOR CCS_QUANTITY
  12304. }
  12305. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12306. {
  12307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12308. {
  12309. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12310. }
  12311. else
  12312. {
  12313. tempIndex = connectorIdInt -1;
  12314. }
  12315. for (int index = 0; index < GB_QUANTITY; index++)
  12316. {
  12317. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12318. {
  12319. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12320. {
  12321. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12322. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12323. {
  12324. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12325. {
  12326. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12327. {
  12328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12329. }
  12330. else
  12331. {
  12332. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12333. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12334. }
  12335. }
  12336. 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'))
  12337. {
  12338. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12339. }
  12340. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12341. {
  12342. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12343. }
  12344. else
  12345. {
  12346. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12347. }
  12348. }
  12349. 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
  12350. {
  12351. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12352. }
  12353. }
  12354. else
  12355. {
  12356. //replace reservation
  12357. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12358. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12359. }
  12360. }
  12361. }// END FOR GB_QUANTITY
  12362. }
  12363. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12364. {
  12365. tempIndex = connectorIdInt -1;
  12366. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12367. {
  12368. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12369. {
  12370. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12371. {
  12372. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12373. 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
  12374. {
  12375. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12376. {
  12377. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12378. {
  12379. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12380. }
  12381. else
  12382. {
  12383. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12384. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12385. }
  12386. }
  12387. 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'))
  12388. {
  12389. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12390. }
  12391. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12392. {
  12393. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12394. }
  12395. else
  12396. {
  12397. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12398. }
  12399. }
  12400. 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
  12401. {
  12402. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12403. }
  12404. }
  12405. else
  12406. {
  12407. //replace reservation
  12408. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12409. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12410. }
  12411. }
  12412. }// END FOR GB_QUANTITY
  12413. }
  12414. else
  12415. {
  12416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12417. {
  12418. tempIndex = 2;
  12419. }
  12420. else
  12421. {
  12422. tempIndex = (connectorIdInt -1);
  12423. }
  12424. for (int index = 0; index < AC_QUANTITY; index++)
  12425. {
  12426. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12427. {
  12428. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12429. {
  12430. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12431. {
  12432. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12433. {
  12434. 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))
  12435. {
  12436. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12437. }
  12438. else
  12439. {
  12440. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12442. }
  12443. }
  12444. 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'))
  12445. {
  12446. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12447. }
  12448. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12449. {
  12450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12451. }
  12452. else
  12453. {
  12454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12455. }
  12456. }
  12457. 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
  12458. {
  12459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12460. }
  12461. }
  12462. else
  12463. {
  12464. //replace reservation
  12465. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12466. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12467. }
  12468. }
  12469. } // END FOR AC_QUANTITY
  12470. }
  12471. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12472. }
  12473. else if(connectorIdInt == 0)
  12474. {
  12475. //check Transaction active
  12476. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12477. {
  12478. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12479. {
  12480. 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'))
  12481. {
  12482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12483. goto end;
  12484. }
  12485. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12486. {
  12487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12488. goto end;
  12489. }
  12490. 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
  12491. {
  12492. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12493. goto end;
  12494. }
  12495. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12496. {
  12497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12498. goto end;
  12499. }
  12500. }
  12501. }// END FOR CHAdeMO_QUANTITY
  12502. for (int index = 0; index < CCS_QUANTITY; index++)
  12503. {
  12504. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12505. {
  12506. 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'))
  12507. {
  12508. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12509. goto end;
  12510. }
  12511. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12512. {
  12513. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12514. goto end;
  12515. }
  12516. 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
  12517. {
  12518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12519. goto end;
  12520. }
  12521. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12522. {
  12523. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12524. goto end;
  12525. }
  12526. }
  12527. } // END FOR CCS_QUANTITY
  12528. for (int index = 0; index < GB_QUANTITY; index++)
  12529. {
  12530. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12531. {
  12532. 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'))
  12533. {
  12534. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12535. goto end;
  12536. }
  12537. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12538. {
  12539. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12540. goto end;
  12541. }
  12542. 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
  12543. {
  12544. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12545. goto end;
  12546. }
  12547. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12548. {
  12549. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12550. goto end;
  12551. }
  12552. }
  12553. } // END FOR GB_QUANTITY
  12554. for (int index = 0; index < AC_QUANTITY; index++)
  12555. {
  12556. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12557. {
  12558. 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'))
  12559. {
  12560. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12561. goto end;
  12562. }
  12563. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12564. {
  12565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12566. goto end;
  12567. }
  12568. 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
  12569. {
  12570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12571. goto end;
  12572. }
  12573. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12574. {
  12575. 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))
  12576. {
  12577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12578. goto end;
  12579. }
  12580. }
  12581. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12582. {
  12583. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12584. goto end;
  12585. }
  12586. }
  12587. }// END FOR AC_QUANTITY
  12588. //The connectorId is 0
  12589. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12591. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12592. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12593. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12594. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12595. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12596. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12597. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12598. result = TRUE;
  12599. return result;
  12600. }
  12601. else
  12602. {
  12603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12604. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12605. }
  12606. if(strcmp(comfirmstr,"Accepted") == 0)
  12607. {
  12608. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12609. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12610. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12611. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12612. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12613. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12614. result = TRUE;
  12615. return result;
  12616. }
  12617. end:
  12618. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12619. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12620. return result;
  12621. }
  12622. int handleResetRequest(char *uuid, char *payload)
  12623. {
  12624. mtrace();
  12625. int result = FAIL;
  12626. char sstr[10]={0},sstrtemp[30]={ 0 };
  12627. char typestr[10]={0};
  12628. char comfirmstr[20]={0};
  12629. int c = 0;
  12630. char *loc;
  12631. DEBUG_INFO("handleResetRequest...\n");
  12632. strcpy(sstrtemp, stringtrimspace(payload));
  12633. loc = strstr(sstrtemp, "type");
  12634. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12635. c = 0;
  12636. while (loc[3+strlen("type")+c] != '\"')
  12637. {
  12638. sstr[c] = loc[3+strlen("type")+c];
  12639. c++;
  12640. }
  12641. sstr[c] = '\0';
  12642. strcpy(typestr,sstr);
  12643. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12644. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12645. {
  12646. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12647. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12648. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12649. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12650. }
  12651. else
  12652. {
  12653. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12654. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12655. result = PASS;
  12656. }
  12657. sendResetConfirmation(uuid, comfirmstr);
  12658. return result;
  12659. }
  12660. int handleSendLocalListRequest(char *uuid, char *payload)
  12661. {
  12662. mtrace();
  12663. int result = FAIL;
  12664. char comfirmstr[20];
  12665. int checkState_Faulted = FALSE;
  12666. json_object *SendLocalList;
  12667. DEBUG_INFO("handleSendLocalListRequest...\n");
  12668. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12669. {
  12670. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12671. goto end;
  12672. }
  12673. //check Charge Point state
  12674. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12675. {
  12676. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12677. {
  12678. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12679. }
  12680. }
  12681. for (int index = 0; index < CCS_QUANTITY; index++)
  12682. {
  12683. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12684. {
  12685. checkState_Faulted = TRUE; //OCPP Status
  12686. }
  12687. }
  12688. for (int index = 0; index < GB_QUANTITY; index++)
  12689. {
  12690. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12691. {
  12692. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12693. }
  12694. }
  12695. //check Charge Point state
  12696. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12697. {
  12698. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12699. {
  12700. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12701. }
  12702. }
  12703. //check Charge Point state
  12704. for (int index = 0; index < AC_QUANTITY; index++)
  12705. {
  12706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12707. {
  12708. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12709. }
  12710. }
  12711. if(checkState_Faulted == TRUE)
  12712. {
  12713. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12714. goto end;
  12715. }
  12716. // Parsing payload
  12717. SendLocalList = json_tokener_parse(payload);
  12718. if(!is_error(SendLocalList))
  12719. {
  12720. // Required data
  12721. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12722. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12723. // Optional data
  12724. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12725. {
  12726. //Check UpdateType
  12727. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12728. {
  12729. //Local list full update
  12730. DEBUG_INFO("Local list full update.\n");
  12731. locallistVersion = 0;
  12732. OCPP_getListVerion();
  12733. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12734. {
  12735. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12736. goto end;
  12737. }
  12738. OCPP_cleanLocalList();
  12739. }
  12740. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12741. {
  12742. //Local list different update
  12743. DEBUG_INFO("Local list different update.\n");
  12744. locallistVersion = 0;
  12745. OCPP_getListVerion();
  12746. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12747. {
  12748. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12749. goto end;
  12750. }
  12751. }
  12752. else
  12753. {
  12754. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12755. goto end;
  12756. }
  12757. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12758. {
  12759. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12760. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12761. goto end;
  12762. }
  12763. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12764. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12765. {
  12766. 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")));
  12767. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12768. {
  12769. 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")));
  12770. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12771. 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")));
  12772. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12773. 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")));
  12774. }
  12775. // Add to db
  12776. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12777. {
  12778. //Local list full update
  12779. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12780. idx,
  12781. ShmOCPP16Data->SendLocalList.ListVersion,
  12782. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12783. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12784. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12785. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12786. // update list
  12787. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12788. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12789. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12790. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12791. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12792. }
  12793. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12794. {
  12795. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12796. idx,
  12797. ShmOCPP16Data->SendLocalList.ListVersion,
  12798. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12799. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12800. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12801. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12802. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12803. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12804. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12805. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12806. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12807. }
  12808. }
  12809. }
  12810. else
  12811. {
  12812. //Check UpdateType
  12813. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12814. {
  12815. //Local list full update
  12816. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12817. OCPP_cleanLocalList();
  12818. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12819. goto end;
  12820. }
  12821. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12822. {
  12823. //Local list different update
  12824. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12825. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12826. goto end;
  12827. }
  12828. }
  12829. result = PASS;
  12830. }
  12831. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12832. end:
  12833. json_object_put(SendLocalList);
  12834. sendSendLocalListConfirmation(uuid, comfirmstr);
  12835. return result;
  12836. }
  12837. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12838. {
  12839. mtrace();
  12840. int result = FAIL;
  12841. struct StructSetChargingProfile SetProfileReq = {0};
  12842. int tempchargingProfileIdInt;
  12843. int tempstackLevelInt;
  12844. int chargingSchedulePeriodCount = 0;
  12845. char comfirmstr[20]={0};
  12846. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12847. char rmFileCmd[128]={0};
  12848. int profileQuantity = 0;
  12849. int replaceableProfileCnt = 0;
  12850. json_object *SetChargingProfile;
  12851. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12852. SetChargingProfile = json_tokener_parse(payload);
  12853. if(!is_error(SetChargingProfile))
  12854. {
  12855. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12856. {
  12857. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12858. }
  12859. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12860. {
  12861. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12862. {
  12863. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12864. }
  12865. else
  12866. {
  12867. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12868. DEBUG_WARN("Cannot find chargingProfileId field.");
  12869. goto end;
  12870. }
  12871. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12872. {
  12873. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12874. }
  12875. else
  12876. {
  12877. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12878. DEBUG_WARN("Cannot find stackLevel field.");
  12879. goto end;
  12880. }
  12881. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12882. {
  12883. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12884. }
  12885. else
  12886. {
  12887. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12888. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12889. goto end;
  12890. }
  12891. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12892. {
  12893. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12894. }
  12895. else
  12896. {
  12897. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12898. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12899. goto end;
  12900. }
  12901. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12902. {
  12903. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12904. }
  12905. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12906. {
  12907. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12908. }
  12909. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12910. {
  12911. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12912. }
  12913. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12914. {
  12915. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12916. }
  12917. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12918. {
  12919. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12920. {
  12921. 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")));
  12922. }
  12923. else
  12924. {
  12925. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12926. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12927. goto end;
  12928. }
  12929. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12930. {
  12931. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12932. }
  12933. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12934. {
  12935. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12936. }
  12937. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12938. {
  12939. 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")));
  12940. }
  12941. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12942. {
  12943. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12944. if(chargingSchedulePeriodCount <= 10)
  12945. {
  12946. 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++)
  12947. {
  12948. 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)
  12949. {
  12950. 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"));
  12951. }
  12952. else
  12953. {
  12954. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12955. DEBUG_WARN("Cannot find startPeriod field.");
  12956. goto end;
  12957. }
  12958. 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)
  12959. {
  12960. 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"));
  12961. }
  12962. else
  12963. {
  12964. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12965. DEBUG_WARN("Cannot find limit field.");
  12966. goto end;
  12967. }
  12968. 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)
  12969. {
  12970. 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"));
  12971. }
  12972. }
  12973. }
  12974. }
  12975. else
  12976. {
  12977. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12978. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12979. goto end;
  12980. }
  12981. }
  12982. else
  12983. {
  12984. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12985. DEBUG_WARN("Cannot find chargingSchedule field.");
  12986. goto end;
  12987. }
  12988. }
  12989. }
  12990. // Profile periods quantity check
  12991. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12992. {
  12993. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12994. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12995. goto end;
  12996. }
  12997. // Check invalid limit
  12998. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12999. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  13000. {
  13001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  13002. {
  13003. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  13004. {
  13005. 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)))) ||
  13006. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  13007. {
  13008. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13009. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  13010. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  13011. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  13012. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  13013. goto end;
  13014. }
  13015. }
  13016. }
  13017. else
  13018. {
  13019. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  13020. {
  13021. 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) ||
  13022. (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)))
  13023. {
  13024. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13025. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  13026. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  13027. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  13028. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  13029. goto end;
  13030. }
  13031. }
  13032. }
  13033. }
  13034. // Profile purpose info check
  13035. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13036. {
  13037. FILE *fp;
  13038. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  13039. if(SetProfileReq.ConnectorId != 0)
  13040. {
  13041. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13042. DEBUG_WARN("Profile connector id is not 0.\n");
  13043. goto end;
  13044. }
  13045. fp = fopen(ChargePointMaxProfile_JSON, "r");
  13046. if (!fp)
  13047. {
  13048. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  13049. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  13050. }
  13051. else
  13052. {
  13053. char *line = NULL;
  13054. size_t len = 0;
  13055. while(getline(&line, &len, fp) != -1)
  13056. {
  13057. json_object *obj = NULL;
  13058. obj = json_tokener_parse(line);
  13059. if(is_error(obj))
  13060. {
  13061. DEBUG_ERROR("Parse txProfile from file error.\n");
  13062. }
  13063. else
  13064. {
  13065. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13066. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13067. {
  13068. profileQuantity += 1;
  13069. }
  13070. else
  13071. replaceableProfileCnt += 1;
  13072. }
  13073. }
  13074. }
  13075. fclose(fp);
  13076. }
  13077. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13078. {
  13079. FILE *fp;
  13080. char filename[128]={0};
  13081. int tmpProfileQuantity;
  13082. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  13083. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13084. {
  13085. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13086. DEBUG_WARN("Profile connector id is over max gun number.\n");
  13087. goto end;
  13088. }
  13089. if(SetProfileReq.ConnectorId == 0)
  13090. {
  13091. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  13092. {
  13093. tmpProfileQuantity = 0;
  13094. memset(filename, 0, ARRAY_SIZE(filename));
  13095. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13096. fp = fopen(filename, "r");
  13097. if (!fp)
  13098. {
  13099. DEBUG_INFO("%s does not create.\n", filename);
  13100. fp = fopen(filename, "w+");
  13101. }
  13102. else
  13103. {
  13104. char *line = NULL;
  13105. size_t len = 0;
  13106. while(getline(&line, &len, fp) != -1)
  13107. {
  13108. json_object *obj = NULL;
  13109. obj = json_tokener_parse(line);
  13110. if(is_error(obj))
  13111. {
  13112. DEBUG_ERROR("Parse txProfile from file error.\n");
  13113. }
  13114. else
  13115. {
  13116. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13117. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13118. {
  13119. tmpProfileQuantity += 1;
  13120. }
  13121. else
  13122. replaceableProfileCnt += 1;
  13123. }
  13124. }
  13125. }
  13126. fclose(fp);
  13127. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  13128. }
  13129. }
  13130. else
  13131. {
  13132. memset(filename, 0, ARRAY_SIZE(filename));
  13133. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13134. fp = fopen(filename, "r");
  13135. if (!fp)
  13136. {
  13137. DEBUG_INFO("%s does not create.\n", filename);
  13138. fp = fopen(filename, "w+");
  13139. }
  13140. else
  13141. {
  13142. char *line = NULL;
  13143. size_t len = 0;
  13144. while(getline(&line, &len, fp) != -1)
  13145. {
  13146. json_object *obj = NULL;
  13147. obj = json_tokener_parse(line);
  13148. if(is_error(obj))
  13149. {
  13150. DEBUG_ERROR("Parse txProfile from file error.\n");
  13151. }
  13152. else
  13153. {
  13154. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13155. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13156. {
  13157. profileQuantity += 1;
  13158. }
  13159. else
  13160. replaceableProfileCnt += 1;
  13161. }
  13162. }
  13163. }
  13164. fclose(fp);
  13165. }
  13166. }
  13167. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13168. {
  13169. int isMatchTransactiodId= FALSE;
  13170. FILE *fp;
  13171. char filename[128]={0};
  13172. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13173. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13174. if(SetProfileReq.ConnectorId == 0)
  13175. {
  13176. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13177. DEBUG_WARN("Profile connector id is 0.\n");
  13178. goto end;
  13179. }
  13180. int tempIndex = 0;
  13181. //check Transaction active
  13182. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13183. {
  13184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13185. {
  13186. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13187. }
  13188. else
  13189. {
  13190. tempIndex = SetProfileReq.ConnectorId -1;
  13191. }
  13192. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13193. {
  13194. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13195. {
  13196. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13197. {
  13198. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13199. {
  13200. isMatchTransactiodId = TRUE;
  13201. break;
  13202. }
  13203. }
  13204. }
  13205. }
  13206. }
  13207. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13208. {
  13209. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13210. {
  13211. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13212. }
  13213. else
  13214. {
  13215. tempIndex = SetProfileReq.ConnectorId -1;
  13216. }
  13217. for (int index = 0; index < CCS_QUANTITY; index++)
  13218. {
  13219. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13220. {
  13221. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13222. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13223. {
  13224. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13225. {
  13226. isMatchTransactiodId = TRUE;
  13227. break;
  13228. }
  13229. }
  13230. }
  13231. }
  13232. }
  13233. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13234. {
  13235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13236. {
  13237. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13238. }
  13239. else
  13240. {
  13241. tempIndex = SetProfileReq.ConnectorId -1;
  13242. }
  13243. for (int index = 0; index < GB_QUANTITY; index++)
  13244. {
  13245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13246. {
  13247. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13248. {
  13249. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13250. {
  13251. isMatchTransactiodId = TRUE;
  13252. break;
  13253. }
  13254. }
  13255. }
  13256. }
  13257. }
  13258. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13259. {
  13260. tempIndex = SetProfileReq.ConnectorId -1;
  13261. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13262. {
  13263. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13264. {
  13265. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13266. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13267. {
  13268. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13269. {
  13270. isMatchTransactiodId = TRUE;
  13271. break;
  13272. }
  13273. }
  13274. }
  13275. }
  13276. }
  13277. else
  13278. {
  13279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13280. {
  13281. tempIndex = 2;
  13282. }
  13283. else
  13284. {
  13285. tempIndex = (SetProfileReq.ConnectorId -1);
  13286. }
  13287. for (int index = 0; index < AC_QUANTITY; index++)
  13288. {
  13289. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13290. {
  13291. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13292. {
  13293. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13294. {
  13295. isMatchTransactiodId = TRUE;
  13296. break;
  13297. }
  13298. }
  13299. }
  13300. }
  13301. }
  13302. //check Transaction active
  13303. if(isMatchTransactiodId == FALSE)
  13304. {
  13305. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13306. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13307. goto end;
  13308. }
  13309. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13310. {
  13311. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13312. DEBUG_WARN("Connector id is over max gun number.\n");
  13313. goto end;
  13314. }
  13315. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13316. fp = fopen(filename, "r");
  13317. if (!fp)
  13318. {
  13319. DEBUG_INFO("%s does not create.\n", filename);
  13320. fp = fopen(filename, "w+");
  13321. }
  13322. else
  13323. {
  13324. char *line = NULL;
  13325. size_t len = 0;
  13326. while(getline(&line, &len, fp) != -1)
  13327. {
  13328. json_object *obj = NULL;
  13329. obj = json_tokener_parse(line);
  13330. if(is_error(obj))
  13331. {
  13332. DEBUG_ERROR("Parse txProfile from file error.\n");
  13333. }
  13334. else
  13335. {
  13336. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13337. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13338. {
  13339. profileQuantity += 1;
  13340. }
  13341. else
  13342. replaceableProfileCnt += 1;
  13343. }
  13344. }
  13345. }
  13346. fclose(fp);
  13347. }
  13348. // Check ChargeProfileMaxStackLevel
  13349. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13350. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13351. {
  13352. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13353. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13354. goto end;
  13355. }
  13356. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13357. {
  13358. FILE *fp;
  13359. char dataLine[4096]={0};
  13360. char fnametemp[128]={0};
  13361. int tmpProfileQuantity;
  13362. //Check ChargePointMaxProfile.json exit
  13363. profileQuantity = 0;
  13364. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13365. {
  13366. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13367. //Check Charging Profile Count
  13368. tmpProfileQuantity = 0;
  13369. while(fscanf(fp, "%s", dataLine) != EOF)
  13370. {
  13371. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13372. {
  13373. profileQuantity += 1;
  13374. tmpProfileQuantity += 1;
  13375. }
  13376. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13377. }
  13378. fclose(fp);
  13379. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13380. }
  13381. //Check TxDefaultProfile_%d.json
  13382. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13383. {
  13384. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13385. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13386. if((access(fnametemp,F_OK))!=-1)
  13387. {
  13388. fp = fopen(fnametemp, "r");
  13389. //Check Charging Profile Count
  13390. tmpProfileQuantity = 0;
  13391. while(fscanf(fp, "%s", dataLine) != EOF)
  13392. {
  13393. //DEBUG_INFO("word=%s\n",word);
  13394. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13395. {
  13396. profileQuantity += 1;
  13397. tmpProfileQuantity += 1;
  13398. }
  13399. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13400. }
  13401. fclose(fp);
  13402. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13403. }
  13404. }
  13405. //Check TxProfile_%d.json
  13406. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13407. {
  13408. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13409. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13410. if((access(fnametemp,F_OK))!=-1)
  13411. {
  13412. fp = fopen(fnametemp, "r");
  13413. //Check Charging Profile Count
  13414. tmpProfileQuantity = 0;
  13415. while(fscanf(fp, "%s", dataLine) != EOF)
  13416. {
  13417. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13418. {
  13419. profileQuantity += 1;
  13420. tmpProfileQuantity += 1;
  13421. }
  13422. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13423. }
  13424. fclose(fp);
  13425. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13426. }
  13427. }
  13428. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13429. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13430. // To check total Profile quantity
  13431. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13432. {
  13433. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13434. {
  13435. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13436. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13437. goto end;
  13438. }
  13439. }
  13440. else
  13441. {
  13442. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13443. {
  13444. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13445. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13446. goto end;
  13447. }
  13448. }
  13449. }
  13450. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13451. //**********************************Write to File********************************************************/
  13452. {
  13453. FILE *infile;
  13454. FILE *outfile;
  13455. char dataLine[4096]={0};
  13456. char filename[128]={0};
  13457. int chkChar=0;
  13458. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13459. {
  13460. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13461. {
  13462. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13463. }
  13464. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13465. {
  13466. if(SetProfileReq.ConnectorId==0)
  13467. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13468. else
  13469. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13470. }
  13471. else
  13472. {
  13473. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13474. }
  13475. infile = fopen (filename, "r");
  13476. outfile = fopen (tempfile, "w");
  13477. chkChar = fgetc(infile);
  13478. rewind(infile);
  13479. if(chkChar == EOF)
  13480. {
  13481. // Profile is empty
  13482. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13483. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13484. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13485. fclose(infile);
  13486. fclose(outfile);
  13487. sprintf(rmFileCmd,"rm -f %s",filename);
  13488. system(rmFileCmd);
  13489. rename(tempfile, filename);
  13490. }
  13491. else
  13492. {
  13493. // Profile is not empty
  13494. int ChargingProfileAdded = FALSE;
  13495. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13496. {
  13497. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13498. json_object *tmpChargingProfile;
  13499. tmpChargingProfile = json_tokener_parse(dataLine);
  13500. if(!is_error(SetChargingProfile))
  13501. {
  13502. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13503. {
  13504. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13505. {
  13506. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13507. }
  13508. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13509. {
  13510. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13511. }
  13512. }
  13513. }
  13514. json_object_put(tmpChargingProfile);
  13515. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13516. {
  13517. if(ChargingProfileAdded == FALSE)
  13518. {
  13519. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13520. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13521. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13522. ChargingProfileAdded = TRUE;
  13523. }
  13524. }
  13525. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13526. {
  13527. if(ChargingProfileAdded == FALSE)
  13528. {
  13529. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13530. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13531. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13532. ChargingProfileAdded = TRUE;
  13533. }
  13534. }
  13535. else
  13536. {
  13537. fprintf(outfile,"%s\n",dataLine);
  13538. if(ChargingProfileAdded == FALSE)
  13539. {
  13540. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13541. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13542. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13543. ChargingProfileAdded = TRUE;
  13544. }
  13545. }
  13546. } // end of while loop
  13547. fclose(infile);
  13548. fclose(outfile);
  13549. sprintf(rmFileCmd,"rm -f %s",filename);
  13550. system(rmFileCmd);
  13551. rename(tempfile, filename);
  13552. }
  13553. }
  13554. sleep(1);
  13555. result = TRUE;
  13556. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13557. }
  13558. end:
  13559. json_object_put(SetChargingProfile);
  13560. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13561. {
  13562. if(SetProfileReq.ConnectorId == 0)
  13563. {
  13564. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13565. {
  13566. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13567. }
  13568. }
  13569. else
  13570. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13571. }
  13572. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13573. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13574. return result;
  13575. }
  13576. int handleTriggerMessageRequest(char *uuid, char *payload)
  13577. {
  13578. mtrace();
  13579. int result = FAIL;
  13580. int connectorIdIsNULL = FALSE;
  13581. int connectorIdInt =0;
  13582. char sstr[40]={0},sstrtemp[100]={ 0 };
  13583. char requestedMessagestr[40]={0};
  13584. char comfirmstr[20]={0};
  13585. int c = 0;
  13586. char *loc;
  13587. DEBUG_INFO("handleTriggerMessageRequest\n");
  13588. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13589. strcpy(sstrtemp, stringtrimspace(payload));
  13590. c = 0;
  13591. loc = strstr(sstrtemp, "requestedMessage");
  13592. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13593. {
  13594. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13595. c++;
  13596. }
  13597. sstr[c] = '\0';
  13598. strcpy(requestedMessagestr, sstr);
  13599. c = 0;
  13600. loc = strstr(sstrtemp, "connectorId");
  13601. if(loc == NULL)
  13602. {
  13603. connectorIdIsNULL = TRUE;
  13604. }
  13605. else
  13606. {
  13607. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13608. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13609. {
  13610. sstr[c] = loc[strlen("connectorId")+2+c];
  13611. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13612. c++;
  13613. }
  13614. sstr[c] = '\0';
  13615. connectorIdInt = atoi(sstr);
  13616. }
  13617. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13618. {
  13619. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13620. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13621. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13622. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13623. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13624. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13625. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13626. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13627. {
  13628. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13629. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13630. return TRUE;
  13631. }
  13632. else
  13633. {
  13634. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13635. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13636. }
  13637. }
  13638. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13639. {
  13640. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13641. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13642. return TRUE;
  13643. }
  13644. //==========================
  13645. // Trigger message
  13646. //==========================
  13647. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13648. {
  13649. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13650. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13651. {
  13652. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13653. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13654. }
  13655. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13656. }
  13657. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13658. {
  13659. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13660. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13661. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13662. }
  13663. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13664. {
  13665. //sendBootNotificationRequest();
  13666. server_sign = FALSE;
  13667. }
  13668. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13669. {
  13670. refreshStartTimer(&clientTime.Heartbeat);
  13671. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13672. }
  13673. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13674. {
  13675. if(connectorIdIsNULL == FALSE)
  13676. {
  13677. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13678. {
  13679. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13680. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13681. }
  13682. }
  13683. else
  13684. {
  13685. for(int idx=0;idx< gunTotalNumber;idx++)
  13686. {
  13687. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13688. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13689. }
  13690. }
  13691. }
  13692. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13693. {
  13694. if(connectorIdIsNULL == FALSE)
  13695. {
  13696. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13697. {
  13698. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13699. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13700. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13701. }
  13702. }
  13703. else
  13704. {
  13705. for(int idx=0;idx< gunTotalNumber;idx++)
  13706. {
  13707. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13708. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13709. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13710. }
  13711. }
  13712. }
  13713. return result;
  13714. }
  13715. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13716. {
  13717. mtrace();
  13718. int result = FAIL;
  13719. int connectorIdInt =0;
  13720. char comfirmstr[20]={0};
  13721. int tempIndex = 0;
  13722. json_object *UnlockConnector;
  13723. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13724. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13725. UnlockConnector = json_tokener_parse(payload);
  13726. if(!is_error(UnlockConnector))
  13727. {
  13728. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13729. {
  13730. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13731. }
  13732. }
  13733. json_object_put(UnlockConnector);
  13734. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13735. if(gunTotalNumber == 0)
  13736. {
  13737. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13738. goto end;
  13739. }
  13740. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13741. {
  13742. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13743. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13744. goto end;
  13745. }
  13746. else
  13747. {
  13748. //check Transaction active
  13749. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13750. {
  13751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13752. {
  13753. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13754. }
  13755. else
  13756. {
  13757. tempIndex = connectorIdInt -1;
  13758. }
  13759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13760. {
  13761. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13762. {
  13763. //stop Transaction
  13764. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13765. }
  13766. }
  13767. }
  13768. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13769. {
  13770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13771. {
  13772. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13773. }
  13774. else
  13775. {
  13776. tempIndex = connectorIdInt -1;
  13777. }
  13778. for (int index = 0; index < CCS_QUANTITY; index++)
  13779. {
  13780. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13781. {
  13782. //stop Transaction
  13783. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13784. }
  13785. }
  13786. }
  13787. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13788. {
  13789. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13790. {
  13791. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13792. }
  13793. else
  13794. {
  13795. tempIndex = connectorIdInt -1;
  13796. }
  13797. for (int index = 0; index < GB_QUANTITY; index++)
  13798. {
  13799. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13800. {
  13801. //stop Transaction
  13802. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13803. }
  13804. }
  13805. }
  13806. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13807. {
  13808. tempIndex = connectorIdInt -1;
  13809. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13810. {
  13811. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13812. {
  13813. //stop Transaction
  13814. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13815. }
  13816. }
  13817. }
  13818. else
  13819. {
  13820. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13821. {
  13822. tempIndex = 2;
  13823. }
  13824. else
  13825. {
  13826. tempIndex = connectorIdInt-1;
  13827. }
  13828. for (int index = 0; index < AC_QUANTITY; index++)
  13829. {
  13830. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13831. {
  13832. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13833. }
  13834. }
  13835. }
  13836. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13837. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13838. result = TRUE;
  13839. return result;
  13840. }
  13841. end:
  13842. //json_object_put(obj); --- remove temporally
  13843. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13844. return result;
  13845. }
  13846. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13847. {
  13848. mtrace();
  13849. int result = FAIL;
  13850. pthread_t t;
  13851. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13852. sendUpdateFirmwareConfirmation(uuid);
  13853. if(!interLock.isUpdateFirmwareGoing)
  13854. {
  13855. interLock.isUpdateFirmwareGoing = 1;
  13856. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13857. sleep(1);
  13858. }
  13859. else
  13860. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13861. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13862. return result;
  13863. }
  13864. void *UpdateFirmwareProcess(void *data)
  13865. {
  13866. pthread_detach(pthread_self());
  13867. mtrace();
  13868. int retriesInt =0, retryIntervalInt=0;
  13869. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13870. int port=0;
  13871. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13872. int isSuccess = 0;
  13873. char ftpbuf[1024];
  13874. char temp[1024];
  13875. char * pch;
  13876. json_object *UpdateFirmware;
  13877. UpdateFirmware = json_tokener_parse(data);
  13878. if(!is_error(UpdateFirmware))
  13879. {
  13880. // Required data
  13881. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13882. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13883. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13884. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13885. // Optional data
  13886. if(json_object_object_get(UpdateFirmware, "retries"))
  13887. {
  13888. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13889. }
  13890. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13891. {
  13892. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13893. }
  13894. }
  13895. json_object_put(UpdateFirmware);
  13896. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13897. memset(path, 0, ARRAY_SIZE(path));
  13898. // Wait retrieveData
  13899. if(strlen(retrieveDatestr) > 10)
  13900. {
  13901. do
  13902. {
  13903. sleep(1);
  13904. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13905. }
  13906. // Ready to download
  13907. system("rm -f /mnt/*");
  13908. if(strncmp(locationstr,"http", 4) == 0)
  13909. {
  13910. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13911. sprintf(ftppath,"/%s", path);
  13912. DEBUG_INFO("locationstr: %s\n", locationstr);
  13913. DEBUG_INFO("protocol: %s\n",protocol);
  13914. DEBUG_INFO("host: %s\n",host);
  13915. DEBUG_INFO("path: %s\n",path);
  13916. DEBUG_INFO("ftppath: %s\n",ftppath);
  13917. int ftppathlen=strlen(ftppath);
  13918. int i=1;
  13919. char filenametemp[50];
  13920. while(i < ftppathlen)
  13921. {
  13922. int len=ftppathlen-i;
  13923. if(ftppath[len]== 47) // '/' ascll code: 47
  13924. {
  13925. DEBUG_INFO("compare '/' all right\n");
  13926. break;
  13927. }
  13928. i=i+1;
  13929. }
  13930. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13931. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13932. filenametemp[i+1] = 0;
  13933. do
  13934. {
  13935. sleep(1);
  13936. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13937. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13938. sleep(1);
  13939. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13940. if(!isSuccess)
  13941. {
  13942. sleep(1);
  13943. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13944. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13945. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13946. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13947. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13948. }
  13949. else
  13950. {
  13951. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13952. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13953. }
  13954. retriesInt--;
  13955. }while((isSuccess == 0)&&(retriesInt >= 0));
  13956. }
  13957. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13958. {
  13959. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13960. memset(temp, 0, ARRAY_SIZE(temp));
  13961. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13962. strcpy(ftpbuf, locationstr);
  13963. int ftppathlen=strlen(ftpbuf);
  13964. int i=1;
  13965. char filenametemp[50];
  13966. while(i < ftppathlen)
  13967. {
  13968. int len=ftppathlen-i;
  13969. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13970. {
  13971. DEBUG_INFO(" compare '/' all right\n");
  13972. break;
  13973. }
  13974. i=i+1;
  13975. }
  13976. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13977. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13978. filenametemp[i+1] = 0;
  13979. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13980. pch=strchr(temp,'@');
  13981. if(pch==NULL)
  13982. {
  13983. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13984. protocol, host, &port, path);
  13985. strcpy(user,"anonymous");
  13986. strcpy(password,"");
  13987. }
  13988. else
  13989. {
  13990. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13991. protocol, user, host, &port, path);
  13992. }
  13993. sscanf(host,"%[^/]%s",host1, path1);
  13994. sprintf(ftppath,"%s:/%s", host,path);
  13995. if(port == 0)
  13996. {
  13997. port = 21;
  13998. }
  13999. do
  14000. {
  14001. sleep(1);
  14002. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  14003. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14004. sleep(1);
  14005. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  14006. if(!isSuccess)
  14007. {
  14008. //BulldogUtil.sleepMs(interval*1000);
  14009. DEBUG_INFO("Update firmware request and download file fail.\n");
  14010. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14011. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14012. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  14013. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14014. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14015. }
  14016. else
  14017. {
  14018. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  14019. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14020. }
  14021. retriesInt--;
  14022. }while((!isSuccess)&&(retriesInt >= 0));
  14023. }
  14024. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  14025. {
  14026. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14027. memset(temp, 0, ARRAY_SIZE(temp));
  14028. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14029. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  14030. int ftppathlen=strlen(ftpbuf);
  14031. int i=1;
  14032. char filenametemp[50];
  14033. while(i < ftppathlen)
  14034. {
  14035. int len=ftppathlen-i;
  14036. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14037. {
  14038. DEBUG_INFO(" compare '/' all right\n");
  14039. break;
  14040. }
  14041. i=i+1;
  14042. }
  14043. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14044. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  14045. filenametemp[i+1] = 0;
  14046. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14047. pch=strchr(temp,'@');
  14048. if(pch==NULL)
  14049. {
  14050. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14051. protocol, host, &port, path);
  14052. strcpy(user,"anonymous");
  14053. strcpy(password,"");
  14054. }
  14055. else
  14056. {
  14057. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14058. protocol, user, password, host, &port, path);
  14059. }
  14060. sscanf(host,"%[^/]%s",host1, path1);
  14061. sprintf(ftppath,"%s", path1);
  14062. //DEBUG_INFO("protocol =%s\n",protocol);
  14063. //DEBUG_INFO("user =%s\n",user);
  14064. //DEBUG_INFO("password =%s\n",password);
  14065. //DEBUG_INFO("host1 =%s\n",host1);
  14066. //DEBUG_INFO("port =%d\n",port);
  14067. //DEBUG_INFO("path1 =%s\n",path1);
  14068. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14069. //ftpFile(host, user, password, port, ftppath, fname);
  14070. //download firmware pthred
  14071. if(port == 0)
  14072. {
  14073. port = 21;
  14074. }
  14075. do
  14076. {
  14077. sleep(1);
  14078. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  14079. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14080. sleep(1);
  14081. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  14082. if(!isSuccess)
  14083. {
  14084. //BulldogUtil.sleepMs(interval*1000);
  14085. DEBUG_INFO("Update firmware request and download file fail.\n");
  14086. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14087. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14088. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  14089. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14090. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14091. }
  14092. else
  14093. {
  14094. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  14095. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14096. }
  14097. retriesInt--;
  14098. }while((!isSuccess)&&(retriesInt >= 0));
  14099. }
  14100. else
  14101. {
  14102. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14103. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14104. sleep(1);
  14105. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14106. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14107. }
  14108. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  14109. {
  14110. sleep(3);
  14111. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  14112. }
  14113. interLock.isUpdateFirmwareGoing = 0;
  14114. pthread_exit(NULL);
  14115. }
  14116. int handleCertificateSignedRequest(char *uuid, char *payload)
  14117. {
  14118. mtrace();
  14119. int result = PASS;
  14120. json_object *CertificateSigned;
  14121. DEBUG_INFO("handleCertificateSignedRequest...\n");
  14122. CertificateSigned = json_tokener_parse(payload);
  14123. if(!is_error(CertificateSigned))
  14124. {
  14125. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  14126. }
  14127. json_object_put(CertificateSigned);
  14128. FILE *fp = fopen(CERTIFICATE_CP, "w");
  14129. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  14130. fclose(fp);
  14131. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14132. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  14133. if(certVerify(PRIVATE_KEY_CP, CERTIFICATE_CP) == PASS)
  14134. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  14135. else
  14136. {
  14137. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  14138. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  14139. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14140. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14141. }
  14142. sendCertificateSignedConfirmation(uuid);
  14143. return result;
  14144. }
  14145. int handleDeleteCertificateRequest(char *uuid, char *payload)
  14146. {
  14147. mtrace();
  14148. int result = PASS;
  14149. json_object *DeleteCertificate;
  14150. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  14151. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14152. DeleteCertificate = json_tokener_parse(payload);
  14153. if(!is_error(DeleteCertificate))
  14154. {
  14155. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14156. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14157. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14158. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14159. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14160. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14161. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14162. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14163. char temp[256] = {0};
  14164. char compareData[256] = {0};
  14165. int isMatch = TRUE;
  14166. FILE *fp;
  14167. if(access(ROOTCA_CS,F_OK) != -1)
  14168. {
  14169. // Check CentralSystemRootCertificate
  14170. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14171. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14172. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14173. isMatch = FALSE;
  14174. if(isMatch == TRUE)
  14175. {
  14176. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14177. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14178. isMatch = FALSE;
  14179. }
  14180. if(isMatch == TRUE)
  14181. {
  14182. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14183. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14184. isMatch = FALSE;
  14185. }
  14186. if(isMatch == TRUE)
  14187. {
  14188. sprintf(temp, "rm -f /Storage/OCPP/%s", ROOTCA_CS);
  14189. system(temp);
  14190. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14191. goto End;
  14192. }
  14193. }
  14194. // Check ManufacturerRootCertificate
  14195. if(access(ROOTCA_MFG,F_OK) != -1)
  14196. {
  14197. isMatch = TRUE;
  14198. parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, compareData);
  14199. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14200. isMatch = FALSE;
  14201. if(isMatch == TRUE)
  14202. {
  14203. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, compareData);
  14204. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14205. isMatch = FALSE;
  14206. }
  14207. if(isMatch == TRUE)
  14208. {
  14209. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, compareData);
  14210. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14211. isMatch = FALSE;
  14212. }
  14213. if(isMatch == TRUE)
  14214. {
  14215. sprintf(temp, "rm -f %s", ROOTCA_MFG);
  14216. system(temp);
  14217. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14218. goto End;
  14219. }
  14220. }
  14221. // Check certCP
  14222. if(access(CERTIFICATE_CP,F_OK) != -1)
  14223. {
  14224. isMatch = FALSE;
  14225. sprintf(temp ,"openssl x509 -noout -serial -in %s", CERTIFICATE_CP);
  14226. fp = popen(temp, "r");
  14227. if(fp)
  14228. {
  14229. while(fgets(temp, sizeof(temp), fp) != NULL)
  14230. {
  14231. if(strstr(temp, "serial=") != NULL)
  14232. {
  14233. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14234. sscanf(temp, "%*[^=]=%s", compareData);
  14235. break;
  14236. }
  14237. }
  14238. }
  14239. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14240. isMatch = FALSE;
  14241. if(isMatch == TRUE)
  14242. {
  14243. memset(compareData, 0, ARRAY_SIZE(compareData));
  14244. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14245. fp = popen(temp, "r");
  14246. if(fp)
  14247. {
  14248. while(fgets(temp, sizeof(temp), fp) != NULL)
  14249. {
  14250. strcat(compareData, temp);
  14251. }
  14252. }
  14253. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  14254. isMatch = FALSE;
  14255. }
  14256. if(isMatch == TRUE)
  14257. {
  14258. memset(compareData, 0, ARRAY_SIZE(compareData));
  14259. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14260. fp = popen(temp, "r");
  14261. if(fp)
  14262. {
  14263. while(fgets(temp, sizeof(temp), fp) != NULL)
  14264. {
  14265. strcat(compareData, temp);
  14266. }
  14267. }
  14268. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14269. isMatch = FALSE;
  14270. }
  14271. if(isMatch == TRUE)
  14272. {
  14273. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14274. system(temp);
  14275. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14276. goto End;
  14277. }
  14278. }
  14279. }
  14280. End:
  14281. json_object_put(DeleteCertificate);
  14282. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14283. sendDeleteCertificateConfirmation(uuid);
  14284. return result;
  14285. }
  14286. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14287. {
  14288. mtrace();
  14289. int result = PASS;
  14290. json_object *ExtendedTriggerMessage;
  14291. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14292. ExtendedTriggerMessage = json_tokener_parse(payload);
  14293. if(!is_error(ExtendedTriggerMessage))
  14294. {
  14295. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14296. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14297. {
  14298. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14299. }
  14300. else
  14301. {
  14302. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14303. }
  14304. }
  14305. json_object_put(ExtendedTriggerMessage);
  14306. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14307. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14308. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14309. {
  14310. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14311. }
  14312. else
  14313. {
  14314. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14315. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14316. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14317. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14318. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14319. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14320. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14321. {
  14322. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14323. }
  14324. else
  14325. {
  14326. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14327. }
  14328. }
  14329. sendExtendedTriggerMessageConfirmation(uuid);
  14330. //==========================
  14331. // Trigger message
  14332. //==========================
  14333. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14334. {
  14335. //sendBootNotificationRequest();
  14336. server_sign = FALSE;
  14337. }
  14338. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14339. {
  14340. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14341. }
  14342. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14343. {
  14344. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14345. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14346. {
  14347. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14348. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14349. }
  14350. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14351. }
  14352. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14353. {
  14354. refreshStartTimer(&clientTime.Heartbeat);
  14355. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14356. }
  14357. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14358. {
  14359. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14360. {
  14361. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14362. }
  14363. else
  14364. {
  14365. for(int idx=0;idx< gunTotalNumber;idx++)
  14366. {
  14367. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14368. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14369. }
  14370. }
  14371. }
  14372. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14373. {
  14374. char cmdBuf[1024]={0};
  14375. 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);
  14376. system(cmdBuf);
  14377. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14378. }
  14379. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14380. {
  14381. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14382. {
  14383. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14384. }
  14385. else
  14386. {
  14387. for(int idx=0;idx< gunTotalNumber;idx++)
  14388. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14389. }
  14390. }
  14391. return result;
  14392. }
  14393. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14394. {
  14395. mtrace();
  14396. int result = PASS;
  14397. json_object *GetInstalledCertificateIds;
  14398. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14399. GetInstalledCertificateIds = json_tokener_parse(payload);
  14400. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14401. if(!is_error(GetInstalledCertificateIds))
  14402. {
  14403. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14404. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14405. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14406. // Check CentralSystemRootCertificate
  14407. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL) && (access(ROOTCA_CS,F_OK) != -1))
  14408. {
  14409. char parseData[512] = {0};
  14410. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14411. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14412. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, parseData) == PASS)
  14413. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14414. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14415. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14416. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14417. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14418. }
  14419. else
  14420. {
  14421. DEBUG_INFO(">>> No CentralSystemRootCertificate found.\n");
  14422. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14423. }
  14424. // Check ManufacturerRootCertificate
  14425. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL) && (access(ROOTCA_MFG,F_OK) != -1))
  14426. {
  14427. char parseData[512] = {0};
  14428. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14429. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14430. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14431. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14432. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14433. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14434. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14435. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14436. }
  14437. else
  14438. {
  14439. DEBUG_INFO(">>> No ManufacturerRootCertificate found.\n");
  14440. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14441. }
  14442. }
  14443. json_object_put(GetInstalledCertificateIds);
  14444. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14445. sendGetInstalledCertificateIdsConfirmation(uuid);
  14446. return result;
  14447. }
  14448. void* GetLogProcess(void* data)
  14449. {
  14450. pthread_detach(pthread_self());
  14451. mtrace();
  14452. 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};
  14453. int port=0;
  14454. int isSuccess = FALSE;
  14455. char cmdBuf[2048];
  14456. struct tm *tmNow;
  14457. time_t CurrentTime;
  14458. struct tm tmStart;
  14459. struct tm tmStop;
  14460. CurrentTime = time(NULL);
  14461. tmNow=localtime(&CurrentTime);
  14462. uint16_t targetYear, targetMonth;
  14463. json_object *GetLog;
  14464. DEBUG_INFO("GetLogProcess...\n");
  14465. GetLog = json_tokener_parse(data);
  14466. if(!is_error(GetLog))
  14467. {
  14468. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14469. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14470. if(json_object_object_get(GetLog, "retries") != NULL)
  14471. {
  14472. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14473. }
  14474. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14475. {
  14476. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14477. }
  14478. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14479. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14480. {
  14481. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14482. }
  14483. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14484. {
  14485. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14486. }
  14487. }
  14488. json_object_put(GetLog);
  14489. // Pack log to compress file
  14490. 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) &&
  14491. (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))
  14492. {
  14493. // Pack system log
  14494. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14495. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14496. targetYear = tmStart.tm_year;
  14497. targetMonth = tmStart.tm_mon;
  14498. do
  14499. {
  14500. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14501. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14502. if(targetMonth+1>=13)
  14503. {
  14504. targetYear += 1;
  14505. targetMonth = 1;
  14506. }
  14507. else
  14508. {
  14509. targetMonth += 1;
  14510. }
  14511. }while((targetYear < (tmNow->tm_year+1900)) ||
  14512. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14513. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14514. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14515. system(cmdBuf);
  14516. // Pack charging & event log
  14517. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14518. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14519. targetYear = tmStart.tm_year;
  14520. targetMonth = tmStart.tm_mon;
  14521. do
  14522. {
  14523. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14524. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14525. if(targetMonth+1>=13)
  14526. {
  14527. targetYear += 1;
  14528. targetMonth = 1;
  14529. }
  14530. else
  14531. {
  14532. targetMonth += 1;
  14533. }
  14534. }while((targetYear < (tmNow->tm_year+1900)) ||
  14535. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14536. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14537. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14538. system(cmdBuf);
  14539. // Combine log file
  14540. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14541. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14542. }
  14543. else
  14544. {
  14545. system("exec /root/logPackTools 'log' 6");
  14546. }
  14547. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14548. system(cmdBuf);
  14549. checkUploadLog();
  14550. //****************location*******************/
  14551. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14552. {
  14553. DEBUG_INFO("location is <Empty>!\n");
  14554. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14555. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14556. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14557. goto end;
  14558. }
  14559. memset(protocol, 0, ARRAY_SIZE(protocol));
  14560. memset(user, 0, ARRAY_SIZE(user) );
  14561. memset(password, 0, ARRAY_SIZE(password));
  14562. memset(host, 0, ARRAY_SIZE(host));
  14563. memset(path, 0, ARRAY_SIZE(path));
  14564. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14565. memset(host1, 0, ARRAY_SIZE(host1));
  14566. memset(path1, 0, ARRAY_SIZE(path1));
  14567. /*location: ftp://user:password@host:port/path*/
  14568. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14569. if((access(fnamePlusPath,F_OK))!=-1)
  14570. {
  14571. DEBUG_INFO("fnamePlusPath exist.\n");
  14572. }
  14573. else
  14574. {
  14575. DEBUG_INFO("fnamePlusPath not exist!\n");
  14576. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14577. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14578. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14579. goto end;
  14580. }
  14581. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14582. {
  14583. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14584. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14585. protocol, host, &port, path);
  14586. strcpy(user,"anonymous");
  14587. strcpy(password,"");
  14588. }
  14589. else
  14590. {
  14591. //DEBUG_INFO("pch=%s\n", pch);
  14592. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14593. protocol, user, password, host, &port, path);
  14594. }
  14595. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14596. {
  14597. DEBUG_INFO("protocol is not ftp/http ! \n");
  14598. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14599. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14600. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14601. goto end;
  14602. }
  14603. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14604. {
  14605. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14606. sprintf(ftppath,"/%s", path);
  14607. do
  14608. {
  14609. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14610. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14611. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14612. sleep(3);
  14613. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14614. if(!isSuccess)
  14615. {
  14616. DEBUG_INFO("Diagnostics fail.\n");
  14617. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14618. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14619. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14620. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14621. }
  14622. else
  14623. {
  14624. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14625. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14626. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14627. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14628. }
  14629. ShmOCPP16Data->GetLog.retries--;
  14630. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14631. }
  14632. else
  14633. {
  14634. sscanf(host,"%[^/]%s",host1, path1);
  14635. if(strlen(path) > 0)
  14636. sprintf(ftppath,"/%s", path);
  14637. else
  14638. sprintf(ftppath,"/%s", path1);
  14639. int ftppathlen=strlen(ftppath);
  14640. int i=1;
  14641. char filenametemp[50];
  14642. while(i < ftppathlen)
  14643. {
  14644. int len=ftppathlen-i;
  14645. if(ftppath[len]== 47) // '/' ascll code: 47
  14646. {
  14647. DEBUG_INFO("find '/' all right\n");
  14648. break;
  14649. }
  14650. i=i+1;
  14651. }
  14652. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14653. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14654. filenametemp[i+1] = 0;
  14655. if(port == 0)
  14656. port = 21;
  14657. do
  14658. {
  14659. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14660. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14661. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14662. sleep(3);
  14663. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14664. if(!isSuccess)
  14665. {
  14666. DEBUG_INFO("Diagnostics fail.\n");
  14667. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14668. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14669. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14670. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14671. }
  14672. else
  14673. {
  14674. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14675. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14676. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14677. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14678. }
  14679. ShmOCPP16Data->GetLog.retries--;
  14680. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14681. }
  14682. end:
  14683. system("rm -f /mnt/*");
  14684. sleep(5);
  14685. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14686. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14687. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14688. interLock.isGetDiagnosticGoing = 0;
  14689. pthread_exit(NULL);
  14690. }
  14691. int handleGetLogRequest(char *uuid, char *payload)
  14692. {
  14693. mtrace();
  14694. int result = PASS;
  14695. time_t CurrentTime;
  14696. struct tm *tm;
  14697. DEBUG_INFO("handleGetLogRequest...\n");
  14698. pthread_t th_Status;
  14699. CurrentTime = time(NULL);
  14700. tm = localtime(&CurrentTime);
  14701. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14702. 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);
  14703. if(!interLock.isGetDiagnosticGoing)
  14704. {
  14705. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14706. interLock.isGetDiagnosticGoing = 1;
  14707. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14708. sleep(1);
  14709. }
  14710. else
  14711. {
  14712. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14713. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14714. }
  14715. sendGetLogConfirmation(uuid);
  14716. return result;
  14717. }
  14718. int handleInstallCertificateRequest(char *uuid, char *payload)
  14719. {
  14720. mtrace();
  14721. int result = PASS;
  14722. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14723. json_object *InstallCertificate;
  14724. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14725. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14726. InstallCertificate = json_tokener_parse(payload);
  14727. if(!is_error(InstallCertificate))
  14728. {
  14729. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14730. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14731. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14732. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14733. char temp[1024];
  14734. FILE *fp = fopen(tempCert, "w");
  14735. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14736. fclose(fp);
  14737. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14738. char strExpDate[30];
  14739. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14740. fp = popen(temp, "r");
  14741. if(fp)
  14742. {
  14743. while(fgets(temp, sizeof(temp), fp) != NULL)
  14744. {
  14745. if(strstr(temp, "notAfter=") != NULL)
  14746. {
  14747. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14748. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14749. break;
  14750. }
  14751. }
  14752. }
  14753. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14754. struct tm tmExpDate;
  14755. struct timeb tbExpDate;
  14756. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14757. tbExpDate.time = mktime(&tmExpDate);
  14758. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14759. {
  14760. DEBUG_INFO("The enddate is already expired...\n");
  14761. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14762. goto End;
  14763. }
  14764. // Verify certificate with rootCA
  14765. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14766. fp = popen(temp, "r");
  14767. if(fp)
  14768. {
  14769. while(fgets(temp, sizeof(temp), fp) != NULL)
  14770. {
  14771. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14772. {
  14773. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14774. break;
  14775. }
  14776. else
  14777. {
  14778. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14779. }
  14780. }
  14781. }
  14782. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14783. {
  14784. //=====================================================
  14785. // Verify if the certificate is valid or not. (OCSP?)
  14786. //=====================================================
  14787. /*
  14788. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14789. // Get ocsp url
  14790. char ocspUrl[512];
  14791. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14792. fp = popen(temp, "r");
  14793. if(fp)
  14794. {
  14795. while(fgets(temp, sizeof(temp), fp) != NULL)
  14796. {
  14797. if(strstr(temp, "://") != NULL)
  14798. {
  14799. strcpy(ocspUrl, temp);
  14800. break;
  14801. }
  14802. }
  14803. }
  14804. // Get certificate chain for issuer
  14805. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14806. *
  14807. // Execute OCSP
  14808. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14809. fp = popen(temp, "r");
  14810. if(fp)
  14811. {
  14812. while(fgets(temp, sizeof(temp), fp) != NULL)
  14813. {
  14814. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14815. {
  14816. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14817. break;
  14818. }
  14819. }
  14820. }
  14821. system("rm -f /Storage/OCPP/tempChain.pem");
  14822. pclose(fp);
  14823. */
  14824. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14825. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14826. {
  14827. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14828. goto End;
  14829. }
  14830. else
  14831. DEBUG_INFO("OCSP verifying...PASS.\n");
  14832. }
  14833. else
  14834. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14835. }
  14836. End:
  14837. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14838. {
  14839. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14840. {
  14841. if(access(ROOTCA_CS,F_OK) != -1)
  14842. {
  14843. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14844. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14845. rename(tempCert, ROOTCA_CS);
  14846. }
  14847. else
  14848. {
  14849. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14850. rename(tempCert, ROOTCA_CS);
  14851. }
  14852. }
  14853. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14854. {
  14855. if(access(ROOTCA_MFG,F_OK) != -1)
  14856. {
  14857. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14858. rename(ROOTCA_MFG, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14859. rename(tempCert, ROOTCA_MFG);
  14860. }
  14861. else
  14862. {
  14863. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14864. rename(tempCert, ROOTCA_MFG);
  14865. }
  14866. }
  14867. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14868. }
  14869. sendInstallCertificateConfirmation(uuid);
  14870. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14871. {
  14872. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14873. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14874. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14875. }
  14876. json_object_put(InstallCertificate);
  14877. return result;
  14878. }
  14879. void *SignedUpdateFirmwareProcess(void *data)
  14880. {
  14881. pthread_detach(pthread_self());
  14882. mtrace();
  14883. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14884. int port=0;
  14885. int isSuccess = 0;
  14886. char ftpbuf[1024];
  14887. char temp[1024];
  14888. char * pch;
  14889. char firmwareFileName[50];
  14890. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14891. json_object *SignedUpdateFirmware;
  14892. SignedUpdateFirmware = json_tokener_parse(data);
  14893. if(!is_error(SignedUpdateFirmware))
  14894. {
  14895. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14896. {
  14897. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14898. }
  14899. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14900. {
  14901. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14902. }
  14903. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14904. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14905. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14906. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14907. {
  14908. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14909. }
  14910. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14911. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14912. }
  14913. json_object_put(SignedUpdateFirmware);
  14914. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14915. memset(path, 0, ARRAY_SIZE(path));
  14916. // Wait retrieveData
  14917. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14918. {
  14919. do
  14920. {
  14921. sleep(1);
  14922. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14923. }
  14924. // Ready to download
  14925. system("rm -f /mnt/*");
  14926. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14927. {
  14928. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14929. sprintf(ftppath,"/%s", path);
  14930. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14931. DEBUG_INFO("protocol: %s\n",protocol);
  14932. DEBUG_INFO("host: %s\n",host);
  14933. DEBUG_INFO("path: %s\n",path);
  14934. DEBUG_INFO("ftppath: %s\n",ftppath);
  14935. int ftppathlen=strlen(ftppath);
  14936. int i=1;
  14937. while(i < ftppathlen)
  14938. {
  14939. int len=ftppathlen-i;
  14940. if(ftppath[len]== 47) // '/' ascll code: 47
  14941. {
  14942. DEBUG_INFO("compare '/' all right\n");
  14943. break;
  14944. }
  14945. i=i+1;
  14946. }
  14947. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14948. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14949. firmwareFileName[i+1] = 0;
  14950. do
  14951. {
  14952. sleep(1);
  14953. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14954. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14955. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14956. sleep(1);
  14957. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14958. if(!isSuccess)
  14959. {
  14960. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14961. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14962. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14963. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14964. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14965. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14966. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14967. }
  14968. else
  14969. {
  14970. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14971. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14972. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14973. }
  14974. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14975. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14976. }
  14977. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14978. {
  14979. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14980. memset(temp, 0, ARRAY_SIZE(temp));
  14981. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14982. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14983. int ftppathlen=strlen(ftpbuf);
  14984. int i=1;
  14985. while(i < ftppathlen)
  14986. {
  14987. int len=ftppathlen-i;
  14988. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14989. {
  14990. DEBUG_INFO(" compare '/' all right\n");
  14991. break;
  14992. }
  14993. i=i+1;
  14994. }
  14995. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14996. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14997. firmwareFileName[i+1] = 0;
  14998. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14999. pch=strchr(temp,'@');
  15000. if(pch==NULL)
  15001. {
  15002. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15003. protocol, host, &port, path);
  15004. strcpy(user,"anonymous");
  15005. strcpy(password,"");
  15006. }
  15007. else
  15008. {
  15009. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  15010. protocol, user, host, &port, path);
  15011. }
  15012. sscanf(host,"%[^/]%s",host1, path1);
  15013. sprintf(ftppath,"%s:/%s", host,path);
  15014. if(port == 0)
  15015. {
  15016. port = 21;
  15017. }
  15018. do
  15019. {
  15020. sleep(1);
  15021. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15022. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15023. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15024. sleep(1);
  15025. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15026. if(!isSuccess)
  15027. {
  15028. sleep(1);
  15029. DEBUG_INFO("Update firmware request and download file fail.\n");
  15030. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15031. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15032. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15033. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15034. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15035. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15036. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15037. }
  15038. else
  15039. {
  15040. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15041. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15042. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15043. }
  15044. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15045. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15046. }
  15047. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  15048. {
  15049. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15050. memset(temp, 0, ARRAY_SIZE(temp));
  15051. //DEBUG_INFO("locationstr=%s\n",locationstr);
  15052. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15053. int ftppathlen=strlen(ftpbuf);
  15054. int i=1;
  15055. while(i < ftppathlen)
  15056. {
  15057. int len=ftppathlen-i;
  15058. if(ftpbuf[len]== 47) // '/' ascll code: 47
  15059. {
  15060. DEBUG_INFO(" compare '/' all right\n");
  15061. break;
  15062. }
  15063. i=i+1;
  15064. }
  15065. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  15066. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  15067. firmwareFileName[i+1] = 0;
  15068. strncpy(temp, ftpbuf, ftppathlen-i+1);
  15069. pch=strchr(temp,'@');
  15070. if(pch==NULL)
  15071. {
  15072. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15073. protocol, host, &port, path);
  15074. strcpy(user,"anonymous");
  15075. strcpy(password,"");
  15076. }
  15077. else
  15078. {
  15079. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  15080. protocol, user, password, host, &port, path);
  15081. }
  15082. sscanf(host,"%[^/]%s",host1, path1);
  15083. sprintf(ftppath,"%s", path1);
  15084. //DEBUG_INFO("protocol =%s\n",protocol);
  15085. //DEBUG_INFO("user =%s\n",user);
  15086. //DEBUG_INFO("password =%s\n",password);
  15087. //DEBUG_INFO("host1 =%s\n",host1);
  15088. //DEBUG_INFO("port =%d\n",port);
  15089. //DEBUG_INFO("path1 =%s\n",path1);
  15090. //DEBUG_INFO("ftppath=%s\n",ftppath);
  15091. //ftpFile(host, user, password, port, ftppath, fname);
  15092. //download firmware pthred
  15093. if(port == 0)
  15094. {
  15095. port = 21;
  15096. }
  15097. do
  15098. {
  15099. sleep(1);
  15100. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15101. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15102. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15103. sleep(1);
  15104. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15105. if(!isSuccess)
  15106. {
  15107. //BulldogUtil.sleepMs(interval*1000);
  15108. DEBUG_INFO("Update firmware request and download file fail.\n");
  15109. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15110. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15111. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15112. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15113. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15114. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15115. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15116. }
  15117. else
  15118. {
  15119. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15120. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15121. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15122. }
  15123. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15124. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15125. }
  15126. else
  15127. {
  15128. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15129. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15130. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15131. sleep(1);
  15132. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15133. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15134. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15135. }
  15136. // Verify firmware image signature
  15137. struct stat st;
  15138. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15139. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15140. fclose(fp);
  15141. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15142. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15143. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15144. fclose(fp);
  15145. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15146. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15147. if(st.st_size == 0)
  15148. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15149. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15150. {
  15151. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15152. fp = popen(temp, "r");
  15153. if(fp)
  15154. {
  15155. while(fgets(temp, sizeof(temp), fp) != NULL)
  15156. {
  15157. if(strstr(temp, "Verified OK") != NULL)
  15158. {
  15159. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15160. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15161. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15162. }
  15163. else
  15164. {
  15165. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15166. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15167. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15168. sleep(1);
  15169. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15170. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15171. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15172. sleep(1);
  15173. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15174. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15175. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15176. }
  15177. break;
  15178. }
  15179. }
  15180. pclose(fp);
  15181. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15182. }
  15183. interLock.isUpdateFirmwareGoing = 0;
  15184. pthread_exit(NULL);
  15185. }
  15186. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15187. {
  15188. mtrace();
  15189. int result = PASS;
  15190. pthread_t t;
  15191. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15192. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15193. sendSignedUpdateFirmwareConfirmation(uuid);
  15194. if(!interLock.isUpdateFirmwareGoing)
  15195. {
  15196. interLock.isUpdateFirmwareGoing = 1;
  15197. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15198. sleep(1);
  15199. }
  15200. else
  15201. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15202. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15203. return result;
  15204. }
  15205. int handleUnknownRequest(char *uuid, char *payload)
  15206. {
  15207. mtrace();
  15208. int result = PASS;
  15209. DEBUG_INFO("handleUnknownRequest...\n");
  15210. sendUnknownConfirmation(uuid);
  15211. return result;
  15212. }
  15213. //==========================================
  15214. // Handle server response routine
  15215. //==========================================
  15216. void handleAuthorizeResponse(char *payload, int gun_index)
  15217. {
  15218. mtrace();
  15219. char expiryDatestr[36]={0};
  15220. char parentIdTagstr[21]={0};
  15221. char statusstr[20]={0};
  15222. int expiryDateISNULL=FALSE;
  15223. int parentIdTagISNULL=FALSE;
  15224. DEBUG_INFO("handleAuthorizeResponse...\n");
  15225. json_object *Authorize;
  15226. Authorize = json_tokener_parse(payload);
  15227. if(!is_error(Authorize))
  15228. {
  15229. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15230. {
  15231. // Required data
  15232. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15233. // Optional data
  15234. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15235. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15236. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15237. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15238. }
  15239. }
  15240. json_object_put(Authorize);
  15241. if(expiryDateISNULL == FALSE)
  15242. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15243. if(parentIdTagISNULL == FALSE)
  15244. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15245. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15246. //Update idTag information to authorization cache if supproted
  15247. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15248. {
  15249. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15250. }
  15251. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15252. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15253. authorizeRetryTimes = 0;
  15254. }
  15255. void handleBootNotificationResponse(char *payload, int gun_index)
  15256. {
  15257. mtrace();
  15258. char statusStr[12]={0};
  15259. char currentTimeStr[30]={0};
  15260. int intervalInt = 0;
  15261. DEBUG_INFO("handleBootNotificationResponse...\n");
  15262. json_object *BootNotification;
  15263. BootNotification = json_tokener_parse(payload);
  15264. if(!is_error(BootNotification))
  15265. {
  15266. // Required data
  15267. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15268. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15269. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15270. }
  15271. json_object_put(BootNotification);
  15272. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15273. BootNotificationInterval = intervalInt;
  15274. //write back to ShmOCPP16Data->BootNotification
  15275. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15276. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15277. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15278. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15279. {
  15280. BootNotificationInterval = 0;
  15281. if((intervalInt == 0) || (intervalInt >= 10))
  15282. {
  15283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15284. HeartBeatWaitTime = intervalInt;
  15285. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15286. }
  15287. server_sign = TRUE;
  15288. server_pending =FALSE;
  15289. }
  15290. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15291. {
  15292. server_pending = TRUE;
  15293. }
  15294. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15295. srand(time(NULL));
  15296. refreshStartTimer(&clientTime.Heartbeat);
  15297. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15298. SetOcppConnStatus(TRUE);
  15299. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15300. }
  15301. void handleDataTransferResponse(char *payload, int gun_index)
  15302. {
  15303. json_object *DataTransfer = json_tokener_parse(payload);
  15304. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15305. if(!is_error(DataTransfer))
  15306. {
  15307. // Required data
  15308. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15309. // Optional data
  15310. if(json_object_object_get(DataTransfer, "data") != NULL)
  15311. {
  15312. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15313. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15314. if(!is_error(Data))
  15315. {
  15316. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15317. {
  15318. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15319. {
  15320. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15321. }
  15322. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15323. {
  15324. 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")));
  15325. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15326. {
  15327. 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")));
  15328. }
  15329. }
  15330. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15331. }
  15332. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15333. {
  15334. if(json_object_object_get(Data, "status") != NULL)
  15335. {
  15336. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15337. }
  15338. if(json_object_object_get(Data, "exiResponse") != NULL)
  15339. {
  15340. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15341. }
  15342. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15343. }
  15344. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15345. {
  15346. if(json_object_object_get(Data, "status") != NULL)
  15347. {
  15348. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15349. }
  15350. if(json_object_object_get(Data, "ocspResult") != NULL)
  15351. {
  15352. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15353. }
  15354. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15355. }
  15356. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15357. {
  15358. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15359. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15360. }
  15361. else
  15362. {
  15363. if(json_object_object_get(Data, "msgId") != NULL)
  15364. {
  15365. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15366. {
  15367. 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")));
  15368. }
  15369. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15370. {
  15371. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15372. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15373. }
  15374. }
  15375. }
  15376. }
  15377. json_object_put(Data);
  15378. }
  15379. }
  15380. json_object_put(DataTransfer);
  15381. }
  15382. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15383. {
  15384. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15385. //struct json_object *obj;
  15386. // obj = json_tokener_parse(payload);
  15387. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15388. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15389. //No fields are defined.
  15390. }
  15391. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15392. {
  15393. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15394. //struct json_object *obj;
  15395. // obj = json_tokener_parse(payload);
  15396. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15397. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15398. //No fields are defined.
  15399. }
  15400. void handleHeartbeatResponse(char *payload, int gun_index)
  15401. {
  15402. mtrace();
  15403. DEBUG_INFO("handleHeartbeatResponse...\n");
  15404. json_object *Heartbeat;
  15405. Heartbeat = json_tokener_parse(payload);
  15406. if(!is_error(Heartbeat))
  15407. {
  15408. // Required data
  15409. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15410. }
  15411. json_object_put(Heartbeat);
  15412. if(FirstHeartBeat == 0)
  15413. {
  15414. FirstHeartBeat = 1;
  15415. DEBUG_INFO("FirstHeartBeat \n");
  15416. }
  15417. HeartBeatWithNOResponse = 0;
  15418. refreshStartTimer(&clientTime.Heartbeat);
  15419. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15420. }
  15421. void handleMeterValuesResponse(char *payload, int gun_index)
  15422. {
  15423. mtrace();
  15424. DEBUG_INFO("handleMeterValuesResponse...\n");
  15425. isQueueSendable = 1;
  15426. }
  15427. void handleStartTransactionResponse(char *payload, int gun_index)
  15428. {
  15429. mtrace();
  15430. //int transactionIdInt = 0;
  15431. FILE *outfile;
  15432. char data[100]={0};
  15433. DEBUG_INFO("handleStartTransactionResponse...\n");
  15434. json_object *StartTransaction;
  15435. StartTransaction = json_tokener_parse(payload);
  15436. if(!is_error(StartTransaction))
  15437. {
  15438. // Required data
  15439. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15440. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15441. // Optional data
  15442. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15443. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15444. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15445. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15446. }
  15447. json_object_put(StartTransaction);
  15448. OCPP_updatePeriodEnergy(gun_index);
  15449. //-----------Start : write to the Queue TransactionId file -----------------//
  15450. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15451. {}
  15452. else
  15453. {
  15454. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15455. if(log == NULL)
  15456. {
  15457. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15458. return ;
  15459. }
  15460. else
  15461. {
  15462. fclose(log);
  15463. }
  15464. }
  15465. // open file for writing
  15466. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15467. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15468. {
  15469. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15470. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15471. fputs(data, outfile);
  15472. fclose (outfile);
  15473. }
  15474. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15475. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15476. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15477. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15478. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15479. isQueueSendable = 1;
  15480. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15481. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15482. }
  15483. void handleStatusNotificationResponse(char *payload, int gun_index)
  15484. {
  15485. mtrace();
  15486. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15487. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15488. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15489. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15490. }
  15491. void handleStopTransactionnResponse(char *payload, int gun_index)
  15492. {
  15493. mtrace();
  15494. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15495. json_object *StopTransaction;
  15496. StopTransaction = json_tokener_parse(payload);
  15497. if(!is_error(StopTransaction))
  15498. {
  15499. // Optional data
  15500. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15501. {
  15502. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15503. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15504. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15505. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15506. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15507. }
  15508. }
  15509. json_object_put(StopTransaction);
  15510. isQueueSendable = 1;
  15511. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15512. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15513. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15514. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15515. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15516. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15517. }
  15518. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15519. {
  15520. mtrace();
  15521. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15522. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15523. }
  15524. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15525. {
  15526. mtrace();
  15527. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15528. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15529. }
  15530. void handleSignCertificateResponse(char *payload, int gun_index)
  15531. {
  15532. mtrace();
  15533. DEBUG_INFO("handleSignCertificateResponse...\n");
  15534. json_object *SignCertificate;
  15535. SignCertificate = json_tokener_parse(payload);
  15536. if(!is_error(SignCertificate))
  15537. {
  15538. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15539. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15540. }
  15541. json_object_put(SignCertificate);
  15542. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15543. }
  15544. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15545. {
  15546. mtrace();
  15547. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15548. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15549. }
  15550. //==========================================
  15551. // Handle Error routine
  15552. //==========================================
  15553. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15554. {
  15555. mtrace();
  15556. #ifdef SystemLogMessage
  15557. DEBUG_INFO("errorCode: %s\n", errorCode);
  15558. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15559. DEBUG_INFO("errorDetails: %s\n", payload);
  15560. #endif
  15561. }
  15562. //===============================================
  15563. // Common routine
  15564. //===============================================
  15565. int initialConfigurationTable(void)
  15566. {
  15567. //clock_t start_t, end_t, total_t;
  15568. FILE *fp;
  15569. FILE *outfile;
  15570. char str[512]={0};
  15571. char sstr[256]={0};
  15572. int c = 0;
  15573. char *loc;
  15574. int confVersion = 21;
  15575. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15576. //start_t = clock();
  15577. //printf("Starting of the program, start_t = %ld\n", start_t);
  15578. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15579. // Check configuration file size is correct
  15580. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15581. {
  15582. struct stat st;
  15583. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15584. if(st.st_size < 3100)
  15585. {
  15586. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15587. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15588. }
  15589. }
  15590. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15591. {
  15592. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15593. if(outfile == NULL)
  15594. {
  15595. DEBUG_INFO("Error opening file\n");
  15596. return FALSE;
  15597. }
  15598. /*Core Profile*/
  15599. //AllowOfflineTxForUnknownId
  15600. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15604. //AuthorizationCacheEnabled
  15605. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15609. //AuthorizeRemoteTxRequests
  15610. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15614. //BlinkRepeat
  15615. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15619. //ClockAlignedDataInterval
  15620. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15624. //ConnectionTimeOut
  15625. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15627. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15629. else
  15630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15632. //GetConfigurationMaxKeys
  15633. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15637. // HeartbeatInterval
  15638. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15642. // LightIntensity
  15643. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15647. // LocalAuthorizeOffline
  15648. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15652. // LocalPreAuthorize
  15653. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15657. // MaxEnergyOnInvalidId
  15658. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15662. // MeterValuesAlignedData
  15663. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15665. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15666. 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" );
  15667. else
  15668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15670. // MeterValuesAlignedDataMaxLength
  15671. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15675. else
  15676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15678. // MeterValuesSampledData
  15679. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15681. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15682. 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" );
  15683. else
  15684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15686. // MeterValuesSampledDataMaxLength
  15687. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15691. else
  15692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15694. // MeterValueSampleInterval
  15695. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15699. // MinimumStatusDuration
  15700. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15703. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15705. // NumberOfConnectors
  15706. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15708. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15709. {
  15710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15711. }
  15712. else
  15713. {
  15714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15715. }
  15716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15717. // ResetRetries
  15718. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15722. // ConnectorPhaseRotation
  15723. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15727. // ConnectorPhaseRotationMaxLength
  15728. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15732. // StopTransactionOnEVSideDisconnect
  15733. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15737. // StopTransactionOnInvalidId
  15738. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15742. // StopTxnAlignedData
  15743. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15747. // StopTxnAlignedDataMaxLength
  15748. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15752. // StopTxnSampledData
  15753. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15755. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  15757. else
  15758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  15759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15760. // StopTxnSampledDataMaxLength
  15761. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15764. {
  15765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  15766. }
  15767. else
  15768. {
  15769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  15770. }
  15771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15772. // SupportedFeatureProfiles
  15773. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15777. // SupportedFeatureProfilesMaxLength
  15778. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15782. // TransactionMessageAttempts
  15783. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15786. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15788. // TransactionMessageRetryInterval
  15789. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15792. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15794. // UnlockConnectorOnEVSideDisconnect
  15795. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15799. // WebSocketPingInterval
  15800. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15804. // QueueOffLineMeterValues
  15805. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15809. // AuthorizationKey
  15810. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15814. // SecurityProfile
  15815. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15819. // DefaultPrice
  15820. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15824. // CustomDisplayCostAndPrice
  15825. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15829. // CustomIdleFeeAfterStop
  15830. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15834. // TimeOffset
  15835. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15839. // NextTimeOffsetTransitionDateTime
  15840. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15844. // TimeOffsetNextTransition
  15845. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15849. // SystemUptimeSec
  15850. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15854. // FreeVend
  15855. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15859. // FreeVendIdtag
  15860. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15864. // OcppServer
  15865. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15867. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15869. // MaintainServer
  15870. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15872. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15874. // StatusNotificationPeriodically
  15875. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15879. // StatusNotificationInterval
  15880. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15884. // PreAuthAmount
  15885. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15889. // isEnableLocalPowerSharing
  15890. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15894. // PowerSharingServerIP
  15895. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15897. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15899. // EVCCID_PREFIX
  15900. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15904. // OffLineMaxChargingPower
  15905. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15909. // Configuration Version
  15910. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15914. // Charging profile refresh interval
  15915. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15919. // CpoName
  15920. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15924. // Ocpp Software certificated version
  15925. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15929. //* Local Auth List Management Profile*/
  15930. #if 0
  15931. //For OCTT Test Case
  15932. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15935. #endif
  15936. #if 1
  15937. //LocalAuthListEnabled
  15938. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15942. #endif
  15943. //LocalAuthListMaxLength
  15944. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15948. //SendLocalListMaxLength
  15949. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15953. //ReserveConnectorZeroSupported
  15954. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15958. //* Smart Charging Profile */
  15959. //ChargeProfileMaxStackLevel
  15960. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15964. // ChargingScheduleAllowedChargingRateUnit
  15965. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15969. // ChargingScheduleMaxPeriods
  15970. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15974. // ConnectorSwitch3to1PhaseSupported
  15975. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15979. // MaxChargingProfilesInstalled
  15980. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15984. fclose(outfile);
  15985. }
  15986. else
  15987. {
  15988. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15989. char keystr[60]={0};
  15990. char readonlystr[10]={0};
  15991. char valuestr[256]={0};
  15992. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15993. if(fp == NULL) {
  15994. DEBUG_INFO("Error opening file");
  15995. return FALSE;
  15996. }
  15997. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15998. {
  15999. //DEBUG_INFO("Get Configuration \n");
  16000. if(strlen(str) > 0)
  16001. {
  16002. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16003. //*************************key*********************************/
  16004. if(strstr(str, "key") != NULL)
  16005. {
  16006. loc = strstr(str, "key");
  16007. c = 0;
  16008. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16009. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  16010. {
  16011. sstr[c] = loc[strlen("key")+3+c];
  16012. c++;
  16013. }
  16014. sstr[c] = '\0';
  16015. strcpy(keystr,sstr);
  16016. }
  16017. //*************************readonly*********************************/
  16018. if(strstr(str, "readonly") != NULL)
  16019. {
  16020. loc = strstr(str, "readonly");
  16021. c = 0;
  16022. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16023. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  16024. {
  16025. sstr[c] = loc[strlen("readonly")+2+c];
  16026. c++;
  16027. }
  16028. sstr[c] = '\0';
  16029. strcpy(readonlystr,sstr);
  16030. }
  16031. //*************************value*********************************/
  16032. if(strstr(str, "value") != NULL)
  16033. {
  16034. loc = strstr(str, "value");
  16035. c = 0;
  16036. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16037. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  16038. {
  16039. sstr[c] = loc[strlen("value")+3+c];
  16040. c++;
  16041. }
  16042. sstr[c] = '\0';
  16043. strcpy(valuestr,sstr);
  16044. }
  16045. // DEBUG_INFO("keystr=%s\n",keystr);
  16046. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  16047. // DEBUG_INFO("valuestr=%s\n",valuestr);
  16048. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  16049. {
  16050. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16051. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  16053. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16054. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16055. }
  16056. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  16057. {
  16058. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16059. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  16061. }
  16062. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  16063. {
  16064. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  16066. }
  16067. if(strcmp(keystr, "BlinkRepeat") == 0)
  16068. {
  16069. //Charger.BlinkRepeat = Integer.parseInt(value);
  16070. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  16072. }
  16073. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  16074. {
  16075. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  16077. }
  16078. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16079. {
  16080. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16082. }
  16083. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16084. {
  16085. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16087. }
  16088. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16089. {
  16090. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16092. HeartBeatWaitTime = atoi(valuestr);
  16093. }
  16094. if(strcmp(keystr, "LightIntensity") == 0)
  16095. {
  16096. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16098. }
  16099. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16100. {
  16101. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16103. }
  16104. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16105. {
  16106. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16108. }
  16109. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16110. {
  16111. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16113. }
  16114. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16115. {
  16116. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16118. }
  16119. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16120. {
  16121. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16123. }
  16124. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16125. {
  16126. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16128. }
  16129. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16130. {
  16131. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16133. }
  16134. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16135. {
  16136. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16138. }
  16139. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16140. {
  16141. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16143. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16144. }
  16145. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16146. {
  16147. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16149. }
  16150. if(strcmp(keystr, "ResetRetries") == 0)
  16151. {
  16152. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16154. }
  16155. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16156. {
  16157. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16159. }
  16160. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16161. {
  16162. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16164. }
  16165. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16166. {
  16167. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16169. }
  16170. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16171. {
  16172. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16174. }
  16175. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16176. {
  16177. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16179. }
  16180. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16181. {
  16182. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16184. }
  16185. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16186. {
  16187. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16189. }
  16190. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16191. {
  16192. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16194. }
  16195. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16196. {
  16197. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16199. }
  16200. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16201. {
  16202. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16204. }
  16205. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16206. {
  16207. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16209. TransactionMessageAttemptsValue = atoi(valuestr);
  16210. }
  16211. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16212. {
  16213. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16215. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16216. }
  16217. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16218. {
  16219. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16221. }
  16222. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16223. {
  16224. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16226. }
  16227. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16228. {
  16229. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16231. }
  16232. if(strcmp(keystr, "AuthorizationKey") == 0)
  16233. {
  16234. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16235. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16237. }
  16238. if(strcmp(keystr, "SecurityProfile") == 0)
  16239. {
  16240. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16242. }
  16243. if(strcmp(keystr, "DefaultPrice") == 0)
  16244. {
  16245. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16247. }
  16248. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16249. {
  16250. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16252. }
  16253. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16254. {
  16255. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16257. }
  16258. if(strcmp(keystr, "TimeOffset") == 0)
  16259. {
  16260. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16262. }
  16263. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16264. {
  16265. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16267. }
  16268. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16269. {
  16270. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16272. }
  16273. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16274. {
  16275. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16277. }
  16278. if(strcmp(keystr, "FreeVend") == 0)
  16279. {
  16280. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16282. }
  16283. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16284. {
  16285. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16287. }
  16288. if(strcmp(keystr, "OcppServer") == 0)
  16289. {
  16290. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16291. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16292. }
  16293. if(strcmp(keystr, "MaintainServer") == 0)
  16294. {
  16295. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16296. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16297. }
  16298. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16299. {
  16300. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16302. }
  16303. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16304. {
  16305. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16307. }
  16308. if(strcmp(keystr, "PreAuthAmount") == 0)
  16309. {
  16310. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16312. }
  16313. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16314. {
  16315. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16317. }
  16318. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16319. {
  16320. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16321. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16322. }
  16323. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16324. {
  16325. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16327. }
  16328. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16329. {
  16330. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16332. }
  16333. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16334. {
  16335. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16337. }
  16338. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16339. {
  16340. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16342. }
  16343. if(strcmp(keystr, "CpoName") == 0)
  16344. {
  16345. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16347. }
  16348. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16349. {
  16350. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16352. }
  16353. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16354. {
  16355. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16357. }
  16358. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16359. {
  16360. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16362. }
  16363. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16364. {
  16365. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16367. }
  16368. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16369. {
  16370. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16372. }
  16373. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16374. {
  16375. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16377. }
  16378. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16379. {
  16380. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16382. }
  16383. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16384. {
  16385. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16387. }
  16388. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16389. {
  16390. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16392. }
  16393. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16394. {
  16395. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16397. }
  16398. }
  16399. }
  16400. fclose(fp);
  16401. }
  16402. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16403. {
  16404. return PASS;
  16405. }
  16406. else
  16407. {
  16408. return FAIL;
  16409. }
  16410. }
  16411. void StoreConfigurationTable(void)
  16412. {
  16413. FILE *outfile;
  16414. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16415. if(outfile == NULL)
  16416. {
  16417. DEBUG_INFO("Error opening file");
  16418. return ;
  16419. }
  16420. /*Core Profile*/
  16421. //AllowOfflineTxForUnknownId
  16422. /*
  16423. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16424. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16427. */
  16428. //DEBUG_INFO("data=%s\n",data);
  16429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16430. //AuthorizationCacheEnabled
  16431. /*
  16432. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16435. */
  16436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16437. //AuthorizeRemoteTxRequests
  16438. /*
  16439. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16442. */
  16443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16444. //BlinkRepeat
  16445. /*
  16446. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16449. */
  16450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16451. //ClockAlignedDataInterval
  16452. /*
  16453. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16456. */
  16457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16458. //ConnectionTimeOut
  16459. /*
  16460. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16463. */
  16464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16465. //GetConfigurationMaxKeys
  16466. /*
  16467. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16470. */
  16471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16472. // HeartbeatInterval
  16473. /*
  16474. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16477. */
  16478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16479. // LightIntensity
  16480. /*
  16481. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16484. */
  16485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16486. // LocalAuthorizeOffline
  16487. /*
  16488. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16491. */
  16492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16493. // LocalPreAuthorize
  16494. /*
  16495. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16498. */
  16499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16500. // MaxEnergyOnInvalidId
  16501. /*
  16502. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16505. */
  16506. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16508. // MeterValuesAlignedData
  16509. /*
  16510. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16513. */
  16514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16515. // MeterValuesAlignedDataMaxLength
  16516. /*
  16517. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16520. */
  16521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16522. // MeterValuesSampledData
  16523. /*
  16524. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16527. */
  16528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16529. // MeterValuesSampledDataMaxLength
  16530. /*
  16531. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16534. */
  16535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16536. // MeterValueSampleInterval
  16537. /*
  16538. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16541. */
  16542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16543. // MinimumStatusDuration
  16544. /*
  16545. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16548. */
  16549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16550. // NumberOfConnectors
  16551. /*
  16552. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16554. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16555. {
  16556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16557. }
  16558. else
  16559. {
  16560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16561. }
  16562. */
  16563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16564. // ResetRetries
  16565. /*
  16566. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16569. */
  16570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16571. // ConnectorPhaseRotation
  16572. /*
  16573. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16576. */
  16577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16578. // ConnectorPhaseRotationMaxLength
  16579. /*
  16580. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16583. */
  16584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16585. // StopTransactionOnEVSideDisconnect
  16586. /*
  16587. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16590. */
  16591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16592. // StopTransactionOnInvalidId
  16593. /*
  16594. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16597. */
  16598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16599. // StopTxnAlignedData
  16600. /*
  16601. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16604. */
  16605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16606. // StopTxnAlignedDataMaxLength
  16607. /*
  16608. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16611. */
  16612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16613. // StopTxnSampledData
  16614. /*
  16615. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16618. */
  16619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16620. // StopTxnSampledDataMaxLength
  16621. /*
  16622. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16625. */
  16626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16627. // SupportedFeatureProfiles
  16628. /*
  16629. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16632. */
  16633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16634. // SupportedFeatureProfilesMaxLength
  16635. /*
  16636. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16639. */
  16640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16641. // TransactionMessageAttempts
  16642. /*
  16643. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16646. */
  16647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16648. // TransactionMessageRetryInterval
  16649. /*
  16650. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16653. */
  16654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16655. // UnlockConnectorOnEVSideDisconnect
  16656. /*
  16657. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16660. */
  16661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16662. // WebSocketPingInterval
  16663. /*
  16664. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16667. */
  16668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16669. // QueueOffLineMeterValues
  16670. /*
  16671. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16674. */
  16675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16676. // AuthorizationKey
  16677. /*
  16678. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16681. */
  16682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16683. // SecurityProfile
  16684. /*
  16685. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16688. */
  16689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16690. // DefaultPrice
  16691. /*
  16692. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16695. */
  16696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16697. // CustomDisplayCostAndPrice
  16698. /*
  16699. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16702. */
  16703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16704. // CustomIdleFeeAfterStop
  16705. /*
  16706. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16709. */
  16710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16711. // TimeOffset
  16712. /*
  16713. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16716. */
  16717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16718. // NextTimeOffsetTransitionDateTime
  16719. /*
  16720. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16723. */
  16724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16725. // TimeOffsetNextTransition
  16726. /*
  16727. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16730. */
  16731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16732. // SystemUptimeSec
  16733. /*
  16734. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16737. */
  16738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16739. // FreeVend
  16740. /*
  16741. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16744. */
  16745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16746. // FreeVendIdtag
  16747. /*
  16748. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16751. */
  16752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16753. // OcppServer
  16754. /*
  16755. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16758. */
  16759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16760. // MaintainServer
  16761. /*
  16762. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16765. */
  16766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16767. // StatusNotificationPeriodically
  16768. /*
  16769. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16772. */
  16773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16774. // StatusNotificationInterval
  16775. /*
  16776. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16779. */
  16780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16781. // PreAuthAmount
  16782. /*
  16783. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16786. */
  16787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16788. // isEnableLocalPowerSharing
  16789. /*
  16790. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16793. */
  16794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16795. // PowerSharingServerIP
  16796. /*
  16797. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16800. */
  16801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16802. // EVCCID_PREFIX
  16803. /*
  16804. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16807. */
  16808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16809. // OffLineMaxChargingPower
  16810. /*
  16811. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16814. */
  16815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16816. // ConfigurationVersion
  16817. /*
  16818. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16821. */
  16822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16823. // CharingProfileRefreshInterval
  16824. /*
  16825. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16828. */
  16829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16830. // CpoName
  16831. /*
  16832. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16835. */
  16836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16837. // OcppSoftwareVersion
  16838. /*
  16839. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16842. */
  16843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16844. //* Local Auth List Management Profile*/
  16845. //LocalAuthListEnabled
  16846. /*
  16847. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16850. */
  16851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16852. //LocalAuthListMaxLength
  16853. /*
  16854. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16857. */
  16858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16859. //SendLocalListMaxLength
  16860. /*
  16861. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16864. */
  16865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16866. //ReserveConnectorZeroSupported
  16867. /*
  16868. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16871. */
  16872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16873. //* Smart Charging Profile */
  16874. //ChargeProfileMaxStackLevel
  16875. /*
  16876. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16879. */
  16880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16881. // ChargingScheduleAllowedChargingRateUnit
  16882. /*
  16883. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16886. */
  16887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16888. // ChargingScheduleMaxPeriods
  16889. /*
  16890. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16893. */
  16894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16895. // ConnectorSwitch3to1PhaseSupported
  16896. /*
  16897. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16900. */
  16901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16902. // MaxChargingProfilesInstalled
  16903. /*
  16904. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16907. */
  16908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16909. fclose(outfile);
  16910. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16911. }
  16912. void getKeyValue(char *keyReq)
  16913. {
  16914. int isEmpty = FALSE;
  16915. int isKnowKey = FALSE;
  16916. DEBUG_INFO("keyReq = %s\n", keyReq);
  16917. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16918. isEmpty = TRUE;
  16919. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16920. {
  16921. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16923. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16924. {
  16925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16926. }
  16927. else
  16928. {
  16929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16930. }
  16931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16932. isKnowKey = TRUE;
  16933. }
  16934. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16935. {
  16936. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16939. {
  16940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16941. }
  16942. else
  16943. {
  16944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16945. }
  16946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16947. isKnowKey = TRUE;
  16948. }
  16949. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16950. {
  16951. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16953. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16954. {
  16955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16956. }
  16957. else
  16958. {
  16959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16960. }
  16961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16962. isKnowKey = TRUE;
  16963. }
  16964. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16965. {
  16966. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16969. {
  16970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16971. }
  16972. else
  16973. {
  16974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16975. }
  16976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16977. isKnowKey = TRUE;
  16978. }
  16979. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16980. {
  16981. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16984. {
  16985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16986. }
  16987. else
  16988. {
  16989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16990. }
  16991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16992. isKnowKey = TRUE;
  16993. }
  16994. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16995. {
  16996. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16999. {
  17000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  17001. }
  17002. else
  17003. {
  17004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  17005. }
  17006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  17007. isKnowKey = TRUE;
  17008. }
  17009. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  17010. {
  17011. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  17012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  17013. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17014. {
  17015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  17016. }
  17017. else
  17018. {
  17019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  17020. }
  17021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  17022. isKnowKey = TRUE;
  17023. }
  17024. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  17025. {
  17026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  17027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  17028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17029. {
  17030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  17031. }
  17032. else
  17033. {
  17034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  17035. }
  17036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  17037. isKnowKey = TRUE;
  17038. }
  17039. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  17040. {
  17041. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  17042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  17043. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17044. {
  17045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  17046. }
  17047. else
  17048. {
  17049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  17050. }
  17051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  17052. isKnowKey = TRUE;
  17053. }
  17054. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  17055. {
  17056. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  17057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  17058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17059. {
  17060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  17061. }
  17062. else
  17063. {
  17064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  17065. }
  17066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  17067. isKnowKey = TRUE;
  17068. }
  17069. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  17070. {
  17071. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  17072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  17073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17074. {
  17075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  17076. }
  17077. else
  17078. {
  17079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17080. }
  17081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17082. isKnowKey = TRUE;
  17083. }
  17084. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17085. {
  17086. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17089. {
  17090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17091. }
  17092. else
  17093. {
  17094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17095. }
  17096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17097. isKnowKey = TRUE;
  17098. }
  17099. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17100. {
  17101. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17104. {
  17105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17106. }
  17107. else
  17108. {
  17109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17110. }
  17111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17112. isKnowKey = TRUE;
  17113. }
  17114. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17115. {
  17116. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17119. {
  17120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17121. }
  17122. else
  17123. {
  17124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17125. }
  17126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17127. isKnowKey = TRUE;
  17128. }
  17129. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17130. {
  17131. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17134. {
  17135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17136. }
  17137. else
  17138. {
  17139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17140. }
  17141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17142. isKnowKey = TRUE;
  17143. }
  17144. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17145. {
  17146. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17149. {
  17150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17151. }
  17152. else
  17153. {
  17154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17155. }
  17156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17157. isKnowKey = TRUE;
  17158. }
  17159. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17160. {
  17161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17164. {
  17165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17166. }
  17167. else
  17168. {
  17169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17170. }
  17171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17172. isKnowKey = TRUE;
  17173. }
  17174. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17175. {
  17176. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17179. {
  17180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17181. }
  17182. else
  17183. {
  17184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17185. }
  17186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17187. isKnowKey = TRUE;
  17188. }
  17189. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17190. {
  17191. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17194. {
  17195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17196. }
  17197. else
  17198. {
  17199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17200. }
  17201. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17203. isKnowKey = TRUE;
  17204. }
  17205. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17206. {
  17207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17210. {
  17211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17212. }
  17213. else
  17214. {
  17215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17216. }
  17217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17218. isKnowKey = TRUE;
  17219. }
  17220. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17221. {
  17222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17225. {
  17226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17227. }
  17228. else
  17229. {
  17230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17231. }
  17232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17233. isKnowKey = TRUE;
  17234. }
  17235. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17236. {
  17237. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17240. {
  17241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17242. }
  17243. else
  17244. {
  17245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17246. }
  17247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17248. isKnowKey = TRUE;
  17249. }
  17250. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17251. {
  17252. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17255. {
  17256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17257. }
  17258. else
  17259. {
  17260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17261. }
  17262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17263. isKnowKey = TRUE;
  17264. }
  17265. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17266. {
  17267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17270. {
  17271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17272. }
  17273. else
  17274. {
  17275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17276. }
  17277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17278. isKnowKey = TRUE;
  17279. }
  17280. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17281. {
  17282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17285. {
  17286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17287. }
  17288. else
  17289. {
  17290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17291. }
  17292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17293. isKnowKey = TRUE;
  17294. }
  17295. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17296. {
  17297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17300. {
  17301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17302. }
  17303. else
  17304. {
  17305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17306. }
  17307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17308. isKnowKey = TRUE;
  17309. }
  17310. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17311. {
  17312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17315. {
  17316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17317. }
  17318. else
  17319. {
  17320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17321. }
  17322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17323. isKnowKey = TRUE;
  17324. }
  17325. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17326. {
  17327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17330. {
  17331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17332. }
  17333. else
  17334. {
  17335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17336. }
  17337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17338. isKnowKey = TRUE;
  17339. }
  17340. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17341. {
  17342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17345. {
  17346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17347. }
  17348. else
  17349. {
  17350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17351. }
  17352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17353. isKnowKey = TRUE;
  17354. }
  17355. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17356. {
  17357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17360. {
  17361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17362. }
  17363. else
  17364. {
  17365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17366. }
  17367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17368. isKnowKey = TRUE;
  17369. }
  17370. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17371. {
  17372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17375. {
  17376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17377. }
  17378. else
  17379. {
  17380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17381. }
  17382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17383. isKnowKey = TRUE;
  17384. }
  17385. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17386. {
  17387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17390. {
  17391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17392. }
  17393. else
  17394. {
  17395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17396. }
  17397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17398. isKnowKey = TRUE;
  17399. }
  17400. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17401. {
  17402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17405. {
  17406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17407. }
  17408. else
  17409. {
  17410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17411. }
  17412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17413. isKnowKey = TRUE;
  17414. }
  17415. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17416. {
  17417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17420. {
  17421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17422. }
  17423. else
  17424. {
  17425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17426. }
  17427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17428. isKnowKey = TRUE;
  17429. }
  17430. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17431. {
  17432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17435. {
  17436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17437. }
  17438. else
  17439. {
  17440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17441. }
  17442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17443. isKnowKey = TRUE;
  17444. }
  17445. /*
  17446. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17447. {
  17448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17451. {
  17452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17453. }
  17454. else
  17455. {
  17456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17457. }
  17458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17459. isKnowKey = TRUE;
  17460. }*/
  17461. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17462. {
  17463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17466. {
  17467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17468. }
  17469. else
  17470. {
  17471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17472. }
  17473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17474. isKnowKey = TRUE;
  17475. }
  17476. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17477. {
  17478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17481. {
  17482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17483. }
  17484. else
  17485. {
  17486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17487. }
  17488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17489. isKnowKey = TRUE;
  17490. }
  17491. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17492. {
  17493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17496. {
  17497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17498. }
  17499. else
  17500. {
  17501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17502. }
  17503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17504. isKnowKey = TRUE;
  17505. }
  17506. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17507. {
  17508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17511. {
  17512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17513. }
  17514. else
  17515. {
  17516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17517. }
  17518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17519. isKnowKey = TRUE;
  17520. }
  17521. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17522. {
  17523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17526. {
  17527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17528. }
  17529. else
  17530. {
  17531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17532. }
  17533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17534. isKnowKey = TRUE;
  17535. }
  17536. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17537. {
  17538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17541. {
  17542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17543. }
  17544. else
  17545. {
  17546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17547. }
  17548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17549. isKnowKey = TRUE;
  17550. }
  17551. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17552. {
  17553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17556. {
  17557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17558. }
  17559. else
  17560. {
  17561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17562. }
  17563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17564. isKnowKey = TRUE;
  17565. }
  17566. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17567. {
  17568. struct sysinfo s_info;
  17569. int error = sysinfo(&s_info);
  17570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17573. {
  17574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17575. }
  17576. else
  17577. {
  17578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17579. }
  17580. if(error != 0)
  17581. {
  17582. DEBUG_WARN("System uptime get error: %d\n", error);
  17583. }
  17584. else
  17585. {
  17586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17587. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17588. }
  17589. isKnowKey = TRUE;
  17590. }
  17591. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17592. {
  17593. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17596. {
  17597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17598. }
  17599. else
  17600. {
  17601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17602. }
  17603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17604. isKnowKey = TRUE;
  17605. }
  17606. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17607. {
  17608. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17611. {
  17612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17613. }
  17614. else
  17615. {
  17616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17617. }
  17618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17619. isKnowKey = TRUE;
  17620. }
  17621. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17622. {
  17623. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17626. {
  17627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17628. }
  17629. else
  17630. {
  17631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17632. }
  17633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17634. isKnowKey = TRUE;
  17635. }
  17636. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17637. {
  17638. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17641. {
  17642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17643. }
  17644. else
  17645. {
  17646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17647. }
  17648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17649. isKnowKey = TRUE;
  17650. }
  17651. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17652. {
  17653. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17656. {
  17657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17658. }
  17659. else
  17660. {
  17661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17662. }
  17663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17664. isKnowKey = TRUE;
  17665. }
  17666. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17667. {
  17668. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17670. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17671. {
  17672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17673. }
  17674. else
  17675. {
  17676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17677. }
  17678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17679. isKnowKey = TRUE;
  17680. }
  17681. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17682. {
  17683. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17685. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17686. {
  17687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17688. }
  17689. else
  17690. {
  17691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17692. }
  17693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17694. isKnowKey = TRUE;
  17695. }
  17696. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17697. {
  17698. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17700. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17701. {
  17702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17703. }
  17704. else
  17705. {
  17706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17707. }
  17708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17709. isKnowKey = TRUE;
  17710. }
  17711. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17712. {
  17713. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17716. {
  17717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17718. }
  17719. else
  17720. {
  17721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17722. }
  17723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17724. isKnowKey = TRUE;
  17725. }
  17726. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17727. {
  17728. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17730. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17731. {
  17732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17733. }
  17734. else
  17735. {
  17736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17737. }
  17738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17739. isKnowKey = TRUE;
  17740. }
  17741. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17742. {
  17743. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17745. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17746. {
  17747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17748. }
  17749. else
  17750. {
  17751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17752. }
  17753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17754. isKnowKey = TRUE;
  17755. }
  17756. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17757. {
  17758. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17760. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17761. {
  17762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17763. }
  17764. else
  17765. {
  17766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17767. }
  17768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17769. isKnowKey = TRUE;
  17770. }
  17771. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17772. {
  17773. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17775. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17776. {
  17777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17778. }
  17779. else
  17780. {
  17781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17782. }
  17783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17784. isKnowKey = TRUE;
  17785. }
  17786. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17787. {
  17788. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17791. {
  17792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17793. }
  17794. else
  17795. {
  17796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17797. }
  17798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17799. isKnowKey = TRUE;
  17800. }
  17801. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17802. {
  17803. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17805. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17806. {
  17807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17808. }
  17809. else
  17810. {
  17811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17812. }
  17813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17814. isKnowKey = TRUE;
  17815. }
  17816. #if 1
  17817. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17818. {
  17819. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17821. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17822. {
  17823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17824. }
  17825. else
  17826. {
  17827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17828. }
  17829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17830. isKnowKey = TRUE;
  17831. }
  17832. #endif
  17833. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17834. {
  17835. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17837. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17838. {
  17839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17840. }
  17841. else
  17842. {
  17843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17844. }
  17845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17846. isKnowKey = TRUE;
  17847. }
  17848. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17849. {
  17850. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17852. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17853. {
  17854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17855. }
  17856. else
  17857. {
  17858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17859. }
  17860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17861. isKnowKey = TRUE;
  17862. }
  17863. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17864. {
  17865. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17867. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17868. {
  17869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17870. }
  17871. else
  17872. {
  17873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17874. }
  17875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17876. isKnowKey = TRUE;
  17877. }
  17878. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17879. {
  17880. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17882. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17883. {
  17884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17885. }
  17886. else
  17887. {
  17888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17889. }
  17890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17891. isKnowKey = TRUE;
  17892. }
  17893. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17894. {
  17895. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17897. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17898. {
  17899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17900. }
  17901. else
  17902. {
  17903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17904. }
  17905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17906. isKnowKey = TRUE;
  17907. }
  17908. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17909. {
  17910. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17912. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17913. {
  17914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17915. }
  17916. else
  17917. {
  17918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17919. }
  17920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17921. isKnowKey = TRUE;
  17922. }
  17923. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17924. {
  17925. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17927. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17928. {
  17929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17930. }
  17931. else
  17932. {
  17933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17934. }
  17935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17936. isKnowKey = TRUE;
  17937. }
  17938. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17939. {
  17940. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17942. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17943. {
  17944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17945. }
  17946. else
  17947. {
  17948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17949. }
  17950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17951. isKnowKey = TRUE;
  17952. }
  17953. //=========================================================
  17954. if(!isEmpty && !isKnowKey)
  17955. {
  17956. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17957. strcpy(unknownkey[UnknownKeynum], keyReq);
  17958. UnknownKeynum = UnknownKeynum + 1;
  17959. }
  17960. }
  17961. void processUnkownKey(void)
  17962. {
  17963. DEBUG_INFO("processUnkownKey...\n");
  17964. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17965. for(int index=0; index < UnknownKeynum; index++)
  17966. {
  17967. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17968. {
  17969. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17970. }
  17971. }
  17972. }
  17973. int setKeyValue(char *key, char *value)
  17974. {
  17975. int isSuccess = NotSupported;
  17976. int check_ascii=0;
  17977. char str[501]={0};
  17978. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17979. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17980. {
  17981. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17983. {
  17984. strcpy(str, (const char*)value);
  17985. for(int i = 0; str[i]; i++){
  17986. str[i] = tolower(str[i]);
  17987. }
  17988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17989. isSuccess = ConfigurationStatus_Accepted;
  17990. }
  17991. else
  17992. {
  17993. isSuccess = ConfigurationStatus_Rejected;
  17994. }
  17995. }
  17996. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  17997. {
  17998. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  17999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  18000. {
  18001. strcpy(str, (const char*)value);
  18002. for(int i = 0; str[i]; i++){
  18003. str[i] = tolower(str[i]);
  18004. }
  18005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18006. isSuccess = ConfigurationStatus_Accepted;
  18007. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  18008. }
  18009. else
  18010. {
  18011. isSuccess = ConfigurationStatus_Rejected;
  18012. }
  18013. }
  18014. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  18015. {
  18016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  18017. {
  18018. strcpy(str, (const char*)value);
  18019. for(int i = 0; str[i]; i++)
  18020. {
  18021. str[i] = tolower(str[i]);
  18022. }
  18023. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  18024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18025. isSuccess = ConfigurationStatus_Accepted;
  18026. }
  18027. else
  18028. {
  18029. isSuccess = ConfigurationStatus_Rejected;
  18030. }
  18031. }
  18032. if(strcmp(key, "BlinkRepeat") == 0)
  18033. {
  18034. //Charger.BlinkRepeat = Integer.parseInt(value);
  18035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  18036. {
  18037. check_ascii = value[0];
  18038. if( (check_ascii < 48) || (check_ascii > 57) )
  18039. {
  18040. isSuccess = ConfigurationStatus_Rejected;
  18041. }
  18042. else
  18043. {
  18044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  18045. isSuccess = ConfigurationStatus_Accepted;
  18046. }
  18047. }
  18048. else
  18049. {
  18050. isSuccess = ConfigurationStatus_Rejected;
  18051. }
  18052. }
  18053. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  18054. {
  18055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  18056. {
  18057. check_ascii = value[0];
  18058. if( (check_ascii < 48) || (check_ascii > 57) )
  18059. {
  18060. isSuccess = ConfigurationStatus_Rejected;
  18061. }
  18062. else
  18063. {
  18064. if((atoi(value) == 0) || (atoi(value) >= 5))
  18065. {
  18066. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  18068. isSuccess = ConfigurationStatus_Accepted;
  18069. }
  18070. else
  18071. isSuccess = ConfigurationStatus_Rejected;
  18072. }
  18073. }
  18074. else
  18075. {
  18076. isSuccess = ConfigurationStatus_Rejected;
  18077. }
  18078. }
  18079. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18080. {
  18081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18082. {
  18083. check_ascii = value[0];
  18084. if( (check_ascii < 48) || (check_ascii > 57) )
  18085. {
  18086. isSuccess = ConfigurationStatus_Rejected;
  18087. }
  18088. else
  18089. {
  18090. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18092. isSuccess = ConfigurationStatus_Accepted;
  18093. }
  18094. }
  18095. else
  18096. {
  18097. isSuccess = ConfigurationStatus_Rejected;
  18098. }
  18099. }
  18100. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18101. {
  18102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18103. {
  18104. check_ascii = value[0];
  18105. if( (check_ascii < 48) || (check_ascii > 57) )
  18106. {
  18107. isSuccess = ConfigurationStatus_Rejected;
  18108. }
  18109. else
  18110. {
  18111. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18113. isSuccess = ConfigurationStatus_Accepted;
  18114. }
  18115. }
  18116. else
  18117. {
  18118. isSuccess = ConfigurationStatus_Rejected;
  18119. }
  18120. }
  18121. if(strcmp(key, "HeartbeatInterval") == 0)
  18122. {
  18123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18124. {
  18125. check_ascii = value[0];
  18126. if( (check_ascii < 48) || (check_ascii > 57) )
  18127. {
  18128. isSuccess = ConfigurationStatus_Rejected;
  18129. }
  18130. else
  18131. {
  18132. if((atoi(value) == 0) || (atoi(value) >= 10))
  18133. {
  18134. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18136. HeartBeatWaitTime = atoi(value);
  18137. isSuccess = ConfigurationStatus_Accepted;
  18138. }
  18139. else
  18140. {
  18141. isSuccess = ConfigurationStatus_Rejected;
  18142. }
  18143. }
  18144. }
  18145. else
  18146. {
  18147. isSuccess = ConfigurationStatus_Rejected;
  18148. }
  18149. }
  18150. if(strcmp(key, "LightIntensity") == 0)
  18151. {
  18152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18162. isSuccess = ConfigurationStatus_Accepted;
  18163. }
  18164. }
  18165. else
  18166. {
  18167. isSuccess = ConfigurationStatus_Rejected;
  18168. }
  18169. }
  18170. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18171. {
  18172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18173. {
  18174. strcpy(str, (const char*)value);
  18175. for(int i = 0; str[i]; i++)
  18176. {
  18177. str[i] = tolower(str[i]);
  18178. }
  18179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18180. isSuccess = ConfigurationStatus_Accepted;
  18181. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18182. }
  18183. else
  18184. {
  18185. isSuccess = ConfigurationStatus_Rejected;
  18186. }
  18187. }
  18188. if(strcmp(key, "LocalPreAuthorize") == 0)
  18189. {
  18190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18191. {
  18192. strcpy(str, (const char*)value);
  18193. for(int i = 0; str[i]; i++)
  18194. {
  18195. str[i] = tolower(str[i]);
  18196. }
  18197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18198. isSuccess = ConfigurationStatus_Accepted;
  18199. }
  18200. else
  18201. {
  18202. isSuccess = ConfigurationStatus_Rejected;
  18203. }
  18204. }
  18205. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18206. {
  18207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18208. {
  18209. check_ascii = value[0];
  18210. if( (check_ascii < 48) || (check_ascii > 57) )
  18211. {
  18212. isSuccess = ConfigurationStatus_Rejected;
  18213. }
  18214. else
  18215. {
  18216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18217. isSuccess = ConfigurationStatus_Accepted;
  18218. }
  18219. }
  18220. else
  18221. {
  18222. isSuccess = ConfigurationStatus_Rejected;
  18223. }
  18224. }
  18225. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18226. {
  18227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18228. {
  18229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18230. isSuccess = ConfigurationStatus_Accepted;
  18231. }
  18232. else
  18233. {
  18234. isSuccess = ConfigurationStatus_Rejected;
  18235. }
  18236. }
  18237. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18238. {
  18239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18240. {
  18241. check_ascii = value[0];
  18242. if( (check_ascii < 48) || (check_ascii > 57) )
  18243. {
  18244. isSuccess = ConfigurationStatus_Rejected;
  18245. }
  18246. else
  18247. {
  18248. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18250. isSuccess = ConfigurationStatus_Accepted;
  18251. }
  18252. }
  18253. else
  18254. {
  18255. isSuccess = ConfigurationStatus_Rejected;
  18256. }
  18257. }
  18258. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18259. {
  18260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18261. {
  18262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18263. isSuccess = ConfigurationStatus_Accepted;
  18264. }
  18265. else
  18266. {
  18267. isSuccess = ConfigurationStatus_Rejected;
  18268. }
  18269. }
  18270. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18271. {
  18272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18273. {
  18274. check_ascii = value[0];
  18275. if( (check_ascii < 48) || (check_ascii > 57) )
  18276. {
  18277. isSuccess = ConfigurationStatus_Rejected;
  18278. }
  18279. else
  18280. {
  18281. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18283. isSuccess = ConfigurationStatus_Accepted;
  18284. }
  18285. }
  18286. else
  18287. {
  18288. isSuccess = ConfigurationStatus_Rejected;
  18289. }
  18290. }
  18291. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18292. {
  18293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18294. {
  18295. check_ascii = value[0];
  18296. if( (check_ascii < 48) || (check_ascii > 57) )
  18297. {
  18298. isSuccess = ConfigurationStatus_Rejected;
  18299. }
  18300. else
  18301. {
  18302. if((atoi(value) == 0) || (atoi(value) >= 3))
  18303. {
  18304. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18306. isSuccess = ConfigurationStatus_Accepted;
  18307. }
  18308. else
  18309. {
  18310. isSuccess = ConfigurationStatus_Rejected;
  18311. }
  18312. }
  18313. }
  18314. else
  18315. {
  18316. isSuccess = ConfigurationStatus_Rejected;
  18317. }
  18318. }
  18319. if(strcmp(key, "MinimumStatusDuration") == 0)
  18320. {
  18321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18322. {
  18323. check_ascii = value[0];
  18324. if( (check_ascii < 48) || (check_ascii > 57) )
  18325. {
  18326. isSuccess = ConfigurationStatus_Rejected;
  18327. }
  18328. else
  18329. {
  18330. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18331. {
  18332. isSuccess = ConfigurationStatus_Rejected;
  18333. }
  18334. else
  18335. {
  18336. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18338. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18339. isSuccess = ConfigurationStatus_Accepted;
  18340. }
  18341. }
  18342. }
  18343. else
  18344. {
  18345. isSuccess = ConfigurationStatus_Rejected;
  18346. }
  18347. }
  18348. if(strcmp(key, "NumberOfConnectors") == 0)
  18349. {
  18350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18351. {
  18352. check_ascii = value[0];
  18353. if( (check_ascii < 48) || (check_ascii > 57) )
  18354. {
  18355. isSuccess = ConfigurationStatus_Rejected;
  18356. }
  18357. else
  18358. {
  18359. //Charger.ResetRetries = Integer.parseInt(value);
  18360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18361. isSuccess = ConfigurationStatus_Accepted;
  18362. }
  18363. }
  18364. else
  18365. {
  18366. isSuccess = ConfigurationStatus_Rejected;
  18367. }
  18368. }
  18369. if(strcmp(key, "ResetRetries") == 0)
  18370. {
  18371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].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. //Charger.ResetRetries = Integer.parseInt(value);
  18381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18382. isSuccess = ConfigurationStatus_Accepted;
  18383. }
  18384. }
  18385. else
  18386. {
  18387. isSuccess = ConfigurationStatus_Rejected;
  18388. }
  18389. }
  18390. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18391. {
  18392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18393. {
  18394. strcpy(str, (const char*)value);
  18395. for(int i = 0; str[i]; i++)
  18396. {
  18397. str[i] = tolower(str[i]);
  18398. }
  18399. if(strcmp(str, "notapplicable")== 0)
  18400. {
  18401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18402. isSuccess = ConfigurationStatus_Accepted;
  18403. }
  18404. else if(strcmp(str, "unknown")== 0)
  18405. {
  18406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18407. isSuccess = ConfigurationStatus_Accepted;
  18408. }
  18409. else if(strcmp(str, "rst")== 0)
  18410. {
  18411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18412. isSuccess = ConfigurationStatus_Accepted;
  18413. }
  18414. else if(strcmp(str, "rts")== 0)
  18415. {
  18416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18417. isSuccess = ConfigurationStatus_Accepted;
  18418. }
  18419. else if(strcmp(str, "srt")== 0)
  18420. {
  18421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18422. isSuccess = ConfigurationStatus_Accepted;
  18423. }
  18424. else if(strcmp(str, "str")== 0)
  18425. {
  18426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18427. isSuccess = ConfigurationStatus_Accepted;
  18428. }
  18429. else if(strcmp(str, "trs")== 0)
  18430. {
  18431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18432. isSuccess = ConfigurationStatus_Accepted;
  18433. }
  18434. else if(strcmp(str, "tsr")== 0)
  18435. {
  18436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18437. isSuccess = ConfigurationStatus_Accepted;
  18438. }
  18439. else
  18440. {
  18441. isSuccess = ConfigurationStatus_Rejected;
  18442. }
  18443. }
  18444. else
  18445. {
  18446. isSuccess = ConfigurationStatus_Rejected;
  18447. }
  18448. }
  18449. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18450. {
  18451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18452. {
  18453. check_ascii = value[0];
  18454. if( (check_ascii < 48) || (check_ascii > 57) )
  18455. {
  18456. isSuccess = ConfigurationStatus_Rejected;
  18457. }
  18458. else
  18459. {
  18460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18461. isSuccess = ConfigurationStatus_Accepted;
  18462. }
  18463. }
  18464. else
  18465. {
  18466. isSuccess = ConfigurationStatus_Rejected;
  18467. }
  18468. }
  18469. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18470. {
  18471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18472. {
  18473. strcpy(str, (const char*)value);
  18474. for(int i = 0; str[i]; i++)
  18475. {
  18476. str[i] = tolower(str[i]);
  18477. }
  18478. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18480. isSuccess = ConfigurationStatus_Accepted;
  18481. }
  18482. else
  18483. {
  18484. isSuccess = ConfigurationStatus_Rejected;
  18485. }
  18486. }
  18487. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18488. {
  18489. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18490. {
  18491. strcpy(str, (const char*)value);
  18492. for(int i = 0; str[i]; i++)
  18493. {
  18494. str[i] = tolower(str[i]);
  18495. }
  18496. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18498. isSuccess = ConfigurationStatus_Accepted;
  18499. }
  18500. else
  18501. {
  18502. isSuccess = ConfigurationStatus_Rejected;
  18503. }
  18504. }
  18505. if(strcmp(key, "StopTxnAlignedData") == 0)
  18506. {
  18507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18508. {
  18509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18510. isSuccess = ConfigurationStatus_Accepted;
  18511. }
  18512. else
  18513. {
  18514. isSuccess = ConfigurationStatus_Rejected;
  18515. }
  18516. }
  18517. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18518. {
  18519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18520. {
  18521. check_ascii = value[0];
  18522. if( (check_ascii < 48) || (check_ascii > 57) )
  18523. {
  18524. isSuccess = ConfigurationStatus_Rejected;
  18525. }
  18526. else
  18527. {
  18528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18529. isSuccess = ConfigurationStatus_Accepted;
  18530. }
  18531. }
  18532. else
  18533. {
  18534. isSuccess = ConfigurationStatus_Rejected;
  18535. }
  18536. }
  18537. if(strcmp(key, "StopTxnSampledData") == 0)
  18538. {
  18539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18540. {
  18541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18542. isSuccess = ConfigurationStatus_Accepted;
  18543. }
  18544. else
  18545. {
  18546. isSuccess = ConfigurationStatus_Rejected;
  18547. }
  18548. }
  18549. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18550. {
  18551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18552. {
  18553. check_ascii = value[0];
  18554. if( (check_ascii < 48) || (check_ascii > 57) )
  18555. {
  18556. isSuccess = ConfigurationStatus_Rejected;
  18557. }
  18558. else
  18559. {
  18560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18561. isSuccess = ConfigurationStatus_Accepted;
  18562. }
  18563. }
  18564. else
  18565. {
  18566. isSuccess = ConfigurationStatus_Rejected;
  18567. }
  18568. }
  18569. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18570. {
  18571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18572. {
  18573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18574. isSuccess = ConfigurationStatus_Accepted;
  18575. }
  18576. else
  18577. {
  18578. isSuccess = ConfigurationStatus_Rejected;
  18579. }
  18580. }
  18581. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18582. {
  18583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18584. {
  18585. check_ascii = value[0];
  18586. if( (check_ascii < 48) || (check_ascii > 57) )
  18587. {
  18588. isSuccess = ConfigurationStatus_Rejected;
  18589. }
  18590. else
  18591. {
  18592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18593. isSuccess = ConfigurationStatus_Accepted;
  18594. }
  18595. }
  18596. else
  18597. {
  18598. isSuccess = ConfigurationStatus_Rejected;
  18599. }
  18600. }
  18601. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18602. {
  18603. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18604. {
  18605. check_ascii = value[0];
  18606. if( (check_ascii < 48) || (check_ascii > 57) )
  18607. {
  18608. isSuccess = ConfigurationStatus_Rejected;
  18609. }
  18610. else
  18611. {
  18612. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18614. TransactionMessageAttemptsValue = atoi(value);
  18615. isSuccess = ConfigurationStatus_Accepted;
  18616. }
  18617. }
  18618. else
  18619. {
  18620. isSuccess = ConfigurationStatus_Rejected;
  18621. }
  18622. }
  18623. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18624. {
  18625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18626. {
  18627. check_ascii = value[0];
  18628. if( (check_ascii < 48) || (check_ascii > 57) )
  18629. {
  18630. isSuccess = ConfigurationStatus_Rejected;
  18631. }
  18632. else
  18633. {
  18634. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18636. TransactionMessageRetryIntervalValue = atoi(value);
  18637. isSuccess = ConfigurationStatus_Accepted;
  18638. }
  18639. }
  18640. else
  18641. {
  18642. isSuccess = ConfigurationStatus_Rejected;
  18643. }
  18644. }
  18645. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18646. {
  18647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18648. {
  18649. strcpy(str, (const char*)value);
  18650. for(int i = 0; str[i]; i++)
  18651. {
  18652. str[i] = tolower(str[i]);
  18653. }
  18654. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18656. isSuccess = ConfigurationStatus_Accepted;
  18657. }
  18658. else
  18659. {
  18660. isSuccess = ConfigurationStatus_Rejected;
  18661. }
  18662. }
  18663. if(strcmp(key, "WebSocketPingInterval") == 0)
  18664. {
  18665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18666. {
  18667. check_ascii = value[0];
  18668. if( (check_ascii < 48) || (check_ascii > 57) )
  18669. {
  18670. isSuccess = ConfigurationStatus_Rejected;
  18671. }
  18672. else
  18673. {
  18674. if((atoi(value) == 0) || (atoi(value) >= 10))
  18675. {
  18676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18677. isSuccess = ConfigurationStatus_Accepted;
  18678. }
  18679. else
  18680. isSuccess = ConfigurationStatus_Rejected;
  18681. }
  18682. }
  18683. else
  18684. {
  18685. isSuccess = ConfigurationStatus_Rejected;
  18686. }
  18687. }
  18688. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18689. {
  18690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18691. {
  18692. strcpy(str, (const char*)value);
  18693. for(int i = 0; str[i]; i++)
  18694. {
  18695. str[i] = tolower(str[i]);
  18696. }
  18697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18698. isSuccess = ConfigurationStatus_Accepted;
  18699. }
  18700. else
  18701. {
  18702. isSuccess = ConfigurationStatus_Rejected;
  18703. }
  18704. }
  18705. if(strcmp(key, "AuthorizationKey") == 0)
  18706. {
  18707. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18708. {
  18709. strcpy(str, (const char*)value);
  18710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  18711. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18712. isSuccess = ConfigurationStatus_Accepted;
  18713. }
  18714. else
  18715. {
  18716. isSuccess = ConfigurationStatus_Rejected;
  18717. }
  18718. }
  18719. if(strcmp(key, "SecurityProfile") == 0)
  18720. {
  18721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18722. {
  18723. check_ascii = value[0];
  18724. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18725. {
  18726. isSuccess = ConfigurationStatus_Rejected;
  18727. }
  18728. else if(check_ascii == 0x33)
  18729. {
  18730. isSuccess = NotSupported;
  18731. }
  18732. else
  18733. {
  18734. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18735. {
  18736. if(((check_ascii - 0x30) == 1) ||
  18737. ((check_ascii - 0x30) == 2) ||
  18738. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18739. {
  18740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18741. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18742. isSuccess = ConfigurationStatus_Accepted;
  18743. }
  18744. else
  18745. isSuccess = ConfigurationStatus_Rejected;
  18746. }
  18747. else
  18748. isSuccess = ConfigurationStatus_Rejected;
  18749. }
  18750. }
  18751. else
  18752. {
  18753. isSuccess = ConfigurationStatus_Rejected;
  18754. }
  18755. }
  18756. if(strcmp(key, "DefaultPrice") == 0)
  18757. {
  18758. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18759. {
  18760. strcpy(str, (const char*)value);
  18761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18762. isSuccess = ConfigurationStatus_Accepted;
  18763. }
  18764. else
  18765. {
  18766. isSuccess = ConfigurationStatus_Rejected;
  18767. }
  18768. }
  18769. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18770. {
  18771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18772. {
  18773. strcpy(str, (const char*)value);
  18774. for(int i = 0; str[i]; i++)
  18775. {
  18776. str[i] = tolower(str[i]);
  18777. }
  18778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18779. isSuccess = ConfigurationStatus_Accepted;
  18780. }
  18781. else
  18782. {
  18783. isSuccess = ConfigurationStatus_Rejected;
  18784. }
  18785. }
  18786. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18787. {
  18788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18789. {
  18790. strcpy(str, (const char*)value);
  18791. for(int i = 0; str[i]; i++)
  18792. {
  18793. str[i] = tolower(str[i]);
  18794. }
  18795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18796. isSuccess = ConfigurationStatus_Accepted;
  18797. }
  18798. else
  18799. {
  18800. isSuccess = ConfigurationStatus_Rejected;
  18801. }
  18802. }
  18803. if(strcmp(key, "TimeOffset") == 0)
  18804. {
  18805. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18806. {
  18807. strcpy(str, (const char*)value);
  18808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18809. isSuccess = ConfigurationStatus_Accepted;
  18810. }
  18811. else
  18812. {
  18813. isSuccess = ConfigurationStatus_Rejected;
  18814. }
  18815. }
  18816. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18817. {
  18818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18819. {
  18820. strcpy(str, (const char*)value);
  18821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18822. isSuccess = ConfigurationStatus_Accepted;
  18823. }
  18824. else
  18825. {
  18826. isSuccess = ConfigurationStatus_Rejected;
  18827. }
  18828. }
  18829. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18830. {
  18831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18832. {
  18833. strcpy(str, (const char*)value);
  18834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18835. isSuccess = ConfigurationStatus_Accepted;
  18836. }
  18837. else
  18838. {
  18839. isSuccess = ConfigurationStatus_Rejected;
  18840. }
  18841. }
  18842. if(strcmp(key, "SystemUptimeSec") == 0)
  18843. {
  18844. isSuccess = NotSupported;
  18845. }
  18846. if(strcmp(key, "FreeVend") == 0)
  18847. {
  18848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18849. {
  18850. strcpy(str, (const char*)value);
  18851. for(int i = 0; str[i]; i++)
  18852. {
  18853. str[i] = tolower(str[i]);
  18854. }
  18855. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18857. isSuccess = ConfigurationStatus_Accepted;
  18858. }
  18859. else
  18860. {
  18861. isSuccess = ConfigurationStatus_Rejected;
  18862. }
  18863. }
  18864. if(strcmp(key, "FreeVendIdtag") == 0)
  18865. {
  18866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18867. {
  18868. strcpy(str, (const char*)value);
  18869. if(strlen(str) <= 20)
  18870. {
  18871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18872. isSuccess = ConfigurationStatus_Accepted;
  18873. }
  18874. else
  18875. {
  18876. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18877. isSuccess = ConfigurationStatus_Rejected;
  18878. }
  18879. }
  18880. else
  18881. {
  18882. isSuccess = ConfigurationStatus_Rejected;
  18883. }
  18884. }
  18885. if(strcmp(key, "OcppServer") == 0)
  18886. {
  18887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18888. {
  18889. strcpy(str, (const char*)value);
  18890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18891. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18892. isSuccess = ConfigurationStatus_Accepted;
  18893. }
  18894. else
  18895. {
  18896. isSuccess = ConfigurationStatus_Rejected;
  18897. }
  18898. }
  18899. if(strcmp(key, "MaintainServer") == 0)
  18900. {
  18901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18902. {
  18903. strcpy(str, (const char*)value);
  18904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18905. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18906. isSuccess = ConfigurationStatus_Accepted;
  18907. }
  18908. else
  18909. {
  18910. isSuccess = ConfigurationStatus_Rejected;
  18911. }
  18912. }
  18913. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18914. {
  18915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18916. {
  18917. strcpy(str, (const char*)value);
  18918. for(int i = 0; str[i]; i++)
  18919. {
  18920. str[i] = tolower(str[i]);
  18921. }
  18922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18923. isSuccess = ConfigurationStatus_Accepted;
  18924. }
  18925. else
  18926. {
  18927. isSuccess = ConfigurationStatus_Rejected;
  18928. }
  18929. }
  18930. if(strcmp(key, "StatusNotificationInterval") == 0)
  18931. {
  18932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18933. {
  18934. check_ascii = value[0];
  18935. if( (check_ascii < 48) || (check_ascii > 57) )
  18936. {
  18937. isSuccess = ConfigurationStatus_Rejected;
  18938. }
  18939. else
  18940. {
  18941. if((atoi(value) == 0) || (atoi(value) >= 10))
  18942. {
  18943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18944. isSuccess = ConfigurationStatus_Accepted;
  18945. }
  18946. else
  18947. isSuccess = ConfigurationStatus_Rejected;
  18948. }
  18949. }
  18950. else
  18951. {
  18952. isSuccess = ConfigurationStatus_Rejected;
  18953. }
  18954. }
  18955. if(strcmp(key, "PreAuthAmount") == 0)
  18956. {
  18957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18958. {
  18959. check_ascii = value[0];
  18960. if( (check_ascii < 48) || (check_ascii > 57) )
  18961. {
  18962. isSuccess = ConfigurationStatus_Rejected;
  18963. }
  18964. else
  18965. {
  18966. if(atof(value) >= 0)
  18967. {
  18968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18969. isSuccess = ConfigurationStatus_Accepted;
  18970. }
  18971. else
  18972. isSuccess = ConfigurationStatus_Rejected;
  18973. }
  18974. }
  18975. else
  18976. {
  18977. isSuccess = ConfigurationStatus_Rejected;
  18978. }
  18979. }
  18980. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  18981. {
  18982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].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)
  18992. {
  18993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  18994. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  18995. isSuccess = ConfigurationStatus_Accepted;
  18996. }
  18997. else
  18998. isSuccess = ConfigurationStatus_Rejected;
  18999. }
  19000. }
  19001. else
  19002. {
  19003. isSuccess = ConfigurationStatus_Rejected;
  19004. }
  19005. }
  19006. if(strcmp(key, "PowerSharingServerIP") == 0)
  19007. {
  19008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  19009. {
  19010. strcpy(str, (const char*)value);
  19011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  19012. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  19013. isSuccess = ConfigurationStatus_Accepted;
  19014. }
  19015. else
  19016. {
  19017. isSuccess = ConfigurationStatus_Rejected;
  19018. }
  19019. }
  19020. if(strcmp(key, "EVCCID_PREFIX") == 0)
  19021. {
  19022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  19023. {
  19024. strcpy(str, (const char*)value);
  19025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  19026. isSuccess = ConfigurationStatus_Accepted;
  19027. }
  19028. else
  19029. {
  19030. isSuccess = ConfigurationStatus_Rejected;
  19031. }
  19032. }
  19033. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  19034. {
  19035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  19036. {
  19037. if(atoi(value) > modelnameInfo.ratedPower)
  19038. {
  19039. isSuccess = ConfigurationStatus_Rejected;
  19040. }
  19041. else{
  19042. strcpy(str, (const char*)value);
  19043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  19044. isSuccess = ConfigurationStatus_Accepted;
  19045. }
  19046. }
  19047. else
  19048. {
  19049. isSuccess = ConfigurationStatus_Rejected;
  19050. }
  19051. }
  19052. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  19053. {
  19054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19055. {
  19056. if((atoi(value) != 0) && (atoi(value) < 5))
  19057. {
  19058. isSuccess = ConfigurationStatus_Rejected;
  19059. }
  19060. else{
  19061. strcpy(str, (const char*)value);
  19062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  19063. isSuccess = ConfigurationStatus_Accepted;
  19064. }
  19065. }
  19066. else
  19067. {
  19068. isSuccess = ConfigurationStatus_Rejected;
  19069. }
  19070. }
  19071. if(strcmp(key, "CpoName") == 0)
  19072. {
  19073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19074. {
  19075. strcpy(str, (const char*)value);
  19076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19077. isSuccess = ConfigurationStatus_Accepted;
  19078. }
  19079. else
  19080. {
  19081. isSuccess = ConfigurationStatus_Rejected;
  19082. }
  19083. }
  19084. #if 0
  19085. //For OCPP Test Case
  19086. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19087. {
  19088. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19089. {
  19090. strcpy(str, (const char*)value);
  19091. for(int i = 0; str[i]; i++)
  19092. {
  19093. str[i] = tolower(str[i]);
  19094. }
  19095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19096. isSuccess = ConfigurationStatus_Accepted;
  19097. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19098. }
  19099. else
  19100. {
  19101. isSuccess = ConfigurationStatus_Rejected;
  19102. }
  19103. }
  19104. #endif
  19105. #if 1
  19106. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19107. {
  19108. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19109. {
  19110. strcpy(str, (const char*)value);
  19111. for(int i = 0; str[i]; i++)
  19112. {
  19113. str[i] = tolower(str[i]);
  19114. }
  19115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19116. isSuccess = ConfigurationStatus_Accepted;
  19117. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19118. }
  19119. else
  19120. {
  19121. isSuccess = ConfigurationStatus_Rejected;
  19122. }
  19123. }
  19124. #endif
  19125. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19126. {
  19127. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19128. {
  19129. check_ascii = value[0];
  19130. if( (check_ascii < 48) || (check_ascii > 57) )
  19131. {
  19132. isSuccess = ConfigurationStatus_Rejected;
  19133. }
  19134. else
  19135. {
  19136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19137. isSuccess = ConfigurationStatus_Accepted;
  19138. }
  19139. }
  19140. else
  19141. {
  19142. isSuccess = ConfigurationStatus_Rejected;
  19143. }
  19144. }
  19145. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19146. {
  19147. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19148. {
  19149. check_ascii = value[0];
  19150. if( (check_ascii < 48) || (check_ascii > 57) )
  19151. {
  19152. isSuccess = ConfigurationStatus_Rejected;
  19153. }
  19154. else
  19155. {
  19156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19157. isSuccess = ConfigurationStatus_Accepted;
  19158. }
  19159. }
  19160. else
  19161. {
  19162. isSuccess = ConfigurationStatus_Rejected;
  19163. }
  19164. }
  19165. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19166. {
  19167. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19168. {
  19169. strcpy(str, (const char*)value);
  19170. for(int i = 0; str[i]; i++)
  19171. {
  19172. str[i] = tolower(str[i]);
  19173. }
  19174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19175. isSuccess = ConfigurationStatus_Accepted;
  19176. }
  19177. else
  19178. {
  19179. isSuccess = ConfigurationStatus_Rejected;
  19180. }
  19181. }
  19182. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19183. {
  19184. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19185. {
  19186. check_ascii = value[0];
  19187. if( (check_ascii < 48) || (check_ascii > 57) )
  19188. {
  19189. isSuccess = ConfigurationStatus_Rejected;
  19190. }
  19191. else
  19192. {
  19193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19194. isSuccess = ConfigurationStatus_Accepted;
  19195. }
  19196. }
  19197. else
  19198. {
  19199. isSuccess = ConfigurationStatus_Rejected;
  19200. }
  19201. }
  19202. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19203. {
  19204. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19205. {
  19206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19207. isSuccess = ConfigurationStatus_Accepted;
  19208. }
  19209. else
  19210. {
  19211. isSuccess = ConfigurationStatus_Rejected;
  19212. }
  19213. }
  19214. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19215. {
  19216. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19217. {
  19218. check_ascii = value[0];
  19219. if( (check_ascii < 48) || (check_ascii > 57) )
  19220. {
  19221. isSuccess = ConfigurationStatus_Rejected;
  19222. }
  19223. else
  19224. {
  19225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19226. isSuccess = ConfigurationStatus_Accepted;
  19227. }
  19228. }
  19229. else
  19230. {
  19231. isSuccess = ConfigurationStatus_Rejected;
  19232. }
  19233. }
  19234. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19235. {
  19236. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19237. {
  19238. strcpy(str, (const char*)value);
  19239. for(int i = 0; str[i]; i++)
  19240. {
  19241. str[i] = tolower(str[i]);
  19242. }
  19243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19244. isSuccess = ConfigurationStatus_Accepted;
  19245. }
  19246. else
  19247. {
  19248. isSuccess = ConfigurationStatus_Rejected;
  19249. }
  19250. }
  19251. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19252. {
  19253. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19254. {
  19255. check_ascii = value[0];
  19256. if( (check_ascii < 48) || (check_ascii > 57) )
  19257. {
  19258. isSuccess = ConfigurationStatus_Rejected;
  19259. }
  19260. else
  19261. {
  19262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19263. isSuccess = ConfigurationStatus_Accepted;
  19264. }
  19265. }
  19266. else
  19267. {
  19268. isSuccess = ConfigurationStatus_Rejected;
  19269. }
  19270. }
  19271. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19272. return isSuccess;
  19273. }
  19274. int TransactionMessageAttemptsGet(void)
  19275. {
  19276. return TransactionMessageAttemptsValue;
  19277. }
  19278. int FirstHeartBeatResponse(void)
  19279. {
  19280. return FirstHeartBeat;
  19281. }
  19282. int TransactionMessageRetryIntervalGet(void)
  19283. {
  19284. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19285. }
  19286. int ReadHttpStatus(int sock)
  19287. {
  19288. //char c;
  19289. char buff[1024]="",*ptr=buff+1;
  19290. int bytes_received, status;
  19291. DEBUG_INFO("Begin Response ..\n");
  19292. while((bytes_received = recv(sock, ptr, 1, 0))){
  19293. if(bytes_received==-1){
  19294. perror("ReadHttpStatus");
  19295. exit(1);
  19296. }
  19297. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19298. ptr++;
  19299. }
  19300. *ptr=0;
  19301. ptr=buff+1;
  19302. sscanf(ptr,"%*s %d ", &status);
  19303. DEBUG_INFO("%s\n",ptr);
  19304. DEBUG_INFO("status=%d\n",status);
  19305. DEBUG_INFO("End Response ..\n");
  19306. return (bytes_received>0)?status:0;
  19307. }
  19308. //the only filed that it parsed is 'Content-Length'
  19309. int ParseHeader(int sock)
  19310. {
  19311. //char c;
  19312. char buff[1024]="",*ptr=buff+4;
  19313. int bytes_received;
  19314. DEBUG_INFO("Begin HEADER ..\n");
  19315. while((bytes_received = recv(sock, ptr, 1, 0))){
  19316. if(bytes_received==-1){
  19317. perror("Parse Header");
  19318. exit(1);
  19319. }
  19320. if(
  19321. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19322. (ptr[-1]=='\r') && (*ptr=='\n' )
  19323. ) break;
  19324. ptr++;
  19325. }
  19326. *ptr=0;
  19327. ptr=buff+4;
  19328. //printf("%s",ptr);
  19329. if(bytes_received){
  19330. ptr=strstr(ptr,"Content-Length:");
  19331. if(ptr){
  19332. sscanf(ptr,"%*s %d",&bytes_received);
  19333. }else
  19334. bytes_received=-1; //unknown size
  19335. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19336. }
  19337. DEBUG_INFO("End HEADER ..\n");
  19338. return bytes_received ;
  19339. }
  19340. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19341. {
  19342. int result = TRUE;
  19343. char rmFileCmd[100]={0};
  19344. char FilePath[100]={0};
  19345. char ftpbuf[200];
  19346. int systemresult;
  19347. sprintf(FilePath,"/mnt/%s",filename);
  19348. system("ping 8.8.8.8 &");
  19349. if((access(FilePath,F_OK))!=-1)
  19350. {
  19351. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19352. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19353. system(rmFileCmd);
  19354. }
  19355. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19356. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19357. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19358. systemresult = system(ftpbuf);
  19359. if(systemresult != 0)
  19360. {
  19361. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19362. result = FALSE;
  19363. }
  19364. system("pkill ping");
  19365. return result;
  19366. }
  19367. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19368. {
  19369. int result = TRUE;
  19370. char rmFileCmd[100]={0};
  19371. char FilePath[100]={0};
  19372. char ftpbuf[200];
  19373. int systemresult;
  19374. sprintf(FilePath,"/mnt/%s",filename);
  19375. system("ping 8.8.8.8 &");
  19376. if((access(FilePath,F_OK))!=-1)
  19377. {
  19378. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19379. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19380. system(rmFileCmd);
  19381. }
  19382. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19383. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19384. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19385. systemresult = system(ftpbuf);
  19386. if(systemresult != 0)
  19387. {
  19388. DEBUG_WARN("scp error!\n");
  19389. result = FALSE;
  19390. }
  19391. system("pkill ping");
  19392. return result;
  19393. }
  19394. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19395. {
  19396. int result = TRUE;
  19397. char rmFileCmd[100]={0};
  19398. char FilePath[100]={0};
  19399. char ftpbuf[200];
  19400. int systemresult;
  19401. sprintf(FilePath,"/mnt/%s",filename);
  19402. system("ping 8.8.8.8 &");
  19403. if((access(FilePath,F_OK))!=-1)
  19404. {
  19405. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19406. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19407. system(rmFileCmd);
  19408. }
  19409. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19410. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  19411. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19412. systemresult = system(ftpbuf);
  19413. if(systemresult != 0)
  19414. {
  19415. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  19416. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19417. systemresult = system(ftpbuf);
  19418. if(systemresult != 0)
  19419. {
  19420. DEBUG_WARN("FTP download fail!\n");
  19421. result = FALSE;
  19422. }
  19423. }
  19424. system("pkill ping");
  19425. return result;
  19426. }
  19427. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19428. {
  19429. char rmFileCmd[100]={0};
  19430. char FilePath[100]={0};
  19431. char buf[512];
  19432. int systemresult = 0;
  19433. //DEBUG_INFO("filename=%s\n",filename);
  19434. //DEBUG_INFO("url=%s\n",url);
  19435. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19436. if((access(FilePath,F_OK))!=-1)
  19437. {
  19438. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19439. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19440. system(rmFileCmd);
  19441. }
  19442. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19443. if(fp == NULL)
  19444. {
  19445. DEBUG_INFO("log is NULL\n");
  19446. return FALSE;
  19447. }
  19448. else
  19449. {
  19450. fprintf(fp, "%s\n", url);
  19451. fprintf(fp, "%s\n", filename);
  19452. fclose(fp);
  19453. }
  19454. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19455. if(phpFP == NULL)
  19456. {
  19457. DEBUG_INFO("PHP upload fail.\n");
  19458. return FALSE;
  19459. }
  19460. else
  19461. {
  19462. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19463. {
  19464. if(strstr(buf, "result") != NULL)
  19465. {
  19466. sscanf(buf, "result: %d", &systemresult);
  19467. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19468. }
  19469. }
  19470. pclose(phpFP);
  19471. }
  19472. if(systemresult != 1)
  19473. {
  19474. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19475. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19476. if(phpFP == NULL)
  19477. {
  19478. DEBUG_WARN("PHP PUT upload fail.\n");
  19479. return FALSE;
  19480. }
  19481. else
  19482. {
  19483. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19484. {
  19485. if(strstr(buf, "result") != NULL)
  19486. {
  19487. sscanf(buf, "result: %d", &systemresult);
  19488. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19489. }
  19490. }
  19491. pclose(phpFP);
  19492. }
  19493. }
  19494. if(systemresult != 1)
  19495. {
  19496. DEBUG_WARN("PHP PUT upload fail.\n");
  19497. return FALSE;
  19498. }
  19499. return TRUE;
  19500. }
  19501. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19502. {
  19503. int result = FALSE;
  19504. char ftpbuf[200];
  19505. int systemresult;
  19506. /*
  19507. // Domaind name transfer to IP address
  19508. struct hostent* server;
  19509. char *IPbuffer;
  19510. server = gethostbyname(location);
  19511. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19512. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19513. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19514. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19515. systemresult = system(ftpbuf);
  19516. if(systemresult != 0)
  19517. {
  19518. DEBUG_INFO("ftpput error!\n");
  19519. }
  19520. else
  19521. {
  19522. result = TRUE;
  19523. DEBUG_INFO("ftpput OK!\n");
  19524. }
  19525. return result;
  19526. }
  19527. int GetOcppServerURL()
  19528. {
  19529. int result = FALSE;
  19530. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19531. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19532. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19533. struct yuarel url;
  19534. char urlStr[512];
  19535. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19536. {
  19537. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19538. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19539. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19540. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19541. if(yuarel_parse(&url, urlStr) != -1)
  19542. {
  19543. sprintf(OcppProtocol, "%s", url.scheme);
  19544. sprintf(OcppHost, "%s", url.host);
  19545. if(url.path == NULL)
  19546. OcppTempPath[0] = '\0';
  19547. else
  19548. {
  19549. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19550. {
  19551. sprintf(OcppTempPath, "%s/", url.path);
  19552. }
  19553. else
  19554. {
  19555. sprintf(OcppTempPath, "%s", url.path);
  19556. }
  19557. }
  19558. if(url.port == 0)
  19559. {
  19560. if(strcmp(OcppProtocol, "wss") == 0)
  19561. OcppPort = 443;
  19562. else
  19563. OcppPort = 80;
  19564. }
  19565. else
  19566. OcppPort = url.port;
  19567. result = TRUE;
  19568. }
  19569. }
  19570. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19571. {
  19572. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19573. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19574. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19575. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19576. if(yuarel_parse(&url, urlStr) != -1)
  19577. {
  19578. sprintf(OcppProtocol, "%s", url.scheme);
  19579. sprintf(OcppHost, "%s", url.host);
  19580. if(url.path == NULL)
  19581. OcppTempPath[0] = '\0';
  19582. else
  19583. sprintf(OcppTempPath, "%s", url.path);
  19584. if(url.port == 0)
  19585. {
  19586. if(strcmp(OcppProtocol, "wss") == 0)
  19587. OcppPort = 443;
  19588. else
  19589. OcppPort = 80;
  19590. }
  19591. else
  19592. OcppPort = url.port;
  19593. result = TRUE;
  19594. }
  19595. }
  19596. else
  19597. {
  19598. strcpy(OcppHost,"");
  19599. }
  19600. return result;
  19601. }
  19602. int GetOcppPath()
  19603. {
  19604. int result = FALSE;
  19605. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19606. {
  19607. if(OcppTempPath == NULL)
  19608. {
  19609. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19610. }
  19611. else
  19612. {
  19613. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19614. }
  19615. result = TRUE;
  19616. goto End;
  19617. }
  19618. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19619. {
  19620. if(OcppTempPath == NULL)
  19621. {
  19622. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19623. }
  19624. else
  19625. {
  19626. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19627. }
  19628. result = TRUE;
  19629. goto End;
  19630. }
  19631. else
  19632. {
  19633. strcpy(OcppPath,"");
  19634. }
  19635. End:
  19636. return result;
  19637. }
  19638. int GetOcppPort()
  19639. {
  19640. return OcppPort;
  19641. }
  19642. int GetOcppConnStatus(void)
  19643. {
  19644. return ShmOCPP16Data->OcppConnStatus;
  19645. }
  19646. void SetOcppConnStatus(uint8_t status)
  19647. {
  19648. ShmOCPP16Data->OcppConnStatus = status;
  19649. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19650. }
  19651. int GetHeartBeatWithNOResponse(void)
  19652. {
  19653. return HeartBeatWithNOResponse;
  19654. }
  19655. void SetHeartBeatWithNOResponse(void)
  19656. {
  19657. HeartBeatWithNOResponse = 0;
  19658. }
  19659. void GetStartTransactionIdTag(int gun_index)
  19660. {
  19661. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19662. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19663. }
  19664. int GetStartTransactionId(int gun_index)
  19665. {
  19666. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19667. }
  19668. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19669. {
  19670. char ch;
  19671. FILE *fptr1;
  19672. int temptransactionId;
  19673. char str[100]={0};
  19674. temptransactionId = 0;
  19675. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19676. {
  19677. DEBUG_INFO("IdTag is empty.\n");
  19678. return temptransactionId;
  19679. }
  19680. /*------ Read the file ----------------*/
  19681. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19682. if (!fptr1)
  19683. {
  19684. DEBUG_INFO("QueueTransactionId file open error.\n");
  19685. //printf(" File not found or unable to open the input file!!\n");
  19686. return temptransactionId;
  19687. }
  19688. ch=fgetc(fptr1);
  19689. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19690. rewind(fptr1);
  19691. if(ch!=EOF)
  19692. {
  19693. // printf("%c",ch);
  19694. while (fgets(str, 100, fptr1) != NULL)
  19695. {
  19696. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19697. if(str[0]=='\0')
  19698. {
  19699. break;
  19700. }
  19701. char *revbuf[8] = {0}; // Variable store string split
  19702. int num = 0;// Quantity after string split
  19703. DEBUG_INFO("Transaction queue data= %s\n", str);
  19704. splitstring(str,",",revbuf,&num); // String split
  19705. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19706. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19707. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19708. DEBUG_INFO("------------------------------\n");
  19709. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19710. {
  19711. if(isStopTransaction)
  19712. {
  19713. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19714. {
  19715. temptransactionId = atoi(revbuf[2]);
  19716. //break;
  19717. }
  19718. }
  19719. else
  19720. {
  19721. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19722. {
  19723. temptransactionId = atoi(revbuf[2]);
  19724. //break;
  19725. }
  19726. }
  19727. }
  19728. }
  19729. }
  19730. else
  19731. DEBUG_INFO("EOF\n");
  19732. fclose(fptr1);
  19733. /*------- End of reading ---------------*/
  19734. return temptransactionId;
  19735. }
  19736. void SetTransactionIdZero(int transactionId)
  19737. {
  19738. char ch;
  19739. FILE *fptr1, *fptr2;
  19740. int temptransactionId = 0;
  19741. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19742. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19743. if (!fptr1)
  19744. {
  19745. //printf(" File not found or unable to open the input file!!\n");
  19746. return ;
  19747. }
  19748. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19749. if (!fptr2)
  19750. {
  19751. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19752. fclose(fptr1);
  19753. return ;
  19754. }
  19755. ch=fgetc(fptr1);
  19756. rewind(fptr1);
  19757. if(ch!=EOF)
  19758. {
  19759. // copy all contents to the temporary file except the specific line
  19760. while (fgets(str, 100, fptr1) != NULL)
  19761. {
  19762. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19763. if(str[0]=='\0')
  19764. {
  19765. break;
  19766. }
  19767. char *revbuf[8] = {0};
  19768. int num = 0;
  19769. strcpy(strtemp, str);
  19770. splitstring(str,",",revbuf,&num);
  19771. if(revbuf[2][0] != '\0')
  19772. {
  19773. temptransactionId = atoi(revbuf[2]);
  19774. if(transactionId != temptransactionId)
  19775. {
  19776. fprintf(fptr2, "%s\n", strtemp);
  19777. }
  19778. }
  19779. }
  19780. }
  19781. fclose(fptr1);
  19782. fclose(fptr2);
  19783. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19784. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19785. /*------ Read the file ----------------*/
  19786. }
  19787. int InternetDisconnect(void)
  19788. {
  19789. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19790. }
  19791. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19792. void storeTempStopTransaction(int gun_index)
  19793. {
  19794. char guid[37]={0};
  19795. int tempIndex = 0;
  19796. char TempStopTransaction[256];
  19797. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19798. DEBUG_INFO("storeTempStopTransaction...\n");
  19799. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19800. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19801. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  19802. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19803. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19804. {
  19805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19806. {
  19807. tempIndex = ((gun_index==2) ? 1: 0);
  19808. }
  19809. else
  19810. {
  19811. tempIndex = gun_index;
  19812. }
  19813. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19814. {
  19815. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19816. {
  19817. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19818. }
  19819. }// END OF CHAdeMO_QUANTITY
  19820. }
  19821. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19822. {
  19823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19824. {
  19825. tempIndex = ((gun_index==2) ? 1: 0);
  19826. }
  19827. else
  19828. {
  19829. tempIndex = gun_index;
  19830. }
  19831. for (int index = 0; index < CCS_QUANTITY; index++)
  19832. {
  19833. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19834. {
  19835. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19836. }
  19837. }// END OF CCS_QUANTITY
  19838. }
  19839. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19840. {
  19841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19842. {
  19843. tempIndex = ((gun_index==2) ? 1: 0);
  19844. }
  19845. else
  19846. {
  19847. tempIndex = gun_index;
  19848. }
  19849. for (int index = 0; index < GB_QUANTITY; index++)
  19850. {
  19851. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19852. {
  19853. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19854. }
  19855. }// END OF GB_QUANTITY
  19856. }
  19857. else if(gunType[gun_index] == GUN_TYPE_DO)
  19858. {
  19859. tempIndex = gun_index;
  19860. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19861. {
  19862. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19863. {
  19864. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19865. }
  19866. }
  19867. }
  19868. else
  19869. {
  19870. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19871. {
  19872. tempIndex = 2;
  19873. }
  19874. else
  19875. {
  19876. tempIndex = gun_index;
  19877. }
  19878. for (int index = 0; index < AC_QUANTITY; index++)
  19879. {
  19880. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19881. {
  19882. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19883. }
  19884. }// END OF AC_QUANTITY
  19885. }
  19886. //Stop Transaction Time
  19887. struct timeval tmnow;
  19888. struct tm *tm;
  19889. char buf[28];//, usec_buf[6];
  19890. gettimeofday(&tmnow, NULL);
  19891. time_t t;
  19892. t = time(NULL);
  19893. /*UTC time and date*/
  19894. tm = gmtime(&t);
  19895. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  19896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  19897. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19899. random_uuid(guid);
  19900. /***********************************transactionData******************************************************/
  19901. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  19902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  19903. //=================================
  19904. //1. Transaction_Begin
  19905. //=================================
  19906. //============================== Energy.Active.Import.Interval ===========================================
  19907. //=================================
  19908. //2. Transaction_End
  19909. //=================================
  19910. //2.1====================================== Current.Import L1 ==============================================
  19911. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19912. {
  19913. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  19914. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19915. {
  19916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19917. {
  19918. tempIndex = ((gun_index==2) ? 1: 0);
  19919. }
  19920. else
  19921. {
  19922. tempIndex = gun_index;
  19923. }
  19924. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19925. {
  19926. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19927. {
  19928. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19929. }
  19930. }// End of for CHAdeMO_QUANTITY
  19931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19932. }
  19933. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19934. {
  19935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19936. {
  19937. tempIndex = ((gun_index==2) ? 1: 0);
  19938. }
  19939. else
  19940. {
  19941. tempIndex = gun_index;
  19942. }
  19943. for (int index = 0; index < CCS_QUANTITY; index++)
  19944. {
  19945. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19946. {
  19947. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19948. }
  19949. }// End of for CCS_QUANTITY
  19950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19951. }
  19952. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19953. {
  19954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19955. {
  19956. tempIndex = ((gun_index==2) ? 1: 0);
  19957. }
  19958. else
  19959. {
  19960. tempIndex = gun_index;
  19961. }
  19962. for (int index = 0; index < GB_QUANTITY; index++)
  19963. {
  19964. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19965. {
  19966. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19967. }
  19968. }// End of for GB_QUANTITY
  19969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19970. }
  19971. else if(gunType[gun_index] == GUN_TYPE_DO)
  19972. {
  19973. tempIndex = gun_index;
  19974. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19975. {
  19976. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19977. {
  19978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19979. }
  19980. }
  19981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19982. }
  19983. else
  19984. {
  19985. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19986. {
  19987. tempIndex = 2;
  19988. }
  19989. else
  19990. {
  19991. tempIndex = gun_index;
  19992. }
  19993. for (int index = 0; index < AC_QUANTITY; index++)
  19994. {
  19995. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19996. {
  19997. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  19998. }
  19999. }// End of for AC_QUANTITY
  20000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  20001. }
  20002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  20004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  20005. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  20006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  20007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20008. }
  20009. //2.2===================================== Energy.Active.Import.Interval ==========================================
  20010. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  20011. {
  20012. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20013. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20014. {
  20015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20016. {
  20017. tempIndex = ((gun_index==2) ? 1: 0);
  20018. }
  20019. else
  20020. {
  20021. tempIndex = gun_index;
  20022. }
  20023. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20024. {
  20025. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20026. {
  20027. 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
  20028. }
  20029. }// END OF CHAdeMO_QUANTITY
  20030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20031. }
  20032. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20033. {
  20034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20035. {
  20036. tempIndex = ((gun_index==2) ? 1: 0);
  20037. }
  20038. else
  20039. {
  20040. tempIndex = gun_index;
  20041. }
  20042. for (int index = 0; index < CCS_QUANTITY; index++)
  20043. {
  20044. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20045. {
  20046. 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
  20047. }
  20048. }// END OF CCS_QUANTITY
  20049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20050. }
  20051. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20052. {
  20053. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20054. {
  20055. tempIndex = ((gun_index==2) ? 1: 0);
  20056. }
  20057. else
  20058. {
  20059. tempIndex = gun_index;
  20060. }
  20061. for (int index = 0; index < GB_QUANTITY; index++)
  20062. {
  20063. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20064. {
  20065. 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
  20066. }
  20067. }// END OF GB_QUANTITY
  20068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20069. }
  20070. else if(gunType[gun_index] == GUN_TYPE_DO)
  20071. {
  20072. tempIndex = gun_index;
  20073. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20074. {
  20075. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20076. {
  20077. 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
  20078. }
  20079. }
  20080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20081. }
  20082. else
  20083. {
  20084. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20085. {
  20086. tempIndex = 2;
  20087. }
  20088. else
  20089. {
  20090. tempIndex = gun_index;
  20091. }
  20092. for (int index = 0; index < AC_QUANTITY; index++)
  20093. {
  20094. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20095. {
  20096. 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
  20097. }
  20098. }// END OF AC_QUANTITY
  20099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  20100. }
  20101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  20103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  20104. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  20105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  20106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  20107. }
  20108. //2.3====================================== Power.Active.Import =========================================
  20109. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  20110. {
  20111. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20112. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20113. {
  20114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20115. {
  20116. tempIndex = ((gun_index==2) ? 1: 0);
  20117. }
  20118. else
  20119. {
  20120. tempIndex = gun_index;
  20121. }
  20122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20123. {
  20124. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20125. {
  20126. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20127. }
  20128. } // End for CHAdeMO_QUANTITY
  20129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20130. }
  20131. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20132. {
  20133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20134. {
  20135. tempIndex = ((gun_index==2) ? 1: 0);
  20136. }
  20137. else
  20138. {
  20139. tempIndex = gun_index;
  20140. }
  20141. for (int index = 0; index < CCS_QUANTITY; index++)
  20142. {
  20143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20144. {
  20145. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20146. }
  20147. } // END for CCS_QUANTITY
  20148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20149. }
  20150. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20151. {
  20152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20153. {
  20154. tempIndex = ((gun_index==2) ? 1: 0);
  20155. }
  20156. else
  20157. {
  20158. tempIndex = gun_index;
  20159. }
  20160. for (int index = 0; index < GB_QUANTITY; index++)
  20161. {
  20162. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20163. {
  20164. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20165. }
  20166. }// END for GB_QUANTITY
  20167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20168. }
  20169. else if(gunType[gun_index] == GUN_TYPE_DO)
  20170. {
  20171. tempIndex = gun_index;
  20172. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20173. {
  20174. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20175. {
  20176. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20177. }
  20178. }
  20179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20180. }
  20181. else
  20182. {
  20183. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20184. {
  20185. tempIndex = 2;
  20186. }
  20187. else
  20188. {
  20189. tempIndex = gun_index;
  20190. }
  20191. for (int index = 0; index < AC_QUANTITY; index++)
  20192. {
  20193. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20194. {
  20195. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20196. }
  20197. } // END for AC_QUANTITY
  20198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  20199. }
  20200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  20202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  20203. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  20204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  20205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  20206. }
  20207. //2.4====================================== Voltage L1 ====================================================
  20208. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20209. {
  20210. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20211. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20212. {
  20213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20214. {
  20215. tempIndex = ((gun_index==2) ? 1: 0);
  20216. }
  20217. else
  20218. {
  20219. tempIndex = gun_index;
  20220. }
  20221. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20222. {
  20223. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20224. {
  20225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20226. }
  20227. } // END OF FOR CHAdeMO_QUANTITY
  20228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20229. }
  20230. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20231. {
  20232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20233. {
  20234. tempIndex = ((gun_index==2) ? 1: 0);
  20235. }
  20236. else
  20237. {
  20238. tempIndex = gun_index;
  20239. }
  20240. for (int index = 0; index < CCS_QUANTITY; index++)
  20241. {
  20242. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20243. {
  20244. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20245. }
  20246. } // END OF FOR CCS_QUANTITY
  20247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20248. }
  20249. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20250. {
  20251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20252. {
  20253. tempIndex = ((gun_index==2) ? 1: 0);
  20254. }
  20255. else
  20256. {
  20257. tempIndex = gun_index;
  20258. }
  20259. for (int index = 0; index < GB_QUANTITY; index++)
  20260. {
  20261. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20262. {
  20263. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20264. }
  20265. } // END OF FOR GB_QUANTITY
  20266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20267. }
  20268. else if(gunType[gun_index] == GUN_TYPE_DO)
  20269. {
  20270. tempIndex = gun_index;
  20271. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20272. {
  20273. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20274. {
  20275. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20276. }
  20277. }
  20278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20279. }
  20280. else
  20281. {
  20282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20283. {
  20284. tempIndex = 2;
  20285. }
  20286. else
  20287. {
  20288. tempIndex = gun_index;
  20289. }
  20290. for (int index = 0; index < AC_QUANTITY; index++)
  20291. {
  20292. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20293. {
  20294. 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
  20295. }
  20296. } // END OF FOR AC_QUANTITY
  20297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  20298. }
  20299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  20301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  20302. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  20303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  20304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20305. }
  20306. //2.5============================================== End SoC =========================================================
  20307. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  20308. {
  20309. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20310. 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))
  20311. {
  20312. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  20313. {
  20314. tempIndex = ((gun_index==2) ? 1: 0);
  20315. }
  20316. else
  20317. {
  20318. tempIndex = gun_index;
  20319. }
  20320. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20321. {
  20322. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20323. {
  20324. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20325. {
  20326. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  20327. }
  20328. }
  20329. }
  20330. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20331. {
  20332. for (int index = 0; index < CCS_QUANTITY; index++)
  20333. {
  20334. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20335. {
  20336. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  20337. }
  20338. }
  20339. }
  20340. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20341. {
  20342. for (int index = 0; index < GB_QUANTITY; index++)
  20343. {
  20344. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20345. {
  20346. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  20347. }
  20348. }
  20349. }
  20350. else if(gunType[gun_index] == GUN_TYPE_DO)
  20351. {
  20352. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20353. {
  20354. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20355. {
  20356. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  20357. }
  20358. }
  20359. }
  20360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  20362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  20363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  20364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  20365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  20366. } // END FOR DC CASE
  20367. }
  20368. //2.6====================================== Current.Import L2 ==============================================
  20369. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20370. {
  20371. // AC 3 phase L2 current
  20372. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20373. {
  20374. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20375. {
  20376. tempIndex = 2;
  20377. }
  20378. else
  20379. {
  20380. tempIndex = gun_index;
  20381. }
  20382. for (int index = 0; index < AC_QUANTITY; index++)
  20383. {
  20384. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20385. {
  20386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  20387. }
  20388. }// End of for AC_QUANTITY
  20389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  20390. }
  20391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  20393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  20394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  20395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20396. }
  20397. //2.7====================================== Current.Import L3 ==============================================
  20398. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20399. {
  20400. // AC 3 phase L3 current
  20401. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20402. {
  20403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20404. {
  20405. tempIndex = 2;
  20406. }
  20407. else
  20408. {
  20409. tempIndex = gun_index;
  20410. }
  20411. for (int index = 0; index < AC_QUANTITY; index++)
  20412. {
  20413. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20414. {
  20415. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  20416. }
  20417. }// End of for AC_QUANTITY
  20418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  20419. }
  20420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  20422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  20423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  20424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20425. }
  20426. //2.9====================================== Voltage L2 ====================================================
  20427. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20428. {
  20429. // AC 3 phase L2 volatge
  20430. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20431. {
  20432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20433. {
  20434. tempIndex = 2;
  20435. }
  20436. else
  20437. {
  20438. tempIndex = gun_index;
  20439. }
  20440. for (int index = 0; index < AC_QUANTITY; index++)
  20441. {
  20442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20443. {
  20444. 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
  20445. }
  20446. } // END OF FOR AC_QUANTITY
  20447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  20448. }
  20449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  20451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  20452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  20453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20454. }
  20455. //2.10====================================== Voltage L3 ====================================================
  20456. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20457. {
  20458. // AC 3 phase L3 volatge
  20459. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20460. {
  20461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20462. {
  20463. tempIndex = 2;
  20464. }
  20465. else
  20466. {
  20467. tempIndex = gun_index;
  20468. }
  20469. for (int index = 0; index < AC_QUANTITY; index++)
  20470. {
  20471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20472. {
  20473. 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
  20474. }
  20475. } // END OF FOR AC_QUANTITY
  20476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  20477. }
  20478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  20480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  20481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  20482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20483. }
  20484. //====================== Start SoC ================================
  20485. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  20486. {
  20487. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20488. 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))
  20489. {
  20490. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  20491. {
  20492. tempIndex = ((gun_index==2) ? 1: 0);
  20493. }
  20494. else
  20495. {
  20496. tempIndex = gun_index;
  20497. }
  20498. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20499. {
  20500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20501. {
  20502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20503. {
  20504. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  20505. }
  20506. }
  20507. }
  20508. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20509. {
  20510. for (int index = 0; index < CCS_QUANTITY; index++)
  20511. {
  20512. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20513. {
  20514. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  20515. }
  20516. }
  20517. }
  20518. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20519. {
  20520. for (int index = 0; index < GB_QUANTITY; index++)
  20521. {
  20522. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20523. {
  20524. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  20525. }
  20526. }
  20527. }
  20528. else if(gunType[gun_index] == GUN_TYPE_DO)
  20529. {
  20530. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20531. {
  20532. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20533. {
  20534. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  20535. }
  20536. }
  20537. }
  20538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  20539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  20540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  20541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  20542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  20543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  20544. } // END FOR DC CASE
  20545. }
  20546. //======================================== Message create ==============================================
  20547. json_object *StopTransaction = json_object_new_object();
  20548. json_object *transactionDatas = json_object_new_array();
  20549. json_object *sampledValues = json_object_new_array();
  20550. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  20551. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  20552. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  20553. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  20554. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  20555. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  20556. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  20557. {
  20558. json_object *transactionData = json_object_new_object();
  20559. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  20560. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  20561. {
  20562. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  20563. {
  20564. json_object *sampledValue = json_object_new_object();
  20565. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  20566. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  20567. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  20568. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  20569. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  20570. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  20571. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  20572. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  20573. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  20574. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  20575. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  20576. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  20577. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  20578. json_object_array_add(sampledValues, sampledValue);
  20579. }
  20580. }
  20581. json_object_object_add(transactionData, "sampledValue", sampledValues);
  20582. json_object_array_add(transactionDatas, transactionData);
  20583. }
  20584. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  20585. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  20586. ,MESSAGE_TYPE_CALL
  20587. ,guid
  20588. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  20589. json_object_put(StopTransaction);
  20590. // Check File "TempStopTransaction" Exist
  20591. if((access(TempStopTransaction,F_OK))!=-1)
  20592. {
  20593. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  20594. fclose(fopen(TempStopTransaction, "w"));
  20595. }
  20596. else
  20597. {
  20598. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  20599. FILE *log = fopen(TempStopTransaction, "w+");
  20600. if(log == NULL)
  20601. {
  20602. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  20603. return ;
  20604. }
  20605. else
  20606. {
  20607. fclose(log);
  20608. }
  20609. }
  20610. //Add TempStopTransaction | Update TempStopTransaction
  20611. // open file for writing
  20612. FILE *outfile;
  20613. outfile = fopen (TempStopTransaction, "a");
  20614. //DEBUG_INFO("data = %s\n", queuedata);
  20615. fputs(queuedata, outfile);
  20616. fputs("\n", outfile);
  20617. fclose (outfile);
  20618. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20619. OCPP_updatePeriodEnergy(gun_index);
  20620. }
  20621. void checkTempStopTransaction(int gun_index)
  20622. {
  20623. FILE *fptr1;
  20624. char ch;
  20625. char str[QUEUE_MESSAGE_LENGTH]={0};
  20626. char guid[37]={0};
  20627. char tempdata[65]={0};
  20628. char connectorStr[2]={0};
  20629. char TempStopTransaction[256];
  20630. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20631. fptr1 = fopen(TempStopTransaction, "r");
  20632. //TempStopTransaction格式: 槍號,StopTransaction封包
  20633. if (!fptr1)
  20634. {
  20635. //printf(" File not found or unable to open the input file!!\n");
  20636. return ;
  20637. }
  20638. ch=fgetc(fptr1);
  20639. //printf(" Now the content of the file %s is : \n",fname);
  20640. rewind(fptr1);
  20641. if(ch!=EOF)
  20642. {
  20643. // copy all contents to the temporary file except the specific line
  20644. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  20645. {
  20646. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20647. if(str[0]=='\0')
  20648. {
  20649. break;
  20650. }
  20651. //TempStopTransaction格式: 槍號,StopTransaction封包
  20652. strncpy(connectorStr, str, 1);
  20653. if(atoi(connectorStr) != (gun_index+1))
  20654. {
  20655. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  20656. fclose(fptr1);
  20657. return ;
  20658. }
  20659. //random_uuid(guid);
  20660. strncpy(guid, str+6, 36); //copy guid
  20661. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  20662. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  20663. {
  20664. //DEBUG_INFO("StopTransaction mapitem pass\n");
  20665. }
  20666. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  20667. OCPP_insert_transaction_msg(NO, str);
  20668. memset(str,0,ARRAY_SIZE(str));
  20669. }
  20670. }
  20671. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  20672. fclose(fptr1);
  20673. remove(TempStopTransaction); // remove the original file
  20674. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20675. }
  20676. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  20677. {
  20678. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20679. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  20680. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  20681. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  20682. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  20683. }
  20684. void FillTransactionId(int ConnectorId, int TransactionId)
  20685. {
  20686. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20687. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  20688. }
  20689. int GetWebSocketPingInterval(void)
  20690. {
  20691. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  20692. }
  20693. int GetServerSign(void)
  20694. {
  20695. return server_sign;
  20696. }
  20697. uint8_t GetOcppSecurityProfile()
  20698. {
  20699. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  20700. }
  20701. void MergeCertificates()
  20702. {
  20703. char cmdBuf[2048]={0};
  20704. if(access(ROOTCA_CS,F_OK) != -1)
  20705. {
  20706. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  20707. }
  20708. else
  20709. {
  20710. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  20711. }
  20712. system(cmdBuf);
  20713. }
  20714. void GetOcppChargerBoxId(uint8_t *data)
  20715. {
  20716. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20717. }
  20718. void GetOcppSecurityPassword(uint8_t *data)
  20719. {
  20720. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20721. }
  20722. void SetOcppVersion(uint8_t *version)
  20723. {
  20724. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20725. DEBUG_INFO("ocpp version: %s\n", version);
  20726. if(strstr((char*)version, "ocpp1.6") != NULL)
  20727. {
  20728. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20729. }
  20730. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20731. {
  20732. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20733. system("pkill OcppBackend");
  20734. }
  20735. }
  20736. void SetServerSign(int value)
  20737. {
  20738. server_sign = value;
  20739. }
  20740. int GetBootNotificationInterval(void)
  20741. {
  20742. return BootNotificationInterval;
  20743. }
  20744. int GetInternetConn(void)
  20745. {
  20746. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20747. }
  20748. int GetBackendConnectionTimeout(void)
  20749. {
  20750. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20751. }
  20752. int isConnectorInitMode(int gun_index)
  20753. {
  20754. int tempIndex = 0;
  20755. int result = TRUE;
  20756. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20757. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20758. {
  20759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20760. {
  20761. tempIndex = ((gun_index==2) ? 1: 0);
  20762. }
  20763. else
  20764. {
  20765. tempIndex = gun_index;
  20766. }
  20767. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20768. {
  20769. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20770. {
  20771. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20772. } //end of the same index
  20773. }//end of for CHAdeMO_QUANTITY
  20774. }
  20775. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20776. {
  20777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20778. {
  20779. tempIndex = ((gun_index==2) ? 1: 0);
  20780. }
  20781. else
  20782. {
  20783. tempIndex = gun_index;
  20784. }
  20785. for (int index = 0; index < CCS_QUANTITY; index++)
  20786. {
  20787. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20788. {
  20789. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20790. } //end of the same index
  20791. } // end of for CCS_QUANTITY
  20792. }
  20793. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20794. {
  20795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20796. {
  20797. tempIndex = ((gun_index==2) ? 1: 0);
  20798. }
  20799. else
  20800. {
  20801. tempIndex = gun_index;
  20802. }
  20803. for (int index = 0; index < GB_QUANTITY; index++)
  20804. {
  20805. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20806. {
  20807. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20808. } //end of the same index
  20809. } // end of for GB_QUANTITY
  20810. }
  20811. else if(gunType[gun_index] == GUN_TYPE_DO)
  20812. {
  20813. tempIndex = gun_index;
  20814. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20815. {
  20816. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20817. {
  20818. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20819. } //end of the same index
  20820. }
  20821. }
  20822. else
  20823. {
  20824. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20825. {
  20826. tempIndex = 2;
  20827. }
  20828. else
  20829. {
  20830. tempIndex = gun_index;
  20831. }
  20832. for (int index = 0; index < AC_QUANTITY; index++)
  20833. {
  20834. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20835. {
  20836. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20837. }//end of the same index
  20838. }//end of for AC_QUANTITY
  20839. }
  20840. return result;
  20841. }
  20842. void refreshProcDogTimer()
  20843. {
  20844. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20845. }
  20846. void InitialSystemValue(void)
  20847. {
  20848. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20849. locallistVersion=0;
  20850. BootNotificationInterval = 0;
  20851. authorizeRetryTimes = 0;
  20852. GunStatusInterval = 10;
  20853. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20854. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20855. //Hear Beat
  20856. HeartBeatWithNOResponse = 0;
  20857. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20858. FirstHeartBeat = 0;
  20859. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20860. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20861. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20862. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20863. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20864. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20865. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20866. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20867. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20868. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20869. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20870. //Status && ConnectorPlugIn Setting
  20871. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20872. {
  20873. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20874. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20875. }
  20876. for (int index = 0; index < CCS_QUANTITY; index++)
  20877. {
  20878. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20879. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20880. }
  20881. for (int index = 0; index < GB_QUANTITY; index++)
  20882. {
  20883. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20884. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20885. }
  20886. for (int index = 0; index < AC_QUANTITY; index++)
  20887. {
  20888. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20889. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20890. }
  20891. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20892. {
  20893. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20894. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20895. }
  20896. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20897. {
  20898. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20899. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20900. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20901. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20902. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20903. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20904. }
  20905. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20906. refreshStartTimer(&clientTime.Heartbeat);
  20907. sleep(1);
  20908. }
  20909. void LWS_Send(char *str)
  20910. {
  20911. //=====================================================
  20912. // Check InternetConn 0: disconnected, 1: connected
  20913. //====================================================
  20914. if(GetOcppConnStatus() == 0)
  20915. {
  20916. DEBUG_INFO("offline now !!!\n");
  20917. return;
  20918. }
  20919. // Only disable isWebsocketSendable operation initiated by charger
  20920. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20921. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20922. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20923. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20924. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20925. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20926. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20927. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20928. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20929. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20930. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20931. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20932. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20933. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20934. {
  20935. isWebsocketSendable = 0;
  20936. }
  20937. pthread_mutex_lock(&lock_send);
  20938. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20939. sprintf((char *)SendBuffer, "%s", str);
  20940. SendBufLen = strlen(str);
  20941. pthread_mutex_unlock(&lock_send);
  20942. lws_callback_on_writable(wsi_client);
  20943. //lws_service(context, 0);
  20944. //sleep(1);
  20945. }
  20946. void LWS_SendNow(char *str)
  20947. {
  20948. //=====================================================
  20949. // Check InternetConn 0: disconnected, 1: connected
  20950. //====================================================
  20951. if(GetOcppConnStatus() == 0)
  20952. {
  20953. DEBUG_INFO("offline now !!!\n");
  20954. return;
  20955. }
  20956. // Only disable isWebsocketSendable operation initiated by charger
  20957. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20958. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20959. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20960. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20961. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20962. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20963. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20964. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20965. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20966. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20967. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20968. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20969. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20970. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20971. {
  20972. isWebsocketSendable = 0;
  20973. }
  20974. pthread_mutex_lock(&lock_send);
  20975. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20976. sprintf((char *)SendBuffer, "%s", str);
  20977. SendBufLen = strlen(str);
  20978. pthread_mutex_unlock(&lock_send);
  20979. lws_callback_on_writable(wsi_client);
  20980. lws_service(context, 0);
  20981. //sleep(1);
  20982. }