MessageHandler.c 989 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031
  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 Connector0PreviousSystemStatus;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. struct timespec TcciQueryOccupancyDeduct;
  118. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  119. }clientTime;
  120. typedef union
  121. {
  122. //Operations Initiated by Central System
  123. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  124. struct
  125. {
  126. //CsMsgValue[0]
  127. unsigned char StatusNotificationReq:1; //bit 0,
  128. unsigned char StatusNotificationConf:1; //bit 1,
  129. unsigned char TriggerMeterValue:1; //bit 2,
  130. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  131. unsigned char isOnCharging:1; //bit 4,
  132. unsigned char :3; //bit5~7
  133. }bits[CONNECTOR_QUANTITY];
  134. }CpinitiateMsg;
  135. CpinitiateMsg cpinitateMsg;
  136. //GetConfiguration Array
  137. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  138. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  139. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  140. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  141. static char *ChargePointErrorCodeStr[] = {
  142. MACROSTR(ConnectorLockFailure),
  143. MACROSTR(EVCommunicationError),
  144. MACROSTR(GroundFailure),
  145. MACROSTR(HighTemperature),
  146. MACROSTR(InternalError),
  147. MACROSTR(LocalListConflict),
  148. MACROSTR(NoError),
  149. MACROSTR(OtherError),
  150. MACROSTR(OverCurrentFailure),
  151. MACROSTR(OverVoltage),
  152. MACROSTR(PowerMeterFailure),
  153. MACROSTR(PowerSwitchFailure),
  154. MACROSTR(ReaderFailure),
  155. MACROSTR(ResetFailure),
  156. MACROSTR(UnderVoltage),
  157. MACROSTR(WeakSignal)
  158. };
  159. static char * ChargePointStatusStr[] = {
  160. MACROSTR(Available),
  161. MACROSTR(Preparing),
  162. MACROSTR(Charging),
  163. MACROSTR(SuspendedEVSE),
  164. MACROSTR(SuspendedEV),
  165. MACROSTR(Finishing),
  166. MACROSTR(Reserved),
  167. MACROSTR(Unavailable),
  168. MACROSTR(Faulted)
  169. };
  170. static char *RegistrationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Pending),
  173. MACROSTR(Rejected)
  174. };
  175. static char *AvailabilityTypeStr[] = {
  176. MACROSTR(Inoperative),
  177. MACROSTR(Operative)
  178. };
  179. static char *AvailabilityStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected),
  182. MACROSTR(Scheduled)
  183. };
  184. static char *ConfigurationStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(RebootRequired),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearCacheStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Rejected)
  193. };
  194. static char *ChargingProfilePurposeTypeStr[] = {
  195. MACROSTR(ChargePointMaxProfile),
  196. MACROSTR(TxDefaultProfile),
  197. MACROSTR(TxProfile)
  198. };
  199. static char *ChargingProfileStatusStr[] = {
  200. MACROSTR(Accepted),
  201. MACROSTR(Rejected),
  202. MACROSTR(NotSupported)
  203. };
  204. static char *ClearChargingProfileStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Unknown)
  207. };
  208. static char *GetCompositeScheduleStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *UpdateTypeStr[] = {
  213. MACROSTR(Differential),
  214. MACROSTR(Full)
  215. };
  216. static char *UpdateStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Failed),
  219. MACROSTR(NotSupported),
  220. MACROSTR(VersionMismatch)
  221. };
  222. static char *RemoteStartStopStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char *ReservationStatusStr[] = {
  227. MACROSTR(Accepted),
  228. MACROSTR(Faulted),
  229. MACROSTR(Occupied),
  230. MACROSTR(Rejected),
  231. MACROSTR(Unavailable)
  232. };
  233. static char *ResetTypeStr[] = {
  234. MACROSTR(Hard),
  235. MACROSTR(Soft)
  236. };
  237. static char *ResetStatusStr[] = {
  238. MACROSTR(Accepted),
  239. MACROSTR(Rejected)
  240. };
  241. static char * DiagnosticsStatusStr[] = {
  242. MACROSTR(Idle),
  243. MACROSTR(Uploaded),
  244. MACROSTR(UploadFailed),
  245. MACROSTR(Uploading)
  246. };
  247. static char * FirmwareStatusStr[] = {
  248. MACROSTR(Downloaded),
  249. MACROSTR(DownloadFailed),
  250. MACROSTR(Downloading),
  251. MACROSTR(Idle),
  252. MACROSTR(InstallationFailed),
  253. MACROSTR(Installing),
  254. MACROSTR(Installed)
  255. };
  256. static char * MessageTriggerStr[] = {
  257. MACROSTR(BootNotification),
  258. MACROSTR(DiagnosticsStatusNotification),
  259. MACROSTR(FirmwareStatusNotification),
  260. MACROSTR(Heartbeat),
  261. MACROSTR(MeterValues),
  262. MACROSTR(StatusNotification)
  263. };
  264. static char * TriggerMessageStatusStr[] = {
  265. MACROSTR(Accepted),
  266. MACROSTR(Rejected),
  267. MACROSTR(NotImplemented)
  268. };
  269. static char * UnlockStatusStr[] = {
  270. MACROSTR(Unlocked),
  271. MACROSTR(UnlockFailed),
  272. MACROSTR(NotSupported)
  273. };
  274. #if 0
  275. static char * StopTransactionReasonStr[] = {
  276. MACROSTR(EmergencyStop),
  277. MACROSTR(EVDisconnected),
  278. MACROSTR(HardReset),
  279. MACROSTR(Local),
  280. MACROSTR(Other),
  281. MACROSTR(PowerLoss),
  282. MACROSTR(Reboot),
  283. MACROSTR(Remote),
  284. MACROSTR(SoftReset),
  285. MACROSTR(UnlockCommand),
  286. MACROSTR(DeAuthorized)
  287. };
  288. #endif
  289. static char * CancelReservationStatusStr[] = {
  290. MACROSTR(Accepted),
  291. MACROSTR(Rejected)
  292. };
  293. static char * ReadingContextStr[] = {
  294. MACROSTR(Interruption.Begin),
  295. MACROSTR(Interruption.End),
  296. MACROSTR(Other),
  297. MACROSTR(Sample.Clock),
  298. MACROSTR(Sample.Periodic),
  299. MACROSTR(Transaction.Begin),
  300. MACROSTR(Transaction.End),
  301. MACROSTR(Trigger)
  302. };
  303. static char * ValueFormatStr[] = {
  304. MACROSTR(Raw),
  305. MACROSTR(SignedData)
  306. };
  307. static char * MeasurandStr[] = {
  308. MACROSTR(Current.Export),
  309. MACROSTR(Current.Import),
  310. MACROSTR(Current.Offered),
  311. MACROSTR(Energy.Active.Export.Register),
  312. MACROSTR(Energy.Active.Import.Register),
  313. MACROSTR(Energy.Reactive.Export.Register),
  314. MACROSTR(Energy.Reactive.Import.Register),
  315. MACROSTR(Energy.Active.Export.Interval),
  316. MACROSTR(Energy.Active.Import.Interval),
  317. MACROSTR(Energy.Reactive.Export.Interval),
  318. MACROSTR(Energy.Reactive.Import.Interval),
  319. MACROSTR(Frequency),
  320. MACROSTR(Power.Active.Export),
  321. MACROSTR(Power.Active.Import),
  322. MACROSTR(Power.Factor),
  323. MACROSTR(Power.Offered),
  324. MACROSTR(Power.Reactive.ExportMACROSTR),
  325. MACROSTR(Power.Reactive.Import),
  326. MACROSTR(RPM),
  327. MACROSTR(SoC),
  328. MACROSTR(Temperature),
  329. MACROSTR(Voltage)
  330. };
  331. static char * LocationStr[] = {
  332. MACROSTR(Body),
  333. MACROSTR(Cable),
  334. MACROSTR(EV),
  335. MACROSTR(Inlet),
  336. MACROSTR(Outlet)
  337. };
  338. static char * PhaseStr[] = {
  339. MACROSTR(L1),
  340. MACROSTR(L2),
  341. MACROSTR(L3),
  342. MACROSTR(N),
  343. MACROSTR(L1-N),
  344. MACROSTR(L2-N),
  345. MACROSTR(L3-N),
  346. MACROSTR(L1-L2),
  347. MACROSTR(L2-L3),
  348. MACROSTR(L3-L1)
  349. };
  350. static char * UnitOfMeasureStr[] = {
  351. MACROSTR(Wh),
  352. MACROSTR(kWh),
  353. MACROSTR(varh),
  354. MACROSTR(kvarh),
  355. MACROSTR(W),
  356. MACROSTR(kW),
  357. MACROSTR(VA),
  358. MACROSTR(kVA),
  359. MACROSTR(var),
  360. MACROSTR(kvar),
  361. MACROSTR(A),
  362. MACROSTR(V),
  363. MACROSTR(Celsius),
  364. MACROSTR(Fahrenheit),
  365. MACROSTR(K),
  366. MACROSTR(Percent)
  367. };
  368. //=========================================
  369. // Meter buffer process
  370. //=========================================
  371. int meterValueBufferDataQuantity(uint8_t gun_index, ReadingContext dataType)
  372. {
  373. uint32_t result = 0;
  374. char sqlCmd[8192];
  375. char zErrMsg[200];
  376. int rows, cols;
  377. char **resultData;
  378. sprintf(sqlCmd, "select count(idx) as dataQuantity from meterValuesBuffer where gun_index='%d' and ReadingContext='%d' order by ReadingContext, idx", gun_index, (dataType==ReadingContext_Sample_Periodic?0:1));
  379. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  380. {
  381. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  382. }
  383. else
  384. {
  385. if(rows >= 1)
  386. {
  387. result = atoi(resultData[1]);
  388. }
  389. }
  390. return result;
  391. }
  392. int meterValueBufferClear(uint8_t gun_index)
  393. {
  394. int result = PASS;
  395. char sqlCmd[512];
  396. char *errMsg = 0;
  397. sprintf(sqlCmd, "delete from meterValuesBuffer where gun_index=%d", gun_index);
  398. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  399. {
  400. DEBUG_INFO("SQL error: %s\n",errMsg);
  401. result = FAIL;
  402. }
  403. return result;
  404. }
  405. int meterValueBufferInsert(uint8_t gun_index, ReadingContext dataType, uint32_t transactionId, char *meterValue)
  406. {
  407. int result = PASS;
  408. char sqlCmd[8192];
  409. char *errMsg = 0;
  410. sprintf(sqlCmd, "insert into meterValuesBuffer(occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values(CURRENT_TIMESTAMP, '%d', '%d','%d','%s')", gun_index
  411. , transactionId
  412. , (dataType==ReadingContext_Sample_Periodic?0:1)
  413. , meterValue);
  414. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  415. {
  416. result = FAIL;
  417. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  418. }
  419. return result;
  420. }
  421. int meterValueBufferQuery(uint8_t gun_index, json_object *MeterValues)
  422. {
  423. int result = PASS;
  424. char sqlCmd[8192];
  425. char zErrMsg[200];
  426. int rows, cols;
  427. char **resultData;
  428. sprintf(sqlCmd, "select * from meterValuesBuffer where gun_index='%d' order by ReadingContext, idx", gun_index);
  429. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  430. {
  431. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  432. result = FAIL;
  433. }
  434. else
  435. {
  436. for(uint32_t idxRow=1;idxRow<rows;idxRow++)
  437. {
  438. json_object *MeterValue = json_tokener_parse(resultData[(idxRow*cols)+5]);
  439. json_object_array_add(MeterValues, MeterValue);
  440. }
  441. }
  442. return result;
  443. }
  444. //=========================================
  445. // Certificate related routine
  446. //=========================================
  447. int certVerify(char *privateKey, char *cert)
  448. {
  449. int result = PASS;
  450. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  451. // Load certificate file
  452. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  453. {
  454. DEBUG_ERROR("Load certificate error!\n");
  455. result = FAIL;
  456. }
  457. // Load private key file
  458. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  459. {
  460. DEBUG_ERROR("Load private key error!\n");
  461. result = FAIL;
  462. }
  463. if(!SSL_CTX_check_private_key(ctx))
  464. {
  465. result = FAIL;
  466. }
  467. SSL_CTX_free(ctx);
  468. return result;
  469. }
  470. //=========================================
  471. // TTIA routine
  472. //=========================================
  473. int sendTTIAInfo(uint8_t gun_index)
  474. {
  475. static int sn = 0;
  476. int result = FAIL;
  477. struct hostent *server;
  478. int udp_socket_fd;
  479. struct sockaddr_in dest_addr = {0};
  480. uint8_t tx_buf[80] = {0};
  481. uint8_t logBuf[256]= {0};
  482. uint8_t tx_len, tempIndex, socStart, socEnd;
  483. uint16_t PresentChargedEnergy;
  484. struct tm tmStart, tmEnd;
  485. DEBUG_INFO("sendTTIAInfo...\n");
  486. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  487. {
  488. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  489. {
  490. tempIndex = ((gun_index==2) ? 1: 0);
  491. }
  492. else
  493. {
  494. tempIndex = gun_index;
  495. }
  496. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  497. {
  498. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  499. {
  500. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  501. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  502. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  503. }
  504. }
  505. }
  506. else if(gunType[gun_index] == GUN_TYPE_CCS)
  507. {
  508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  509. {
  510. tempIndex = ((gun_index==2) ? 1: 0);
  511. }
  512. else
  513. {
  514. tempIndex = gun_index;
  515. }
  516. for (int index = 0; index < CCS_QUANTITY; index++)
  517. {
  518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  519. {
  520. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  521. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  522. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  523. }
  524. }
  525. }
  526. else if(gunType[gun_index] == GUN_TYPE_GBT)
  527. {
  528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  529. {
  530. tempIndex = ((gun_index==2) ? 1: 0);
  531. }
  532. else
  533. {
  534. tempIndex = gun_index;
  535. }
  536. for (int index = 0; index < GB_QUANTITY; index++)
  537. {
  538. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  539. {
  540. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  541. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  542. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  543. }
  544. }
  545. }
  546. else if(gunType[gun_index] == GUN_TYPE_DO)
  547. {
  548. tempIndex = gun_index;
  549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  550. {
  551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  552. {
  553. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  554. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  555. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  556. }
  557. }
  558. }
  559. else
  560. {
  561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  562. {
  563. tempIndex = 2;
  564. }
  565. else
  566. {
  567. tempIndex = gun_index;
  568. }
  569. for (int index = 0; index < AC_QUANTITY; index++)
  570. {
  571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  572. {
  573. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  574. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  575. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  576. }
  577. }// END
  578. }
  579. // Message assembly
  580. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  581. tx_buf[4] = 0x02; // Protocol Version
  582. tx_buf[5] = 0xb0; // Message ID
  583. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  584. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  585. tx_buf[8] = 0x00; // CarID low byte
  586. tx_buf[9] = 0x00; // CarID high byte
  587. tx_buf[10] = 0x00; // ID Storage
  588. tx_buf[11] = 0x00; // Driver lowest byte
  589. tx_buf[12] = 0x00; // Driver 2nd byte
  590. tx_buf[13] = 0x00; // Driver 3rd byte
  591. tx_buf[14] = 0x00; // Driver highest byte
  592. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  593. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  594. tx_buf[17] = 0x00; // Reserve
  595. tx_buf[18] = 60 & 0xff; // Payload length low byte
  596. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  597. // EVSE provider
  598. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  599. // EVSE provider
  600. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  601. // EVSE id
  602. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  603. // Connector id
  604. tx_buf[37] = gun_index;
  605. // EVSE station
  606. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  607. // Vehicle SN
  608. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  609. // Mileage
  610. tx_buf[61] = 0x00; // lowest byte
  611. tx_buf[62] = 0x00; // 2nd byte
  612. tx_buf[63] = 0x00; // highest byte
  613. // Start date time 6 bytes
  614. 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))
  615. {
  616. struct tm *tmTarget;
  617. struct timeb tbTarget;
  618. tmStart.tm_year -= 1900;
  619. tmStart.tm_mon -= 1;
  620. tmStart.tm_gmtoff = 0;
  621. tbTarget.time = mktime(&tmStart);
  622. tbTarget.timezone = 0;
  623. tbTarget.time += (8*3600);
  624. tmTarget = gmtime(&tbTarget.time);
  625. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  626. tx_buf[65] = (tmTarget->tm_mon+1);
  627. tx_buf[66] = tmTarget->tm_mday;
  628. tx_buf[67] = tmTarget->tm_hour;
  629. tx_buf[68] = tmTarget->tm_min;
  630. tx_buf[69] = tmTarget->tm_sec;
  631. }
  632. // Stop date time 6 bytes
  633. 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))
  634. {
  635. struct tm *tmTarget;
  636. struct timeb tbTarget;
  637. tmEnd.tm_year -= 1900;
  638. tmEnd.tm_mon -= 1;
  639. tmEnd.tm_gmtoff = 0;
  640. tbTarget.time = mktime(&tmEnd);
  641. tbTarget.timezone = 0;
  642. tbTarget.time += (8*3600);
  643. tmTarget = gmtime(&tbTarget.time);
  644. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  645. tx_buf[71] = (tmTarget->tm_mon+1);
  646. tx_buf[72] = tmTarget->tm_mday;
  647. tx_buf[73] = tmTarget->tm_hour;
  648. tx_buf[74] = tmTarget->tm_min;
  649. tx_buf[75] = tmTarget->tm_sec;
  650. }
  651. // Session energy 2 bytes
  652. tx_buf[76] = PresentChargedEnergy & 0xff;
  653. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  654. // Start SOC 1 byte
  655. tx_buf[78] = socStart;
  656. // Stop SOC 1 byte
  657. tx_buf[79] = socEnd;
  658. // Open socket
  659. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  660. if(udp_socket_fd == -1)
  661. {
  662. DEBUG_ERROR("UDP socket create failed!\n");
  663. }
  664. else
  665. {
  666. // Get server DNS entry
  667. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  668. if (server == NULL)
  669. {
  670. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  671. }
  672. else
  673. {
  674. // Build the server's Internet address
  675. bzero((char *) &dest_addr, sizeof(dest_addr));
  676. dest_addr.sin_family = AF_INET;
  677. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  678. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  679. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  680. {
  681. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  682. {
  683. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  684. }
  685. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  686. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  687. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  688. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  689. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  690. DEBUG_TTIA_INFO("---------- Header ----------\n");
  691. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  692. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  693. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  694. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  695. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  696. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  697. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  698. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  699. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  700. DEBUG_TTIA_INFO("Len: 0x3C\n");
  701. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  702. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  703. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  704. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  705. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  706. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  707. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  708. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  709. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  710. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  711. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  712. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  713. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  714. DEBUG_TTIA_INFO("=========================================\n");
  715. sn++;
  716. result = PASS;
  717. }
  718. else
  719. {
  720. DEBUG_ERROR("UDP sent out fail.\n");
  721. }
  722. }
  723. }
  724. return result;
  725. }
  726. //=========================================
  727. // Save configuration
  728. //=========================================
  729. int runShellCmd(const char*cmd)
  730. {
  731. int result = FAIL;
  732. char buf[256];
  733. FILE *fp;
  734. fp = popen(cmd, "r");
  735. if(fp != NULL)
  736. {
  737. while(fgets(buf, sizeof(buf), fp) != NULL)
  738. {
  739. DEBUG_INFO("%s\n", buf);
  740. }
  741. result = PASS;
  742. }
  743. pclose(fp);
  744. return result;
  745. }
  746. int StoreUsrConfigData(struct SysConfigData *UsrData)
  747. {
  748. int result = PASS;
  749. int fd,wrd;
  750. unsigned int i,Chk;
  751. unsigned char *ptr, *BufTmp;
  752. int MtdBlockSize = 0x300000;
  753. Chk=0;
  754. ptr=(unsigned char *)UsrData;
  755. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  756. {
  757. memset(BufTmp,0,MtdBlockSize);
  758. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  759. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  760. Chk+=*(BufTmp+i);
  761. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  762. // Output configuration to file.
  763. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  764. if (fd < 0)
  765. {
  766. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  767. free(BufTmp);
  768. return 0;
  769. }
  770. wrd=write(fd, BufTmp, MtdBlockSize);
  771. close(fd);
  772. if(wrd<MtdBlockSize)
  773. {
  774. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  775. free(BufTmp);
  776. return 0;
  777. }
  778. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  779. DEBUG_INFO("Erase /dev/mtd10.\n");
  780. runShellCmd("flash_erase /dev/mtd10 0 0");
  781. DEBUG_INFO("Write /dev/mtd10.\n");
  782. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  783. DEBUG_INFO("Erase /dev/mtd11.\n");
  784. runShellCmd("flash_erase /dev/mtd11 0 0");
  785. DEBUG_INFO("Write /dev/mtd11.\n");
  786. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  787. system("rm -f /mnt/EvseConfig.bin");
  788. DEBUG_INFO("EvseConfig write to flash OK\n");
  789. }
  790. else
  791. {
  792. DEBUG_ERROR("alloc BlockSize NG\r\n");
  793. result = FAIL;
  794. }
  795. if(BufTmp!=NULL)
  796. free(BufTmp);
  797. return result;
  798. }
  799. //=========================================
  800. // Sqlite3 related function
  801. //=========================================
  802. static int selectSqlCount = 0;
  803. static int callback(void *data, int argc, char **argv, char **azColName){
  804. int i;
  805. //printf("%s: ", (const char*)data);
  806. selectSqlCount = argc;
  807. for(i = 0; i<argc; i++){
  808. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  809. }
  810. //printf("\n");
  811. return 0;
  812. }
  813. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  814. //int i;
  815. //printf("%s:\n", (const char*)data);
  816. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  817. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  818. return 0;
  819. }
  820. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  821. //printf("%s:\n", (const char*)data);
  822. //idTag
  823. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  824. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  825. //parentIdTag
  826. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  827. //expir_date
  828. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  829. //status
  830. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  831. //version
  832. if(columenCount > 5)
  833. idTagQuery.listVersionInt = atoi(columnValue[5]);
  834. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  835. return 0;
  836. }
  837. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  838. {
  839. // localversion = argv[5] ? atoi(argv[5]) : 0;
  840. // printf("localversion=%d\n", localversion);
  841. return 0;
  842. }
  843. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  844. {
  845. for (int i = 0; i < n_columns; i++)
  846. {
  847. DEBUG_INFO("%s\t", col_values[i]);
  848. }
  849. DEBUG_INFO("\n");
  850. return 0;
  851. }
  852. int OCPP_cleanLocalCache()
  853. {
  854. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  855. char *errMsg = 0;
  856. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  857. if (SQLITE_OK != rc)
  858. {
  859. DEBUG_INFO("SQL error: %s\n",errMsg);
  860. return FALSE;
  861. }
  862. return TRUE;
  863. }
  864. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  865. {
  866. int isSuccess = TRUE;
  867. int ret = 0;
  868. //const char* data = "Callback function called";
  869. char sql[300];
  870. char zErrMsg[200];
  871. memset(sql, 0, 300);
  872. memset(zErrMsg, 0, 200);
  873. 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);
  874. //* Execute SQL statement */
  875. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  876. if( ret != SQLITE_OK )
  877. {
  878. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  879. isSuccess = FALSE;
  880. }
  881. return isSuccess;
  882. }
  883. void OCPP_getIdTagFromLocalCache(char idTag[])
  884. {
  885. int rc = 0;
  886. char sql[100];
  887. char zErrMsg[100];
  888. memset(sql, 0, 100);
  889. memset(zErrMsg, 0, 100);
  890. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  891. memset(&idTagQuery, 0, sizeof(idTagQuery));
  892. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  893. /* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. void OCPP_getListVerion()
  901. {
  902. int rc = 0;
  903. // const char* data = "Callback function called";
  904. char sql[100];
  905. char zErrMsg[100];
  906. memset(sql, 0, 100);
  907. memset(zErrMsg, 0, 100);
  908. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  909. /* Execute SQL statement */
  910. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  911. if( rc != SQLITE_OK )
  912. {
  913. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  914. }
  915. }
  916. void OCPP_get_TableAuthlocalAllData(void)
  917. {
  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,"select * from ocpp_auth_local ");
  924. /* Execute SQL statement */
  925. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  926. if( rc != SQLITE_OK )
  927. {
  928. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  929. }
  930. //return ver;
  931. }
  932. int OCPP_cleanLocalList()
  933. {
  934. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  935. char *errMsg = 0;
  936. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  937. if (SQLITE_OK != rc)
  938. {
  939. DEBUG_INFO("%s\n",errMsg);
  940. return FALSE;
  941. }
  942. return TRUE;
  943. }
  944. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  945. {
  946. int isSuccess = FALSE;
  947. int ret = 0;
  948. //const char* data = "Callback function called";
  949. char sql[300];
  950. char zErrMsg[200];
  951. memset(sql, 0, 300);
  952. memset(zErrMsg, 0, 200);
  953. 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);
  954. //* Execute SQL statement */
  955. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  956. if( ret != SQLITE_OK )
  957. {
  958. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  959. return isSuccess;
  960. }
  961. memset(sql, 0, 300);
  962. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  963. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  964. if( ret != SQLITE_OK )
  965. {
  966. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  967. return isSuccess;
  968. }
  969. isSuccess = TRUE;
  970. return isSuccess;
  971. }
  972. void OCPP_getIdTagFromLocalList(char idTag[])
  973. {
  974. int rc = 0;
  975. // const char* data = "Callback function called";
  976. char sql[100];
  977. char zErrMsg[100];
  978. memset(sql, 0, 100);
  979. memset(zErrMsg, 0, 100);
  980. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  981. memset(&idTagQuery, 0, sizeof(idTagQuery));
  982. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  983. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  984. /* Execute SQL statement */
  985. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  986. if( rc != SQLITE_OK )
  987. {
  988. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  989. }
  990. //return ver;
  991. }
  992. void OCPP_deleteIdTagFromLocalList(char idTag[])
  993. {
  994. //int ver = 0;
  995. //int isSuccess = FALSE;
  996. int rc = 0;
  997. char sql[100];
  998. char zErrMsg[100];
  999. memset(sql, 0, 100);
  1000. memset(zErrMsg, 0, 100);
  1001. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  1002. //* Execute SQL statement */
  1003. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  1004. if( rc != SQLITE_OK )
  1005. {
  1006. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1007. }
  1008. }
  1009. int getCurrentYear()
  1010. {
  1011. int result = 0;
  1012. time_t CurrentTime;
  1013. struct tm *tm;
  1014. CurrentTime = time(NULL);
  1015. tm=localtime(&CurrentTime);
  1016. result = (tm->tm_year + 1900);
  1017. return result;
  1018. }
  1019. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  1020. {
  1021. int result = PASS;
  1022. char* errMsg = NULL;
  1023. char sqlStr[WEBSOCKET_BUFFER_SIZE];
  1024. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  1025. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1026. {
  1027. result = FAIL;
  1028. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  1029. }
  1030. 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));
  1031. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1032. {
  1033. result = FAIL;
  1034. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  1035. }
  1036. return result;
  1037. }
  1038. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  1039. {
  1040. int isSuccess = TRUE;
  1041. int tempIndex;
  1042. json_object *EnergyDataTransfer = json_object_new_object();
  1043. json_object *periodEnergys = json_object_new_object();
  1044. char sql[1024];
  1045. char zErrMsg[200];
  1046. memset(sql, 0, ARRAY_SIZE(sql));
  1047. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  1048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  1049. {
  1050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1051. {
  1052. tempIndex = ((gun_index==2) ? 1: 0);
  1053. }
  1054. else
  1055. {
  1056. tempIndex = gun_index;
  1057. }
  1058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1059. {
  1060. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1061. {
  1062. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1063. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1064. {
  1065. uint8_t period[3];
  1066. sprintf((char*)period, "%d", idxPeriod);
  1067. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1068. }
  1069. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1070. } //end of the same index
  1071. }//end of for CHAdeMO_QUANTITY
  1072. }
  1073. else if(gunType[gun_index] == GUN_TYPE_CCS)
  1074. {
  1075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1076. {
  1077. tempIndex = ((gun_index==2) ? 1: 0);
  1078. }
  1079. else
  1080. {
  1081. tempIndex = gun_index;
  1082. }
  1083. for (int index = 0; index < CCS_QUANTITY; index++)
  1084. {
  1085. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1086. {
  1087. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1088. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1089. {
  1090. uint8_t period[3];
  1091. sprintf((char*)period, "%d", idxPeriod);
  1092. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1093. }
  1094. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1095. } //end of the same index
  1096. } // end of for CCS_QUANTITY
  1097. }
  1098. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1099. {
  1100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1101. {
  1102. tempIndex = ((gun_index==2) ? 1: 0);
  1103. }
  1104. else
  1105. {
  1106. tempIndex = gun_index;
  1107. }
  1108. for (int index = 0; index < GB_QUANTITY; index++)
  1109. {
  1110. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1111. {
  1112. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1113. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1114. {
  1115. uint8_t period[3];
  1116. sprintf((char*)period, "%d", idxPeriod);
  1117. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1118. }
  1119. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1120. } //end of the same index
  1121. } // end of for GB_QUANTITY
  1122. }
  1123. else if(gunType[gun_index] == GUN_TYPE_DO)
  1124. {
  1125. tempIndex = gun_index;
  1126. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1127. {
  1128. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1129. {
  1130. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1131. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1132. {
  1133. uint8_t period[3];
  1134. sprintf((char*)period, "%d", idxPeriod);
  1135. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1136. }
  1137. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1138. } //end of the same index
  1139. }
  1140. }
  1141. else
  1142. {
  1143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1144. {
  1145. tempIndex = 2;
  1146. }
  1147. else
  1148. {
  1149. tempIndex = gun_index;
  1150. }
  1151. for (int index = 0; index < AC_QUANTITY; index++)
  1152. {
  1153. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1154. {
  1155. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1156. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1157. {
  1158. uint8_t period[3];
  1159. sprintf((char*)period, "%d", idxPeriod);
  1160. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1161. }
  1162. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1163. }//end of the same index
  1164. }//end of for AC_QUANTITY
  1165. }
  1166. 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));
  1167. json_object_put(EnergyDataTransfer);
  1168. //* Execute SQL statement */
  1169. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1170. {
  1171. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1172. isSuccess = FALSE;
  1173. }
  1174. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1175. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1176. {
  1177. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1178. isSuccess = FALSE;
  1179. }
  1180. return isSuccess;
  1181. }
  1182. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1183. {
  1184. int isSuccess = TRUE;
  1185. char sql[512];
  1186. char zErrMsg[200];
  1187. int rows, cols;
  1188. char **resultData;
  1189. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1190. /* Execute SQL statement */
  1191. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1192. {
  1193. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1194. isSuccess = FALSE;
  1195. }
  1196. else
  1197. {
  1198. if((rows > 0) && (atoi(resultData[4]) > 0))
  1199. {
  1200. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1201. }
  1202. else
  1203. {
  1204. DEBUG_WARN("There is not match transaction data.\n");
  1205. isSuccess = FALSE;
  1206. }
  1207. }
  1208. return isSuccess;
  1209. }
  1210. 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)
  1211. {
  1212. int result = PASS;
  1213. char* errMsg = NULL;
  1214. char sqlStr[8192];
  1215. 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');",
  1216. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1217. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1218. {
  1219. result = FAIL;
  1220. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1221. }
  1222. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1223. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1224. {
  1225. result = FAIL;
  1226. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1227. }
  1228. return result;
  1229. }
  1230. int OCPP_update_deduct_info(int txId, char *creditNo)
  1231. {
  1232. int result = PASS;
  1233. char* errMsg = NULL;
  1234. char sqlStr[8192];
  1235. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1236. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1237. {
  1238. result = FAIL;
  1239. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1240. }
  1241. return result;
  1242. }
  1243. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1244. {
  1245. json_object *dataBuf = json_object_new_object();
  1246. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1247. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1248. json_object_object_add(dataBuf, "txId", json_object_new_int(atoi(columnValue[1])));
  1249. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1250. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1251. json_object_object_add(dataBuf, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1252. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[5])));
  1253. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[9]));
  1254. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1255. json_object_put(dataBuf);
  1256. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1257. return 0;
  1258. }
  1259. void OCPP_query_deduct_info()
  1260. {
  1261. int rc = 0;
  1262. char sql[100];
  1263. char zErrMsg[100];
  1264. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1265. /* Execute SQL statement */
  1266. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1267. if( rc != SQLITE_OK )
  1268. {
  1269. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1270. }
  1271. }
  1272. // Occupancy fee deduct queue process
  1273. int OCPP_insert_occupancyDeduct_info(char *occupancySN, char *creditNo, uint8_t deductResult, double amount, char *approvalNo)
  1274. {
  1275. int result = PASS;
  1276. char* errMsg = NULL;
  1277. char sqlStr[8192];
  1278. sprintf(sqlStr, "insert or replace into report_occupancyDeduct_info(occupancySN, creditNo, deductResult, amount, approvalNo, isUploaded) values('%s', '%s', '%d', '%.2f', '%s', '0');",
  1279. occupancySN, creditNo, deductResult, amount, approvalNo);
  1280. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1281. {
  1282. result = FAIL;
  1283. DEBUG_WARN( "Insert local report_occupancyDeduct_info error message: %s\n", errMsg);
  1284. }
  1285. sprintf(sqlStr, "delete from report_occupancyDeduct_info where (idx < (select idx from report_occupancyDeduct_info order by idx desc limit 1)-5000);");
  1286. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1287. {
  1288. result = FAIL;
  1289. DEBUG_WARN( "delete local report_occupancyDeduct_info error message: %s\n", errMsg);
  1290. }
  1291. return result;
  1292. }
  1293. int OCPP_update_occupancyDeduct_info(char *occupancySN)
  1294. {
  1295. int result = PASS;
  1296. char* errMsg = NULL;
  1297. char sqlStr[8192];
  1298. sprintf(sqlStr, "update report_occupancyDeduct_info set isUploaded='1' where occupancySN='%s';", occupancySN);
  1299. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1300. {
  1301. result = FAIL;
  1302. DEBUG_WARN( "Update local report_occupancyDeduct_info error message: %s\n", errMsg);
  1303. }
  1304. return result;
  1305. }
  1306. int queryOccupancyDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1307. {
  1308. json_object *dataBuf = json_object_new_object();
  1309. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1310. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_OccupancyDeductResult");
  1311. json_object_object_add(dataBuf, "occupancySN", json_object_new_string(columnValue[1]));
  1312. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1313. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1314. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[4])));
  1315. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[5]));
  1316. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1317. json_object_put(dataBuf);
  1318. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1319. return 0;
  1320. }
  1321. void OCPP_query_occupancyDeduct_info()
  1322. {
  1323. int rc = 0;
  1324. char sql[100];
  1325. char zErrMsg[100];
  1326. sprintf(sql,"select * from report_occupancyDeduct_info where isUploaded='0' order by idx limit 1");
  1327. /* Execute SQL statement */
  1328. rc = sqlite3_exec(db, sql, queryOccupancyDeductCallBack, 0, (char **)&zErrMsg);
  1329. if( rc != SQLITE_OK )
  1330. {
  1331. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1332. }
  1333. }
  1334. void reportReaderStatus(int gun_index)
  1335. {
  1336. struct timeval tmnow;
  1337. struct tm *tm;
  1338. char buf[28];//, usec_buf[6];
  1339. gettimeofday(&tmnow, NULL);
  1340. time_t t;
  1341. t = time(NULL);
  1342. /*UTC time and date*/
  1343. tm = gmtime(&t);
  1344. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1345. #if 0 // remove temporally
  1346. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1347. strcat(buf,".");
  1348. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1349. strcat(buf,usec_buf);
  1350. #endif
  1351. json_object *dataBuf = json_object_new_object();
  1352. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1353. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1354. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1355. json_object_object_add(dataBuf, "readerStatus", json_object_new_int(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus));
  1356. json_object_object_add(dataBuf, "timestamp", json_object_new_string(buf));
  1357. json_object_object_add(dataBuf, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  1358. json_object_object_add(dataBuf, "creditNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
  1359. json_object_object_add(dataBuf, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  1360. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1361. json_object_put(dataBuf);
  1362. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1363. }
  1364. void getOccupancyFee(int gun_index)
  1365. {
  1366. struct timeval tmnow;
  1367. struct tm *tm;
  1368. char buf[28];//, usec_buf[6];
  1369. gettimeofday(&tmnow, NULL);
  1370. time_t t;
  1371. t = time(NULL);
  1372. /*UTC time and date*/
  1373. tm = gmtime(&t);
  1374. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1375. #if 0 // remove temporally
  1376. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1377. strcat(buf,".");
  1378. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1379. strcat(buf,usec_buf);
  1380. #endif
  1381. json_object *dataBuf = json_object_new_object();
  1382. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1383. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_GetOccupancyFee");
  1384. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1385. json_object_object_add(dataBuf, "occupancySN", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[gun_index].occupancySN));
  1386. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1387. json_object_put(dataBuf);
  1388. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1389. }
  1390. //==========================================
  1391. // Check time passed since today
  1392. //==========================================
  1393. long long DiffTimebWithNow(struct timeb ST)
  1394. {
  1395. //return milli-second
  1396. struct timeb ET;
  1397. long long StartTime,StopTime;
  1398. ftime(&ET);
  1399. StartTime=(long long)ST.time;
  1400. StopTime=(long long)ET.time;
  1401. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1402. }
  1403. int getTimePassSinceToday(uint8_t gun_index)
  1404. {
  1405. int result = -1;
  1406. static time_t lastTime[4];
  1407. time_t t;
  1408. struct tm *tmStartToday;
  1409. struct timeb tbStartToday;
  1410. t=time(NULL);
  1411. if(difftime(t, lastTime[gun_index])>0)
  1412. {
  1413. tmStartToday=localtime(&t);
  1414. tmStartToday->tm_hour = 0;
  1415. tmStartToday->tm_min = 0;
  1416. tmStartToday->tm_sec = 0;
  1417. tbStartToday.time = mktime(tmStartToday);
  1418. tbStartToday.millitm = 0;
  1419. result = DiffTimebWithNow(tbStartToday)/1000;
  1420. lastTime[gun_index] = t;
  1421. }
  1422. return result;
  1423. }
  1424. void getNowDatetime(uint8_t *data)
  1425. {
  1426. time_t t = time(NULL);
  1427. struct tm tm = *localtime(&t);
  1428. 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);
  1429. }
  1430. int syncDateTimeRTC(uint8_t *data)
  1431. {
  1432. struct ParsingResult
  1433. {
  1434. int result;
  1435. int scanedElement;
  1436. int year;
  1437. int month;
  1438. int mday;
  1439. int hour;
  1440. int min;
  1441. int sec;
  1442. int tz_hour;
  1443. int tz_min;
  1444. float minSec;
  1445. }result;
  1446. struct tm tmOrg;
  1447. struct tm *tmTarget;
  1448. struct timeb tbTarget;
  1449. char buf[128];
  1450. memset(&result, 0x00, sizeof(struct ParsingResult));
  1451. result.result = PASS;
  1452. if(strstr((char*)data, ".") != NULL)
  1453. {
  1454. // Original data with mini second
  1455. if(strstr((char*)data, "Z") != NULL)
  1456. {
  1457. // Original data with Z
  1458. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1459. &result.year,
  1460. &result.month,
  1461. &result.mday,
  1462. &result.hour,
  1463. &result.min,
  1464. &result.sec,
  1465. &result.minSec);
  1466. }
  1467. else
  1468. {
  1469. // Original data without Z
  1470. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1471. &result.year,
  1472. &result.month,
  1473. &result.mday,
  1474. &result.hour,
  1475. &result.min,
  1476. &result.sec,
  1477. &result.minSec,
  1478. &result.tz_hour,
  1479. &result.tz_min);
  1480. }
  1481. }
  1482. else
  1483. {
  1484. // Original data without mini second
  1485. if(strstr((char*)data, "Z") != NULL)
  1486. {
  1487. // Original data with Z
  1488. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1489. &result.year,
  1490. &result.month,
  1491. &result.mday,
  1492. &result.hour,
  1493. &result.min,
  1494. &result.sec);
  1495. }
  1496. else
  1497. {
  1498. // Original data without Z
  1499. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1500. &result.year,
  1501. &result.month,
  1502. &result.mday,
  1503. &result.hour,
  1504. &result.min,
  1505. &result.sec,
  1506. &result.tz_hour,
  1507. &result.tz_min);
  1508. }
  1509. }
  1510. tmOrg.tm_year = result.year - 1900;
  1511. tmOrg.tm_mon = result.month - 1;
  1512. tmOrg.tm_mday = result.mday;
  1513. tmOrg.tm_hour = result.hour;
  1514. tmOrg.tm_min = result.min;
  1515. tmOrg.tm_sec = result.sec;
  1516. tmOrg.tm_gmtoff = 0;
  1517. tbTarget.time = mktime(&tmOrg);
  1518. tbTarget.timezone = 0;
  1519. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1520. tmTarget = gmtime(&tbTarget.time);
  1521. 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);
  1522. //DEBUG_INFO(" org date time: %s\n", data);
  1523. //DEBUG_INFO("parse date time: %s\n", buf);
  1524. system(buf);
  1525. system("/sbin/hwclock -w --systohc");
  1526. if(result.scanedElement < 6)
  1527. result.result = FAIL;
  1528. return result.result;
  1529. }
  1530. //==========================================
  1531. // Parse certificate content
  1532. //==========================================
  1533. int parseCertInfo(char *certPath, int parseType, char *data)
  1534. {
  1535. int result = FAIL;
  1536. memset(data, 0, ARRAY_SIZE(data));
  1537. if(access(certPath,F_OK) != -1)
  1538. {
  1539. char temp[512] = {0};
  1540. char capturedData[256] = {0};
  1541. char hashType[10] = "SHA256";
  1542. FILE *fp;
  1543. // Need to get hash type first
  1544. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1545. fp = popen(temp, "r");
  1546. if(fp)
  1547. {
  1548. while(fgets(temp, sizeof(temp), fp) != NULL)
  1549. {
  1550. if(strstr(temp, "Signature Algorithm:") != NULL)
  1551. {
  1552. result = PASS;
  1553. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1554. sprintf((char*)hashType, "SHA256");
  1555. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1556. sprintf((char*)hashType, "SHA384");
  1557. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1558. sprintf((char*)hashType, "SHA512");
  1559. else
  1560. {
  1561. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1562. result = FAIL;
  1563. }
  1564. break;
  1565. }
  1566. }
  1567. }
  1568. switch(parseType)
  1569. {
  1570. case CERT_PARSE_HashAlgorithm:
  1571. sprintf((char*)data, hashType);
  1572. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1573. break;
  1574. case CERT_PARSE_SerialNumber:
  1575. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1576. fp = popen(temp, "r");
  1577. if(fp)
  1578. {
  1579. while(fgets(temp, sizeof(temp), fp) != NULL)
  1580. {
  1581. if(strstr(temp, "serial=") != NULL)
  1582. {
  1583. sscanf(temp, "%*[^=]=%s", capturedData);
  1584. result = PASS;
  1585. break;
  1586. }
  1587. }
  1588. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1589. sprintf((char*)data, capturedData);
  1590. }
  1591. break;
  1592. case CERT_PARSE_IssuerNameHash:
  1593. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", certPath, (char*)hashType);
  1594. fp = popen(temp, "r");
  1595. if(fp)
  1596. {
  1597. while(fgets(temp, sizeof(temp), fp) != NULL)
  1598. {
  1599. if(strstr(temp, "(stdin)=") != NULL)
  1600. {
  1601. sscanf(temp, "%*[^=]=%s", capturedData);
  1602. result = PASS;
  1603. break;
  1604. }
  1605. }
  1606. stringtrimspace(capturedData);
  1607. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1608. sprintf((char*)data, capturedData);
  1609. }
  1610. break;
  1611. case CERT_PARSE_IssuerKeyHash:
  1612. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", certPath, (char*)hashType);
  1613. fp = popen(temp, "r");
  1614. if(fp)
  1615. {
  1616. while(fgets(temp, sizeof(temp), fp) != NULL)
  1617. {
  1618. if(strstr(temp, "(stdin)=") != NULL)
  1619. {
  1620. sscanf(temp, "%*[^=]=%s", capturedData);
  1621. result = PASS;
  1622. break;
  1623. }
  1624. }
  1625. stringtrimspace(capturedData);
  1626. DEBUG_INFO("issuerKeyHash: %s\n", capturedData);
  1627. sprintf((char*)data, capturedData);
  1628. }
  1629. break;
  1630. case CERT_PARSE_OcspUrl:
  1631. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1632. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1633. fp = popen(temp, "r");
  1634. if(fp)
  1635. {
  1636. while(fgets(temp, sizeof(temp), fp) != NULL)
  1637. {
  1638. if(strstr(temp, "OCSP - URI:") != NULL)
  1639. {
  1640. //strcpy((char*)data, temp);
  1641. sscanf(temp, "%*[^:]:%s", capturedData);
  1642. sprintf((char*)data, capturedData);
  1643. DEBUG_INFO("OCSP_URI: %s\n", data);
  1644. result = PASS;
  1645. break;
  1646. }
  1647. }
  1648. }
  1649. break;
  1650. default:
  1651. DEBUG_INFO("Parse type is invalid.\n");
  1652. break;
  1653. }
  1654. pclose(fp);
  1655. }
  1656. return result;
  1657. }
  1658. //==========================================
  1659. // GetCompositeSchedule logic related function
  1660. //==========================================
  1661. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1662. {
  1663. //return milli-second
  1664. unsigned int StartTime,StopTime;
  1665. StartTime=(unsigned int)ST.time;
  1666. StopTime=(unsigned int)ET.time;
  1667. return (StopTime-StartTime);
  1668. }
  1669. int DiffTimebWithNowSec(struct timeb ST)
  1670. {
  1671. //return milli-second
  1672. struct timeb ET;
  1673. unsigned int StartTime,StopTime;
  1674. ftime(&ET);
  1675. StartTime=(unsigned int)ST.time;
  1676. StopTime=(unsigned int)ET.time;
  1677. return (StopTime-StartTime);
  1678. }
  1679. int getStartStop(uint8_t *start, uint8_t *stop)
  1680. {
  1681. struct ParsingResult
  1682. {
  1683. int result;
  1684. int scanedElement;
  1685. int year;
  1686. int month;
  1687. int mday;
  1688. int hour;
  1689. int min;
  1690. int sec;
  1691. int tz_hour;
  1692. int tz_min;
  1693. float minSec;
  1694. };
  1695. struct ParsingResult parseStart;
  1696. struct ParsingResult parseStop;
  1697. int result = -1;
  1698. struct tm tmStart;
  1699. struct timeb tbStart;
  1700. struct tm tmStop;
  1701. struct timeb tbStop;
  1702. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1703. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1704. // Scan start & stop date time
  1705. if(strstr((char*)start, ".") != NULL)
  1706. {
  1707. // Original data with mini second
  1708. if(strstr((char*)start, "Z") != NULL)
  1709. {
  1710. // Original data with Z
  1711. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1712. &parseStart.year,
  1713. &parseStart.month,
  1714. &parseStart.mday,
  1715. &parseStart.hour,
  1716. &parseStart.min,
  1717. &parseStart.sec,
  1718. &parseStart.minSec);
  1719. }
  1720. else
  1721. {
  1722. // Original data without Z
  1723. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1724. &parseStart.year,
  1725. &parseStart.month,
  1726. &parseStart.mday,
  1727. &parseStart.hour,
  1728. &parseStart.min,
  1729. &parseStart.sec,
  1730. &parseStart.minSec,
  1731. &parseStart.tz_hour,
  1732. &parseStart.tz_min);
  1733. }
  1734. }
  1735. else
  1736. {
  1737. // Original data without mini second
  1738. if(strstr((char*)start, "Z") != NULL)
  1739. {
  1740. // Original data with Z
  1741. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1742. &parseStart.year,
  1743. &parseStart.month,
  1744. &parseStart.mday,
  1745. &parseStart.hour,
  1746. &parseStart.min,
  1747. &parseStart.sec);
  1748. }
  1749. else
  1750. {
  1751. // Original data without Z
  1752. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1753. &parseStart.year,
  1754. &parseStart.month,
  1755. &parseStart.mday,
  1756. &parseStart.hour,
  1757. &parseStart.min,
  1758. &parseStart.sec,
  1759. &parseStart.tz_hour,
  1760. &parseStart.tz_min);
  1761. }
  1762. }
  1763. if(strstr((char*)stop, ".") != NULL)
  1764. {
  1765. // Original data with mini second
  1766. if(strstr((char*)stop, "Z") != NULL)
  1767. {
  1768. // Original data with Z
  1769. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1770. &parseStop.year,
  1771. &parseStop.month,
  1772. &parseStop.mday,
  1773. &parseStop.hour,
  1774. &parseStop.min,
  1775. &parseStop.sec,
  1776. &parseStop.minSec);
  1777. }
  1778. else
  1779. {
  1780. // Original data without Z
  1781. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1782. &parseStop.year,
  1783. &parseStop.month,
  1784. &parseStop.mday,
  1785. &parseStop.hour,
  1786. &parseStop.min,
  1787. &parseStop.sec,
  1788. &parseStop.minSec,
  1789. &parseStop.tz_hour,
  1790. &parseStop.tz_min);
  1791. }
  1792. }
  1793. else
  1794. {
  1795. // Original data without mini second
  1796. if(strstr((char*)stop, "Z") != NULL)
  1797. {
  1798. // Original data with Z
  1799. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1800. &parseStop.year,
  1801. &parseStop.month,
  1802. &parseStop.mday,
  1803. &parseStop.hour,
  1804. &parseStop.min,
  1805. &parseStop.sec);
  1806. }
  1807. else
  1808. {
  1809. // Original data without Z
  1810. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1811. &parseStop.year,
  1812. &parseStop.month,
  1813. &parseStop.mday,
  1814. &parseStop.hour,
  1815. &parseStop.min,
  1816. &parseStop.sec,
  1817. &parseStop.tz_hour,
  1818. &parseStop.tz_min);
  1819. }
  1820. }
  1821. // Calculate date time difference
  1822. if((parseStart.scanedElement >=6) &&
  1823. (parseStop.scanedElement >=6))
  1824. {
  1825. //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);
  1826. //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);
  1827. tmStart.tm_year = parseStart.year - 1900;
  1828. tmStart.tm_mon = parseStart.month - 1;
  1829. tmStart.tm_mday = parseStart.mday;
  1830. tmStart.tm_hour = parseStart.hour;
  1831. tmStart.tm_min = parseStart.min;
  1832. tmStart.tm_sec = parseStart.sec;
  1833. tmStart.tm_gmtoff = 0;
  1834. tbStart.time = mktime(&tmStart);
  1835. tbStart.timezone = 0;
  1836. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1837. tmStop.tm_year = parseStop.year - 1900;
  1838. tmStop.tm_mon = parseStop.month - 1;
  1839. tmStop.tm_mday = parseStop.mday;
  1840. tmStop.tm_hour = parseStop.hour;
  1841. tmStop.tm_min = parseStop.min;
  1842. tmStop.tm_sec = parseStop.sec;
  1843. tmStop.tm_gmtoff = 0;
  1844. tbStop.time = mktime(&tmStop);
  1845. tbStop.timezone = 0;
  1846. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1847. result = DiffTimebSec(tbStart, tbStop);
  1848. //DEBUG_INFO("getStartStop(): %d\n", result);
  1849. }
  1850. else
  1851. {
  1852. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1853. }
  1854. return result;
  1855. }
  1856. int isOvertNow(uint8_t *start)
  1857. {
  1858. int result = NO;
  1859. struct ParsingResult
  1860. {
  1861. int result;
  1862. int scanedElement;
  1863. int year;
  1864. int month;
  1865. int mday;
  1866. int hour;
  1867. int min;
  1868. int sec;
  1869. int tz_hour;
  1870. int tz_min;
  1871. float minSec;
  1872. }parsingResult;
  1873. struct tm tmStart;
  1874. struct timeb tbStart;
  1875. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1876. if(strstr((char*)start, ".") != NULL)
  1877. {
  1878. // Original data with mini second
  1879. if(strstr((char*)start, "Z") != NULL)
  1880. {
  1881. // Original data with Z
  1882. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1883. &parsingResult.year,
  1884. &parsingResult.month,
  1885. &parsingResult.mday,
  1886. &parsingResult.hour,
  1887. &parsingResult.min,
  1888. &parsingResult.sec,
  1889. &parsingResult.minSec);
  1890. }
  1891. else
  1892. {
  1893. // Original data without Z
  1894. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1895. &parsingResult.year,
  1896. &parsingResult.month,
  1897. &parsingResult.mday,
  1898. &parsingResult.hour,
  1899. &parsingResult.min,
  1900. &parsingResult.sec,
  1901. &parsingResult.minSec,
  1902. &parsingResult.tz_hour,
  1903. &parsingResult.tz_min);
  1904. }
  1905. }
  1906. else
  1907. {
  1908. // Original data without mini second
  1909. if(strstr((char*)start, "Z") != NULL)
  1910. {
  1911. // Original data with Z
  1912. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1913. &parsingResult.year,
  1914. &parsingResult.month,
  1915. &parsingResult.mday,
  1916. &parsingResult.hour,
  1917. &parsingResult.min,
  1918. &parsingResult.sec);
  1919. }
  1920. else
  1921. {
  1922. // Original data without Z
  1923. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1924. &parsingResult.year,
  1925. &parsingResult.month,
  1926. &parsingResult.mday,
  1927. &parsingResult.hour,
  1928. &parsingResult.min,
  1929. &parsingResult.sec,
  1930. &parsingResult.tz_hour,
  1931. &parsingResult.tz_min);
  1932. }
  1933. }
  1934. if(parsingResult.scanedElement >= 6)
  1935. {
  1936. tmStart.tm_year = parsingResult.year - 1900;
  1937. tmStart.tm_mon = parsingResult.month - 1;
  1938. tmStart.tm_mday = parsingResult.mday;
  1939. tmStart.tm_hour = parsingResult.hour;
  1940. tmStart.tm_min = parsingResult.min;
  1941. tmStart.tm_sec = parsingResult.sec;
  1942. tmStart.tm_gmtoff = 0;
  1943. tbStart.time = mktime(&tmStart);
  1944. tbStart.timezone = 0;
  1945. tbStart.millitm = 0;
  1946. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1947. if(DiffTimebWithNowSec(tbStart) <= 0)
  1948. result = NO;
  1949. else
  1950. result = YES;
  1951. }
  1952. else
  1953. {
  1954. DEBUG_WARN("Start date parsing error.\n");
  1955. }
  1956. return result;
  1957. }
  1958. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1959. {
  1960. struct ParsingResult
  1961. {
  1962. int result;
  1963. int scanedElement;
  1964. int year;
  1965. int month;
  1966. int mday;
  1967. int hour;
  1968. int min;
  1969. int sec;
  1970. int tz_hour;
  1971. int tz_min;
  1972. float minSec;
  1973. };
  1974. struct ParsingResult parseStart;
  1975. struct ParsingResult parseStop;
  1976. int result = -1;
  1977. struct tm tmStart;
  1978. struct timeb tbStart;
  1979. struct tm tmStop;
  1980. struct timeb tbStop;
  1981. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1982. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1983. // Scan start & stop date time
  1984. if(strstr((char*)start, ".") != NULL)
  1985. {
  1986. // Original data with mini second
  1987. if(strstr((char*)start, "Z") != NULL)
  1988. {
  1989. // Original data with Z
  1990. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1991. &parseStart.year,
  1992. &parseStart.month,
  1993. &parseStart.mday,
  1994. &parseStart.hour,
  1995. &parseStart.min,
  1996. &parseStart.sec,
  1997. &parseStart.minSec);
  1998. }
  1999. else
  2000. {
  2001. // Original data without Z
  2002. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2003. &parseStart.year,
  2004. &parseStart.month,
  2005. &parseStart.mday,
  2006. &parseStart.hour,
  2007. &parseStart.min,
  2008. &parseStart.sec,
  2009. &parseStart.minSec,
  2010. &parseStart.tz_hour,
  2011. &parseStart.tz_min);
  2012. }
  2013. }
  2014. else
  2015. {
  2016. // Original data without mini second
  2017. if(strstr((char*)start, "Z") != NULL)
  2018. {
  2019. // Original data with Z
  2020. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  2021. &parseStart.year,
  2022. &parseStart.month,
  2023. &parseStart.mday,
  2024. &parseStart.hour,
  2025. &parseStart.min,
  2026. &parseStart.sec);
  2027. }
  2028. else
  2029. {
  2030. // Original data without Z
  2031. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  2032. &parseStart.year,
  2033. &parseStart.month,
  2034. &parseStart.mday,
  2035. &parseStart.hour,
  2036. &parseStart.min,
  2037. &parseStart.sec,
  2038. &parseStart.tz_hour,
  2039. &parseStart.tz_min);
  2040. }
  2041. }
  2042. if(strstr((char*)stop, ".") != NULL)
  2043. {
  2044. // Original data with mini second
  2045. if(strstr((char*)stop, "Z") != NULL)
  2046. {
  2047. // Original data with Z
  2048. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  2049. &parseStop.year,
  2050. &parseStop.month,
  2051. &parseStop.mday,
  2052. &parseStop.hour,
  2053. &parseStop.min,
  2054. &parseStop.sec,
  2055. &parseStop.minSec);
  2056. }
  2057. else
  2058. {
  2059. // Original data without Z
  2060. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2061. &parseStop.year,
  2062. &parseStop.month,
  2063. &parseStop.mday,
  2064. &parseStop.hour,
  2065. &parseStop.min,
  2066. &parseStop.sec,
  2067. &parseStop.minSec,
  2068. &parseStop.tz_hour,
  2069. &parseStop.tz_min);
  2070. }
  2071. }
  2072. else
  2073. {
  2074. // Original data without mini second
  2075. if(strstr((char*)stop, "Z") != NULL)
  2076. {
  2077. // Original data with Z
  2078. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  2079. &parseStop.year,
  2080. &parseStop.month,
  2081. &parseStop.mday,
  2082. &parseStop.hour,
  2083. &parseStop.min,
  2084. &parseStop.sec);
  2085. }
  2086. else
  2087. {
  2088. // Original data without Z
  2089. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  2090. &parseStop.year,
  2091. &parseStop.month,
  2092. &parseStop.mday,
  2093. &parseStop.hour,
  2094. &parseStop.min,
  2095. &parseStop.sec,
  2096. &parseStop.tz_hour,
  2097. &parseStop.tz_min);
  2098. }
  2099. }
  2100. // Calculate date time difference
  2101. if((parseStart.scanedElement >=6) &&
  2102. (parseStop.scanedElement >=6))
  2103. {
  2104. //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);
  2105. //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);
  2106. tmStart.tm_year = parseStart.year - 1900;
  2107. tmStart.tm_mon = parseStart.month - 1;
  2108. tmStart.tm_mday = parseStart.mday;
  2109. tmStart.tm_hour = parseStart.hour;
  2110. tmStart.tm_min = parseStart.min;
  2111. tmStart.tm_sec = parseStart.sec;
  2112. tmStart.tm_gmtoff = 0;
  2113. tbStart.time = mktime(&tmStart);
  2114. tbStart.timezone = 0;
  2115. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  2116. tmStop.tm_year = parseStop.year - 1900;
  2117. tmStop.tm_mon = parseStop.month - 1;
  2118. tmStop.tm_mday = parseStop.mday;
  2119. tmStop.tm_hour = parseStop.hour;
  2120. tmStop.tm_min = parseStop.min;
  2121. tmStop.tm_sec = parseStop.sec;
  2122. tmStop.tm_gmtoff = 0;
  2123. tbStop.time = mktime(&tmStop);
  2124. tbStop.timezone = 0;
  2125. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  2126. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2127. //DEBUG_INFO("getStartStop(): %d\n", result);
  2128. }
  2129. else
  2130. {
  2131. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2132. }
  2133. return result;
  2134. }
  2135. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2136. {
  2137. FILE *fp;
  2138. char profileFileName[128];
  2139. char *line = NULL;
  2140. size_t len = 0;
  2141. time_t CurrentTime;
  2142. struct tm *tmComposite;
  2143. struct StructChargingProfile maxProfile;
  2144. struct StructChargingProfile compositeProfile;
  2145. uint8_t limitMax=0;
  2146. int compositePeriodIdx = 0;
  2147. //uint8_t isDurationNull = FALSE;
  2148. CurrentTime = time(NULL);
  2149. tmComposite=localtime(&CurrentTime);
  2150. 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);
  2151. if(isUnitA)
  2152. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2153. else
  2154. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2155. compositeProfile.ChargingSchedule.Duration = durationReq;
  2156. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2157. {
  2158. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2159. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2160. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2161. }
  2162. compositeProfile.ChargingProfileId = 0;
  2163. compositeProfile.StackLevel = 99 ;
  2164. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2165. maxProfile.ChargingProfileId = -1;
  2166. maxProfile.ChargingSchedule.Duration = -1;
  2167. system("rm -f /tmp/*.json");
  2168. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2169. // Search max profile
  2170. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2171. if((access(profileFileName, F_OK))!=-1)
  2172. {
  2173. fp = fopen(profileFileName, "r");
  2174. while(getline(&line, &len, fp) != -1)
  2175. {
  2176. json_object *obj = NULL;
  2177. obj = json_tokener_parse(line);
  2178. if(is_error(obj))
  2179. {
  2180. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2181. }
  2182. else
  2183. {
  2184. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2185. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2186. )
  2187. {
  2188. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2189. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2190. )
  2191. {
  2192. struct tm tmFrom, tmTo;
  2193. struct timeb tbFrom, tbTo;
  2194. 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) &&
  2195. (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))
  2196. {
  2197. tmFrom.tm_year -= 1900;
  2198. tmFrom.tm_mon -= 1;
  2199. tbFrom.time = mktime(&tmFrom);
  2200. tmTo.tm_year -= 1900;
  2201. tmTo.tm_mon -= 1;
  2202. tbTo.time = mktime(&tmTo);
  2203. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2204. {
  2205. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2206. {
  2207. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2208. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2209. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2210. }
  2211. if(maxProfile.ChargingProfileId == -1)
  2212. DEBUG_INFO("MaxProfile found.\n");
  2213. else
  2214. DEBUG_INFO("MaxProfile updated.\n");
  2215. // Required item
  2216. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2217. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2218. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2219. if(isUnitA)
  2220. {
  2221. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2222. 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++)
  2223. {
  2224. 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"));
  2225. 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?
  2226. 3:
  2227. 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")));
  2228. 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")));
  2229. }
  2230. }
  2231. else
  2232. {
  2233. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2234. 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++)
  2235. {
  2236. 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"));
  2237. 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?
  2238. 3:
  2239. 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")));
  2240. 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));
  2241. }
  2242. }
  2243. // Optional item
  2244. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2245. {
  2246. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2247. }
  2248. else
  2249. {
  2250. sprintf((char*)maxProfile.ValidFrom, " ");
  2251. }
  2252. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2253. {
  2254. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2255. }
  2256. else
  2257. {
  2258. sprintf((char*)maxProfile.ValidTo, " ");
  2259. }
  2260. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2261. {
  2262. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2263. }
  2264. else
  2265. {
  2266. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2267. }
  2268. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2269. {
  2270. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2271. }
  2272. else
  2273. {
  2274. maxProfile.TransactionId = -1;
  2275. }
  2276. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2277. {
  2278. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2279. }
  2280. else
  2281. {
  2282. maxProfile.ChargingSchedule.Duration = 86400;
  2283. //isDurationNull = TRUE;
  2284. }
  2285. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2286. {
  2287. 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")));
  2288. }
  2289. else
  2290. {
  2291. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2292. }
  2293. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2294. {
  2295. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2296. }
  2297. else
  2298. {
  2299. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2300. }
  2301. }
  2302. }
  2303. }
  2304. else
  2305. {
  2306. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2307. {
  2308. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2309. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2310. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2311. }
  2312. if(maxProfile.ChargingProfileId == -1)
  2313. DEBUG_INFO("MaxProfile found.\n");
  2314. else
  2315. DEBUG_INFO("MaxProfile updated.\n");
  2316. // Required item
  2317. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2318. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2319. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2320. if(isUnitA)
  2321. {
  2322. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2323. 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++)
  2324. {
  2325. 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"));
  2326. 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?
  2327. 3:
  2328. 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")));
  2329. 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")));
  2330. }
  2331. }
  2332. else
  2333. {
  2334. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2335. 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++)
  2336. {
  2337. 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"));
  2338. 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?
  2339. 3:
  2340. 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")));
  2341. 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));
  2342. }
  2343. }
  2344. // Optional item
  2345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2346. {
  2347. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2348. }
  2349. else
  2350. {
  2351. sprintf((char*)maxProfile.ValidFrom, " ");
  2352. }
  2353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2354. {
  2355. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2356. }
  2357. else
  2358. {
  2359. sprintf((char*)maxProfile.ValidTo, " ");
  2360. }
  2361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2362. {
  2363. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2364. }
  2365. else
  2366. {
  2367. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2368. }
  2369. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2370. {
  2371. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2372. }
  2373. else
  2374. {
  2375. maxProfile.TransactionId = -1;
  2376. }
  2377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2378. {
  2379. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2380. }
  2381. else
  2382. {
  2383. maxProfile.ChargingSchedule.Duration = 86400;
  2384. //isDurationNull = TRUE;
  2385. }
  2386. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2387. {
  2388. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2389. }
  2390. else
  2391. {
  2392. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2393. }
  2394. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2395. {
  2396. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2397. }
  2398. else
  2399. {
  2400. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2401. }
  2402. }
  2403. }
  2404. }
  2405. json_object_put(obj);
  2406. }
  2407. fclose(fp);
  2408. /*
  2409. if(maxProfile.ChargingProfileId !=-1)
  2410. {
  2411. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2412. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2413. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2414. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2415. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2416. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2417. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2418. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2419. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2420. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2421. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2422. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2423. {
  2424. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2425. {
  2426. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2427. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2428. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2429. }
  2430. }
  2431. }
  2432. else
  2433. DEBUG_INFO("MaxProfile not found.\n");
  2434. DEBUG_INFO("------------------------------------\n");*/
  2435. }
  2436. if(maxProfile.ChargingProfileId != -1)
  2437. {
  2438. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2439. {
  2440. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2441. {
  2442. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2443. 0:
  2444. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2445. }
  2446. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2447. {
  2448. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2449. {
  2450. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2451. 0:
  2452. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2453. if(idxPeriod > 0)
  2454. {
  2455. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2456. {
  2457. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2458. }
  2459. }
  2460. }
  2461. }
  2462. }
  2463. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2464. {
  2465. if(maxProfile.ChargingSchedule.Duration != -1)
  2466. {
  2467. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2468. }
  2469. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2470. {
  2471. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2472. {
  2473. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2474. if(idxPeriod > 0)
  2475. {
  2476. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2477. {
  2478. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2479. }
  2480. }
  2481. }
  2482. }
  2483. }
  2484. else
  2485. {
  2486. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2487. {
  2488. if(maxProfile.ChargingSchedule.Duration != -1)
  2489. {
  2490. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2491. 0:
  2492. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2493. }
  2494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2495. {
  2496. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2497. {
  2498. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2499. 0:
  2500. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2501. if(idxPeriod > 0)
  2502. {
  2503. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2504. {
  2505. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2506. }
  2507. }
  2508. }
  2509. }
  2510. }
  2511. else
  2512. {
  2513. if(maxProfile.ChargingSchedule.Duration != -1)
  2514. {
  2515. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2516. 0:
  2517. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2518. }
  2519. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2520. {
  2521. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2522. {
  2523. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2524. 0:
  2525. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2526. if(idxPeriod > 0)
  2527. {
  2528. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2529. {
  2530. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2531. }
  2532. }
  2533. }
  2534. }
  2535. }
  2536. }
  2537. /*
  2538. DEBUG_INFO("MaxProfile after align.\n");
  2539. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2540. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2541. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2542. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2543. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2544. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2545. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2546. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2547. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2548. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2549. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2550. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2551. {
  2552. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2553. {
  2554. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2555. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2556. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2557. }
  2558. }
  2559. DEBUG_INFO("------------------------------------\n");*/
  2560. }
  2561. // Find each profile period quantity
  2562. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2563. {
  2564. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2565. limitMax = idx+1;
  2566. }
  2567. if(maxProfile.ChargingProfileId != -1)
  2568. {
  2569. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2570. {
  2571. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2572. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2573. (maxProfile.ChargingSchedule.Duration > 0))
  2574. {
  2575. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2576. {
  2577. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2578. compositePeriodIdx++;
  2579. }
  2580. else
  2581. {
  2582. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2583. }
  2584. }
  2585. }
  2586. }
  2587. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2588. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2589. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2590. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2591. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2592. {
  2593. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2594. {
  2595. compositeProfile.ChargingProfileId = 1;
  2596. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2597. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2598. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2599. }
  2600. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2601. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2602. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2603. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2604. }
  2605. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2606. if(line)
  2607. free(line);
  2608. }
  2609. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2610. {
  2611. FILE *fp;
  2612. char profileFileName[128];
  2613. char *line = NULL;
  2614. size_t len = 0;
  2615. time_t CurrentTime;
  2616. struct tm *tmComposite;
  2617. struct StructChargingProfile maxProfile;
  2618. struct StructChargingProfile defaultTxProfile;
  2619. struct StructChargingProfile txProfile;
  2620. struct StructChargingProfile compositeProfile;
  2621. struct StructChargingSchedulePeriod tmpPeriod;
  2622. uint8_t limitMax=0;
  2623. uint8_t limitDef=0;
  2624. uint8_t limitTx=0;
  2625. int compositePeriodIdx = 0;
  2626. CurrentTime = time(NULL);
  2627. tmComposite=localtime(&CurrentTime);
  2628. 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);
  2629. if(isUnitA)
  2630. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2631. else
  2632. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2633. compositeProfile.ChargingSchedule.Duration = durationReq;
  2634. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2635. {
  2636. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2637. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2638. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2639. }
  2640. compositeProfile.ChargingProfileId = 0;
  2641. compositeProfile.StackLevel = 99 ;
  2642. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2643. maxProfile.ChargingProfileId = -1;
  2644. defaultTxProfile.ChargingProfileId = -1;
  2645. txProfile.ChargingProfileId = -1;
  2646. maxProfile.ChargingSchedule.Duration = -1;
  2647. defaultTxProfile.ChargingSchedule.Duration = -1;
  2648. txProfile.ChargingSchedule.Duration = -1;
  2649. system("rm -f /tmp/*.json");
  2650. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2651. /*
  2652. * Search valid charging profile
  2653. */
  2654. //DEBUG_INFO("====================================\n");
  2655. // Search tx profile
  2656. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2657. if((access(profileFileName, F_OK))!=-1)
  2658. {
  2659. fp = fopen(profileFileName, "r");
  2660. while(getline(&line, &len, fp) != -1)
  2661. {
  2662. json_object *obj = NULL;
  2663. obj = json_tokener_parse(line);
  2664. if(is_error(obj))
  2665. {
  2666. DEBUG_ERROR("Parse txProfile from file error.\n");
  2667. }
  2668. else
  2669. {
  2670. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2671. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2672. )
  2673. {
  2674. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2675. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2676. )
  2677. {
  2678. struct tm tmFrom, tmTo;
  2679. struct timeb tbFrom, tbTo;
  2680. 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) &&
  2681. (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))
  2682. {
  2683. tmFrom.tm_year -= 1900;
  2684. tmFrom.tm_mon -= 1;
  2685. tbFrom.time = mktime(&tmFrom);
  2686. tmTo.tm_year -= 1900;
  2687. tmTo.tm_mon -= 1;
  2688. tbTo.time = mktime(&tmTo);
  2689. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2690. {
  2691. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2692. {
  2693. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2694. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2695. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2696. }
  2697. if(txProfile.ChargingProfileId == -1)
  2698. DEBUG_INFO("TxProfile found.\n");
  2699. else
  2700. DEBUG_INFO("TxProfile updated.\n");
  2701. // Required item
  2702. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2703. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2704. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2705. if(isUnitA)
  2706. {
  2707. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2708. 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++)
  2709. {
  2710. 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"));
  2711. 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?
  2712. 3:
  2713. 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")));
  2714. 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")));
  2715. }
  2716. }
  2717. else
  2718. {
  2719. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2720. 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++)
  2721. {
  2722. 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"));
  2723. 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?
  2724. 3:
  2725. 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")));
  2726. 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));
  2727. }
  2728. }
  2729. // Optional item
  2730. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2731. {
  2732. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2733. }
  2734. else
  2735. {
  2736. sprintf((char*)txProfile.ValidFrom, " ");
  2737. }
  2738. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2739. {
  2740. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2741. }
  2742. else
  2743. {
  2744. sprintf((char*)txProfile.ValidTo, " ");
  2745. }
  2746. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2747. {
  2748. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2749. }
  2750. else
  2751. {
  2752. sprintf((char*)txProfile.RecurrencyKind, " ");
  2753. }
  2754. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2755. {
  2756. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2757. }
  2758. else
  2759. {
  2760. txProfile.TransactionId = -1;
  2761. }
  2762. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2763. {
  2764. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2765. }
  2766. else
  2767. {
  2768. txProfile.ChargingSchedule.Duration = 86400;
  2769. }
  2770. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2771. {
  2772. 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")));
  2773. }
  2774. else
  2775. {
  2776. 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));
  2777. }
  2778. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2779. {
  2780. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2781. }
  2782. else
  2783. {
  2784. txProfile.ChargingSchedule.MinChargingRate = -1;
  2785. }
  2786. }
  2787. }
  2788. }
  2789. else
  2790. {
  2791. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2792. {
  2793. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2794. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2795. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2796. }
  2797. if(txProfile.ChargingProfileId == -1)
  2798. DEBUG_INFO("TxProfile found.\n");
  2799. else
  2800. DEBUG_INFO("TxProfile updated.\n");
  2801. // Required item
  2802. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2803. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2804. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2805. if(isUnitA)
  2806. {
  2807. sprintf((char*)txProfile.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. 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"));
  2811. 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?
  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. 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")));
  2815. }
  2816. }
  2817. else
  2818. {
  2819. sprintf((char*)txProfile.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. 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"));
  2823. 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?
  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. 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));
  2827. }
  2828. }
  2829. // Optional item
  2830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2831. {
  2832. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2833. }
  2834. else
  2835. {
  2836. sprintf((char*)txProfile.ValidFrom, " ");
  2837. }
  2838. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2839. {
  2840. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2841. }
  2842. else
  2843. {
  2844. sprintf((char*)txProfile.ValidTo, " ");
  2845. }
  2846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2847. {
  2848. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2849. }
  2850. else
  2851. {
  2852. sprintf((char*)txProfile.RecurrencyKind, " ");
  2853. }
  2854. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2855. {
  2856. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2857. }
  2858. else
  2859. {
  2860. txProfile.TransactionId = -1;
  2861. }
  2862. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2863. {
  2864. txProfile.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. txProfile.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*)txProfile.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*)txProfile.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. txProfile.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. txProfile.ChargingSchedule.MinChargingRate = -1;
  2885. }
  2886. }
  2887. }
  2888. }
  2889. json_object_put(obj);
  2890. }
  2891. fclose(fp);
  2892. /*
  2893. if(txProfile.ChargingProfileId != -1)
  2894. {
  2895. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2896. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2897. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2898. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2899. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2900. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2901. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2902. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2903. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2904. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2905. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2906. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2907. {
  2908. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2909. {
  2910. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2911. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2912. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2913. }
  2914. }
  2915. }
  2916. else
  2917. DEBUG_INFO("TxProfile not found.\n");*/
  2918. }
  2919. // Search default tx profile
  2920. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2921. if((access(profileFileName, F_OK))==-1)
  2922. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2923. if((access(profileFileName, F_OK))!=-1)
  2924. {
  2925. fp = fopen(profileFileName, "r");
  2926. while(getline(&line, &len, fp) != -1)
  2927. {
  2928. json_object *obj = NULL;
  2929. obj = json_tokener_parse(line);
  2930. if(is_error(obj))
  2931. {
  2932. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2933. }
  2934. else
  2935. {
  2936. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2937. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2938. )
  2939. {
  2940. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2941. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2942. )
  2943. {
  2944. struct tm tmFrom, tmTo;
  2945. struct timeb tbFrom, tbTo;
  2946. 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) &&
  2947. (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))
  2948. {
  2949. tmFrom.tm_year -= 1900;
  2950. tmFrom.tm_mon -= 1;
  2951. tbFrom.time = mktime(&tmFrom);
  2952. tmTo.tm_year -= 1900;
  2953. tmTo.tm_mon -= 1;
  2954. tbTo.time = mktime(&tmTo);
  2955. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2956. {
  2957. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2958. {
  2959. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2960. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2961. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2962. }
  2963. if(defaultTxProfile.ChargingProfileId == -1)
  2964. DEBUG_INFO("TxDefaultProfile found.\n");
  2965. else
  2966. DEBUG_INFO("TxDefaultProfile updated.\n");
  2967. // Required item
  2968. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2969. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2970. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2971. if(isUnitA)
  2972. {
  2973. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2974. 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++)
  2975. {
  2976. 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"));
  2977. 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?
  2978. 3:
  2979. 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")));
  2980. 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")));
  2981. }
  2982. }
  2983. else
  2984. {
  2985. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2986. 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++)
  2987. {
  2988. 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"));
  2989. 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?
  2990. 3:
  2991. 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")));
  2992. 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));
  2993. }
  2994. }
  2995. // Optional item
  2996. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2997. {
  2998. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2999. }
  3000. else
  3001. {
  3002. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3003. }
  3004. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3005. {
  3006. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3007. }
  3008. else
  3009. {
  3010. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3011. }
  3012. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3013. {
  3014. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3015. }
  3016. else
  3017. {
  3018. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3019. }
  3020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3021. {
  3022. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3023. }
  3024. else
  3025. {
  3026. defaultTxProfile.TransactionId = -1;
  3027. }
  3028. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3029. {
  3030. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3031. }
  3032. else
  3033. {
  3034. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3035. }
  3036. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3037. {
  3038. 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")));
  3039. }
  3040. else
  3041. {
  3042. 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));
  3043. }
  3044. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3045. {
  3046. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3047. }
  3048. else
  3049. {
  3050. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3051. }
  3052. }
  3053. }
  3054. }
  3055. else
  3056. {
  3057. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3058. {
  3059. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3060. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3061. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3062. }
  3063. if(defaultTxProfile.ChargingProfileId == -1)
  3064. DEBUG_INFO("TxDefaultProfile found.\n");
  3065. else
  3066. DEBUG_INFO("TxDefaultProfile updated.\n");
  3067. // Required item
  3068. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3069. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3070. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3071. if(isUnitA)
  3072. {
  3073. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3074. 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++)
  3075. {
  3076. 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"));
  3077. 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?
  3078. 3:
  3079. 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")));
  3080. 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")));
  3081. }
  3082. }
  3083. else
  3084. {
  3085. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3086. 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++)
  3087. {
  3088. 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"));
  3089. 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?
  3090. 3:
  3091. 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")));
  3092. 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));
  3093. }
  3094. }
  3095. // Optional item
  3096. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3097. {
  3098. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3099. }
  3100. else
  3101. {
  3102. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3103. }
  3104. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3105. {
  3106. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3107. }
  3108. else
  3109. {
  3110. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3111. }
  3112. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3113. {
  3114. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3115. }
  3116. else
  3117. {
  3118. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3119. }
  3120. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3121. {
  3122. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3123. }
  3124. else
  3125. {
  3126. defaultTxProfile.TransactionId = -1;
  3127. }
  3128. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3129. {
  3130. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3131. }
  3132. else
  3133. {
  3134. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3135. }
  3136. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3137. {
  3138. 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")));
  3139. }
  3140. else
  3141. {
  3142. 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));
  3143. }
  3144. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3145. {
  3146. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3147. }
  3148. else
  3149. {
  3150. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3151. }
  3152. }
  3153. }
  3154. }
  3155. json_object_put(obj);
  3156. }
  3157. fclose(fp);
  3158. /*
  3159. if(defaultTxProfile.ChargingProfileId != -1)
  3160. {
  3161. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3162. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3163. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3164. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3165. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3166. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3167. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3168. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  3169. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3170. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3171. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3172. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3173. {
  3174. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3175. {
  3176. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3177. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3178. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3179. }
  3180. }
  3181. }
  3182. else
  3183. DEBUG_INFO("TxDefaultProfile not found.\n");
  3184. DEBUG_INFO("------------------------------------\n");*/
  3185. }
  3186. // Search max profile
  3187. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3188. if((access(profileFileName, F_OK))!=-1)
  3189. {
  3190. fp = fopen(profileFileName, "r");
  3191. while(getline(&line, &len, fp) != -1)
  3192. {
  3193. json_object *obj = NULL;
  3194. obj = json_tokener_parse(line);
  3195. if(is_error(obj))
  3196. {
  3197. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3198. }
  3199. else
  3200. {
  3201. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3202. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3203. )
  3204. {
  3205. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3206. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3207. )
  3208. {
  3209. struct tm tmFrom, tmTo;
  3210. struct timeb tbFrom, tbTo;
  3211. 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) &&
  3212. (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))
  3213. {
  3214. tmFrom.tm_year -= 1900;
  3215. tmFrom.tm_mon -= 1;
  3216. tbFrom.time = mktime(&tmFrom);
  3217. tmTo.tm_year -= 1900;
  3218. tmTo.tm_mon -= 1;
  3219. tbTo.time = mktime(&tmTo);
  3220. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3221. {
  3222. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3223. {
  3224. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3225. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3226. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3227. }
  3228. if(maxProfile.ChargingProfileId == -1)
  3229. DEBUG_INFO("MaxProfile found.\n");
  3230. else
  3231. DEBUG_INFO("MaxProfile updated.\n");
  3232. // Required item
  3233. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3234. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3235. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3236. if(isUnitA)
  3237. {
  3238. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3239. 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++)
  3240. {
  3241. 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"));
  3242. 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?
  3243. 3:
  3244. 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")));
  3245. 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")));
  3246. }
  3247. }
  3248. else
  3249. {
  3250. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3251. 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++)
  3252. {
  3253. 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"));
  3254. 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?
  3255. 3:
  3256. 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")));
  3257. 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));
  3258. }
  3259. }
  3260. // Optional item
  3261. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3262. {
  3263. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3264. }
  3265. else
  3266. {
  3267. sprintf((char*)maxProfile.ValidFrom, " ");
  3268. }
  3269. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3270. {
  3271. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3272. }
  3273. else
  3274. {
  3275. sprintf((char*)maxProfile.ValidTo, " ");
  3276. }
  3277. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3278. {
  3279. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3280. }
  3281. else
  3282. {
  3283. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3284. }
  3285. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3286. {
  3287. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3288. }
  3289. else
  3290. {
  3291. maxProfile.TransactionId = -1;
  3292. }
  3293. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3294. {
  3295. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3296. }
  3297. else
  3298. {
  3299. maxProfile.ChargingSchedule.Duration = 86400;
  3300. }
  3301. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3302. {
  3303. 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")));
  3304. }
  3305. else
  3306. {
  3307. 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));
  3308. }
  3309. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3310. {
  3311. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3312. }
  3313. else
  3314. {
  3315. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3316. }
  3317. }
  3318. }
  3319. }
  3320. else
  3321. {
  3322. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3323. {
  3324. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3325. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3326. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3327. }
  3328. if(maxProfile.ChargingProfileId == -1)
  3329. DEBUG_INFO("MaxProfile found.\n");
  3330. else
  3331. DEBUG_INFO("MaxProfile updated.\n");
  3332. // Required item
  3333. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3334. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3335. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3336. if(isUnitA)
  3337. {
  3338. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3339. 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++)
  3340. {
  3341. 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"));
  3342. 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?
  3343. 3:
  3344. 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")));
  3345. 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")));
  3346. }
  3347. }
  3348. else
  3349. {
  3350. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3351. 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++)
  3352. {
  3353. 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"));
  3354. 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?
  3355. 3:
  3356. 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")));
  3357. 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));
  3358. }
  3359. }
  3360. // Optional item
  3361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3362. {
  3363. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3364. }
  3365. else
  3366. {
  3367. sprintf((char*)maxProfile.ValidFrom, " ");
  3368. }
  3369. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3370. {
  3371. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3372. }
  3373. else
  3374. {
  3375. sprintf((char*)maxProfile.ValidTo, " ");
  3376. }
  3377. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3378. {
  3379. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3380. }
  3381. else
  3382. {
  3383. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3384. }
  3385. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3386. {
  3387. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3388. }
  3389. else
  3390. {
  3391. maxProfile.TransactionId = -1;
  3392. }
  3393. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3394. {
  3395. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3396. }
  3397. else
  3398. {
  3399. maxProfile.ChargingSchedule.Duration = 86400;
  3400. }
  3401. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3402. {
  3403. 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")));
  3404. }
  3405. else
  3406. {
  3407. 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));
  3408. }
  3409. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3410. {
  3411. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3412. }
  3413. else
  3414. {
  3415. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3416. }
  3417. }
  3418. }
  3419. }
  3420. json_object_put(obj);
  3421. }
  3422. fclose(fp);
  3423. /*
  3424. if(maxProfile.ChargingProfileId !=-1)
  3425. {
  3426. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3427. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3428. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3429. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3430. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3431. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3432. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3433. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3434. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3435. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3436. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3437. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3438. {
  3439. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3440. {
  3441. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3442. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3443. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3444. }
  3445. }
  3446. }
  3447. else
  3448. DEBUG_INFO("MaxProfile not found.\n");
  3449. DEBUG_INFO("------------------------------------\n");*/
  3450. }
  3451. /*
  3452. * Align found profile start schedule & periods
  3453. */
  3454. //DEBUG_INFO("====================================\n");
  3455. /*
  3456. // For local test usage, force modify found profile start schedule info
  3457. 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);
  3458. 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);
  3459. 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);
  3460. */
  3461. if(txProfile.ChargingProfileId != -1)
  3462. {
  3463. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3464. {
  3465. if(txProfile.ChargingSchedule.Duration != -1)
  3466. {
  3467. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3468. 0:
  3469. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3470. }
  3471. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3472. {
  3473. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3474. {
  3475. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3476. 0:
  3477. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3478. if(idxPeriod > 0)
  3479. {
  3480. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3481. {
  3482. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3483. }
  3484. }
  3485. }
  3486. }
  3487. }
  3488. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3489. {
  3490. if(txProfile.ChargingSchedule.Duration != -1)
  3491. {
  3492. 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?
  3493. 0:
  3494. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3495. }
  3496. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3497. {
  3498. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3499. {
  3500. 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?
  3501. 0:
  3502. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3503. if(idxPeriod > 0)
  3504. {
  3505. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3506. {
  3507. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3508. }
  3509. }
  3510. }
  3511. }
  3512. }
  3513. else
  3514. {
  3515. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3516. {
  3517. if(txProfile.ChargingSchedule.Duration != -1)
  3518. {
  3519. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3520. 0:
  3521. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3522. }
  3523. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3524. {
  3525. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3526. {
  3527. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3528. 0:
  3529. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3530. if(idxPeriod > 0)
  3531. {
  3532. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3533. {
  3534. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3535. }
  3536. }
  3537. }
  3538. }
  3539. }
  3540. else
  3541. {
  3542. if(txProfile.ChargingSchedule.Duration != -1)
  3543. {
  3544. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3545. 0:
  3546. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3547. }
  3548. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3549. {
  3550. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3551. {
  3552. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3553. 0:
  3554. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3555. if(idxPeriod > 0)
  3556. {
  3557. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3558. {
  3559. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3560. }
  3561. }
  3562. }
  3563. }
  3564. }
  3565. }
  3566. /*
  3567. DEBUG_INFO("txProfile after align.\n");
  3568. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3569. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3570. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3571. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3572. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3573. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3574. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3575. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3576. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3577. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3578. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3579. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3580. {
  3581. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3582. {
  3583. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3584. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3585. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3586. }
  3587. }*/
  3588. }
  3589. if(defaultTxProfile.ChargingProfileId != -1)
  3590. {
  3591. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3592. {
  3593. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3594. {
  3595. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3596. 0:
  3597. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3598. }
  3599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3600. {
  3601. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3602. {
  3603. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3604. 0:
  3605. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3606. if(idxPeriod > 0)
  3607. {
  3608. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3609. {
  3610. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3611. }
  3612. }
  3613. }
  3614. }
  3615. }
  3616. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3617. {
  3618. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3619. {
  3620. 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?
  3621. 0:
  3622. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3623. }
  3624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3625. {
  3626. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3627. {
  3628. 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?
  3629. 0:
  3630. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3631. if(idxPeriod > 0)
  3632. {
  3633. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3634. {
  3635. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3636. }
  3637. }
  3638. }
  3639. }
  3640. }
  3641. else
  3642. {
  3643. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3644. {
  3645. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3646. {
  3647. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3648. 0:
  3649. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3650. }
  3651. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3652. {
  3653. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3654. {
  3655. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3656. 0:
  3657. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3658. if(idxPeriod > 0)
  3659. {
  3660. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3661. {
  3662. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3663. }
  3664. }
  3665. }
  3666. }
  3667. }
  3668. else
  3669. {
  3670. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3671. {
  3672. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3673. 0:
  3674. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3675. }
  3676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3677. {
  3678. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3679. {
  3680. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3681. 0:
  3682. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3683. if(idxPeriod > 0)
  3684. {
  3685. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3686. {
  3687. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3688. }
  3689. }
  3690. }
  3691. }
  3692. }
  3693. }
  3694. /*
  3695. DEBUG_INFO("defaultTxProfile after align.\n");
  3696. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3697. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3698. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3699. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3700. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3701. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3702. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3703. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3704. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3705. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3706. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3707. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3708. {
  3709. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3710. {
  3711. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3712. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3713. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3714. }
  3715. }
  3716. DEBUG_INFO("------------------------------------\n");*/
  3717. }
  3718. if(maxProfile.ChargingProfileId != -1)
  3719. {
  3720. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3721. {
  3722. if(maxProfile.ChargingSchedule.Duration != -1)
  3723. {
  3724. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3725. 0:
  3726. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3727. }
  3728. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3729. {
  3730. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3731. {
  3732. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3733. 0:
  3734. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3735. if(idxPeriod > 0)
  3736. {
  3737. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3738. {
  3739. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3740. }
  3741. }
  3742. }
  3743. }
  3744. }
  3745. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3746. {
  3747. if(maxProfile.ChargingSchedule.Duration != -1)
  3748. {
  3749. 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?
  3750. 0:
  3751. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3752. }
  3753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3754. {
  3755. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3756. {
  3757. 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?
  3758. 0:
  3759. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3760. if(idxPeriod > 0)
  3761. {
  3762. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3763. {
  3764. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3765. }
  3766. }
  3767. }
  3768. }
  3769. }
  3770. else
  3771. {
  3772. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3773. {
  3774. if(maxProfile.ChargingSchedule.Duration != -1)
  3775. {
  3776. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3777. 0:
  3778. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3779. }
  3780. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3781. {
  3782. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3783. {
  3784. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3785. 0:
  3786. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3787. if(idxPeriod > 0)
  3788. {
  3789. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3790. {
  3791. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3792. }
  3793. }
  3794. }
  3795. }
  3796. }
  3797. else
  3798. {
  3799. if(maxProfile.ChargingSchedule.Duration != -1)
  3800. {
  3801. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3802. 0:
  3803. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3804. }
  3805. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3806. {
  3807. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3808. {
  3809. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3810. 0:
  3811. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3812. if(idxPeriod > 0)
  3813. {
  3814. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3815. {
  3816. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3817. }
  3818. }
  3819. }
  3820. }
  3821. }
  3822. }
  3823. /*
  3824. DEBUG_INFO("MaxProfile after align.\n");
  3825. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3826. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3827. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3828. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3829. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3830. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3831. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3832. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3833. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3834. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3835. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3836. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3837. {
  3838. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3839. {
  3840. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3841. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3842. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3843. }
  3844. }
  3845. DEBUG_INFO("------------------------------------\n");*/
  3846. }
  3847. /*
  3848. * Merge to composite schedule
  3849. */
  3850. //DEBUG_INFO("====================================\n");
  3851. // Find each profile period quantity
  3852. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3853. {
  3854. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3855. limitMax = idx+1;
  3856. }
  3857. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3858. {
  3859. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3860. limitDef = idx+1;
  3861. }
  3862. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3863. {
  3864. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3865. limitTx = idx+1;
  3866. }
  3867. // TxProfile found, composite schedule based on it
  3868. if(txProfile.ChargingProfileId != -1)
  3869. {
  3870. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3871. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3872. {
  3873. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3874. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3875. (txProfile.ChargingSchedule.Duration > 0))
  3876. {
  3877. if(maxProfile.ChargingProfileId != -1)
  3878. {
  3879. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3880. {
  3881. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3882. {
  3883. if((maxProfile.ChargingSchedule.Duration > 0))
  3884. {
  3885. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3886. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3887. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3888. }
  3889. else
  3890. {
  3891. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3892. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3893. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3894. }
  3895. }
  3896. if(idxMaxPeriod == (limitMax-1))
  3897. {
  3898. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3899. {
  3900. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3901. {
  3902. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3903. compositePeriodIdx++;
  3904. }
  3905. else
  3906. {
  3907. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3908. }
  3909. }
  3910. }
  3911. }
  3912. }
  3913. else
  3914. {
  3915. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3916. {
  3917. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3918. compositePeriodIdx++;
  3919. }
  3920. else
  3921. {
  3922. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3923. }
  3924. }
  3925. }
  3926. if(idxTxPeriod == (limitTx-1))
  3927. {
  3928. if(defaultTxProfile.ChargingProfileId != -1)
  3929. {
  3930. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3931. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3932. {
  3933. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3934. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3935. (defaultTxProfile.ChargingSchedule.Duration>0))
  3936. {
  3937. if(maxProfile.ChargingProfileId != -1)
  3938. {
  3939. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3940. {
  3941. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3942. {
  3943. if((maxProfile.ChargingSchedule.Duration > 0))
  3944. {
  3945. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3946. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3947. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3948. }
  3949. else
  3950. {
  3951. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3952. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3953. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3954. }
  3955. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3956. {
  3957. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3958. {
  3959. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3960. compositePeriodIdx++;
  3961. }
  3962. else
  3963. {
  3964. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3965. }
  3966. }
  3967. // Delete duplicate period
  3968. if(compositePeriodIdx > 1)
  3969. {
  3970. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3971. {
  3972. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3973. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3974. compositePeriodIdx -= 1;
  3975. }
  3976. }
  3977. }
  3978. else
  3979. {
  3980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3981. {
  3982. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3983. compositePeriodIdx++;
  3984. }
  3985. else
  3986. {
  3987. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3988. }
  3989. break;
  3990. }
  3991. }
  3992. }
  3993. else
  3994. {
  3995. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3996. {
  3997. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3998. compositePeriodIdx++;
  3999. }
  4000. else
  4001. {
  4002. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4003. }
  4004. }
  4005. }
  4006. }
  4007. }
  4008. }
  4009. }
  4010. }
  4011. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4012. else if(defaultTxProfile.ChargingProfileId != -1)
  4013. {
  4014. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  4015. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4016. {
  4017. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  4018. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  4019. (defaultTxProfile.ChargingSchedule.Duration > 0))
  4020. {
  4021. if(maxProfile.ChargingProfileId != -1)
  4022. {
  4023. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4024. {
  4025. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4026. {
  4027. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4028. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4029. if((maxProfile.ChargingSchedule.Duration > 0))
  4030. {
  4031. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  4032. }
  4033. else
  4034. {
  4035. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4036. }
  4037. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4038. {
  4039. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4040. {
  4041. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4042. compositePeriodIdx++;
  4043. }
  4044. else
  4045. {
  4046. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4047. }
  4048. }
  4049. // Delete duplicate period
  4050. if(compositePeriodIdx > 1)
  4051. {
  4052. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4053. {
  4054. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4055. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4056. compositePeriodIdx -= 1;
  4057. }
  4058. }
  4059. }
  4060. else
  4061. {
  4062. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4063. {
  4064. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4065. compositePeriodIdx++;
  4066. }
  4067. else
  4068. {
  4069. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4070. }
  4071. break;
  4072. }
  4073. }
  4074. }
  4075. else
  4076. {
  4077. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4078. {
  4079. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4080. compositePeriodIdx++;
  4081. }
  4082. else
  4083. {
  4084. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4085. }
  4086. }
  4087. }
  4088. }
  4089. }
  4090. // Fill other period by MaxProfile
  4091. if(maxProfile.ChargingProfileId != -1)
  4092. {
  4093. if(compositePeriodIdx==0)
  4094. {
  4095. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4096. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  4097. {
  4098. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4099. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4100. (maxProfile.ChargingSchedule.Duration > 0))
  4101. {
  4102. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4103. {
  4104. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4105. compositePeriodIdx++;
  4106. }
  4107. else
  4108. {
  4109. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4110. }
  4111. }
  4112. }
  4113. }
  4114. else
  4115. {
  4116. int lastCompositePeriodIdx = compositePeriodIdx;
  4117. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4118. {
  4119. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4120. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4121. (maxProfile.ChargingSchedule.Duration > 0))
  4122. {
  4123. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  4124. {
  4125. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  4126. {
  4127. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4128. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4129. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  4130. }
  4131. else
  4132. {
  4133. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4134. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4135. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  4136. }
  4137. }
  4138. if(tmpPeriod.Limit != -1)
  4139. {
  4140. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  4141. {
  4142. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  4143. {
  4144. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4145. compositePeriodIdx++;
  4146. }
  4147. else
  4148. {
  4149. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4150. }
  4151. }
  4152. // Delete duplicate period
  4153. if(compositePeriodIdx > 1)
  4154. {
  4155. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4156. {
  4157. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4158. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4159. compositePeriodIdx -= 1;
  4160. }
  4161. }
  4162. }
  4163. }
  4164. }
  4165. }
  4166. }
  4167. if(compositeProfile.ChargingSchedule.Duration < durationReq)
  4168. {
  4169. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4170. {
  4171. if((idxPeriod > 0) && (compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == 0 || compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1))
  4172. {
  4173. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = compositeProfile.ChargingSchedule.Duration;
  4174. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  4175. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].NumberPhases;
  4176. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  4177. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4178. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4179. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4180. DEBUG_INFO("------------------------------------------------\n");
  4181. break;
  4182. }
  4183. }
  4184. }
  4185. compositeProfile.ChargingSchedule.Duration = durationReq;
  4186. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4187. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4188. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4189. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4190. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4191. {
  4192. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4193. {
  4194. compositeProfile.ChargingProfileId = 1;
  4195. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4196. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4197. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4198. }
  4199. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4200. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4201. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4202. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4203. }
  4204. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4205. if(line)
  4206. free(line);
  4207. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4208. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4209. }
  4210. //==========================================
  4211. // Init all share memory
  4212. //==========================================
  4213. int InitShareMemory()
  4214. {
  4215. int result = PASS;
  4216. int MeterSMId;
  4217. //creat ShmSysConfigAndInfo
  4218. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4219. {
  4220. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4221. result = FAIL;
  4222. }
  4223. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4224. {
  4225. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4226. result = FAIL;
  4227. }
  4228. else
  4229. {}
  4230. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4231. {
  4232. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4233. result = FAIL;
  4234. }
  4235. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4236. {
  4237. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4238. result = FAIL;
  4239. }
  4240. else
  4241. {}
  4242. //creat ShmPsuData
  4243. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4244. {
  4245. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4246. result = FAIL;
  4247. }
  4248. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4249. {
  4250. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4251. result = FAIL;
  4252. }
  4253. else
  4254. {}
  4255. //creat ShmOCPP16Data
  4256. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4257. {
  4258. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4259. result = FAIL;
  4260. }
  4261. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4262. {
  4263. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4264. result = FAIL;
  4265. }
  4266. else
  4267. {}
  4268. /****************************** For Initial Settings************************************************/
  4269. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4270. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4271. // allocate Configuration memory address
  4272. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4273. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4274. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4275. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4276. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4277. //offline MeterValue Interval
  4278. TempMeterValueInterval = 0;
  4279. return result;
  4280. }
  4281. int ProcessShareMemory()
  4282. {
  4283. int result = PASS;
  4284. if(InitShareMemory() == FAIL)
  4285. {
  4286. DEBUG_ERROR("InitShareMemory NG\n");
  4287. if(ShmStatusCodeData!=NULL)
  4288. {
  4289. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4290. }
  4291. result = FAIL;
  4292. }
  4293. // Model name parsing
  4294. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4295. {
  4296. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4297. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4298. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4299. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4300. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  4301. ) // 'D' means DC
  4302. {
  4303. // DO series
  4304. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4305. {
  4306. gunTotalNumber += 1;
  4307. gunType[gun_index] = GUN_TYPE_DO;
  4308. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4309. {
  4310. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4311. {
  4312. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4313. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4314. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4315. }
  4316. }
  4317. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4318. {
  4319. case Gun_Type_Chademo:
  4320. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4321. break;
  4322. case Gun_Type_CCS_2:
  4323. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4324. break;
  4325. case Gun_Type_GB:
  4326. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4327. break;
  4328. case Gun_Type_AC:
  4329. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4330. break;
  4331. default:
  4332. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4333. break;
  4334. }
  4335. }
  4336. }
  4337. else
  4338. {
  4339. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4340. {
  4341. gunTotalNumber += 1;
  4342. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4343. {
  4344. case Gun_Type_Chademo:
  4345. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4346. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4347. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4348. {
  4349. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4350. {
  4351. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4352. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4353. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4354. }
  4355. }
  4356. break;
  4357. case Gun_Type_CCS_2:
  4358. gunType[gun_index] = GUN_TYPE_CCS;
  4359. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4360. for (int index = 0; index < CCS_QUANTITY; index++)
  4361. {
  4362. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4363. {
  4364. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4365. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4366. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4367. }
  4368. }
  4369. break;
  4370. case Gun_Type_GB:
  4371. gunType[gun_index] = GUN_TYPE_GBT;
  4372. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4373. for (int index = 0; index < GB_QUANTITY; index++)
  4374. {
  4375. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4376. {
  4377. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4378. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4379. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4380. }
  4381. }
  4382. break;
  4383. case Gun_Type_AC:
  4384. gunType[gun_index] = GUN_TYPE_AC;
  4385. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4386. for (int index = 0; index < AC_QUANTITY; index++)
  4387. {
  4388. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4389. {
  4390. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4391. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4392. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4393. }
  4394. }
  4395. break;
  4396. default:
  4397. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4398. break;
  4399. }
  4400. }
  4401. }
  4402. }
  4403. else
  4404. {
  4405. DEBUG_ERROR("Model name parsing fail.\n");
  4406. result = FAIL;
  4407. }
  4408. if(result != PASS)sleep(5);
  4409. return result;
  4410. }
  4411. void checkRemoteStart(uint8_t connectorIdInt)
  4412. {
  4413. uint8_t tempIndex;
  4414. int result = PASS;
  4415. char cmdBuf[512];
  4416. //check Transaction active
  4417. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4418. {
  4419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4420. {
  4421. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4422. }
  4423. else
  4424. {
  4425. tempIndex = connectorIdInt -1;
  4426. }
  4427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4428. {
  4429. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4430. {
  4431. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4432. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4433. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4434. {
  4435. //Reserved
  4436. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4437. }
  4438. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4439. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4440. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4441. {
  4442. //Reserved
  4443. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4444. result = FAIL;
  4445. goto end;
  4446. }
  4447. else
  4448. {
  4449. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4450. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4451. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4452. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4453. {
  4454. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4455. result = FAIL;
  4456. goto end;
  4457. }
  4458. }//END FOR ELSE
  4459. }
  4460. }// END FOR CHAdeMO_QUANTITY
  4461. }
  4462. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4463. {
  4464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4465. {
  4466. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4467. }
  4468. else
  4469. {
  4470. tempIndex = connectorIdInt -1;
  4471. }
  4472. for (int index = 0; index < CCS_QUANTITY; index++)
  4473. {
  4474. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4475. {
  4476. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4477. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4478. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4479. {
  4480. //Reserved
  4481. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4482. }
  4483. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4484. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4485. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4486. {
  4487. //Reserved
  4488. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4489. result = FAIL;
  4490. goto end;
  4491. }
  4492. else
  4493. {
  4494. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4495. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4496. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4497. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4498. {
  4499. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4500. result = FAIL;
  4501. goto end;
  4502. }
  4503. }// END FOR ELSE
  4504. }
  4505. }// END FOR CCS_QUANTITY
  4506. }
  4507. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4508. {
  4509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4510. {
  4511. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4512. }
  4513. else
  4514. {
  4515. tempIndex = connectorIdInt -1;
  4516. }
  4517. for (int index = 0; index < GB_QUANTITY; index++)
  4518. {
  4519. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4520. {
  4521. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4522. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4523. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4524. {
  4525. //Reserved
  4526. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4527. }
  4528. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4529. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4530. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4531. {
  4532. //Reserved
  4533. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4534. result = FAIL;
  4535. goto end;
  4536. }
  4537. else
  4538. {
  4539. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4540. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4541. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4542. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4543. {
  4544. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4545. result = FAIL;
  4546. goto end;
  4547. }
  4548. }// END FOR ELSE
  4549. }
  4550. } // END FOR GB_QUANTITY
  4551. }
  4552. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4553. {
  4554. tempIndex = connectorIdInt -1;
  4555. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4556. {
  4557. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4558. {
  4559. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4560. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4561. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4562. {
  4563. //Reserved
  4564. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4565. }
  4566. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4567. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4568. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4569. {
  4570. //Reserved
  4571. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4572. result = FAIL;
  4573. goto end;
  4574. }
  4575. else
  4576. {
  4577. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4578. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4579. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4580. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4581. {
  4582. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4583. result = FAIL;
  4584. goto end;
  4585. }
  4586. }// END FOR ELSE
  4587. }
  4588. } // END FOR GB_QUANTITY
  4589. }
  4590. else
  4591. {
  4592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4593. {
  4594. tempIndex = 2;
  4595. }
  4596. else
  4597. {
  4598. tempIndex = connectorIdInt -1;
  4599. }
  4600. for (int index = 0; index < AC_QUANTITY; index++)
  4601. {
  4602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4603. {
  4604. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4605. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4606. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4607. {
  4608. //Reserved
  4609. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4610. }
  4611. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4612. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4613. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4614. {
  4615. //Reserved
  4616. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4617. result = FAIL;
  4618. goto end;
  4619. }
  4620. else
  4621. {
  4622. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4623. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4624. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4625. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4626. {
  4627. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4628. result = FAIL;
  4629. goto end;
  4630. }
  4631. }//END FOR ELSE
  4632. }
  4633. }// END FOR AC_QUANTITY
  4634. }
  4635. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4636. {
  4637. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4638. {
  4639. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4640. {
  4641. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4642. system(cmdBuf);
  4643. }
  4644. }
  4645. else
  4646. {
  4647. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4648. result = FAIL;
  4649. }
  4650. }
  4651. end:
  4652. if(result == PASS)
  4653. {
  4654. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4655. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4656. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4657. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4658. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4659. }
  4660. }
  4661. int isConnector0Unavailable()
  4662. {
  4663. uint8_t result = YES;
  4664. uint8_t tempIndex;
  4665. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4666. {
  4667. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4668. {
  4669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4670. {
  4671. tempIndex = ((gun_index==2) ? 1: 0);
  4672. }
  4673. else
  4674. {
  4675. tempIndex = gun_index;
  4676. }
  4677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4678. {
  4679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4680. {
  4681. 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))
  4682. {
  4683. result = NO;
  4684. }
  4685. }
  4686. }
  4687. }
  4688. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4689. {
  4690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4691. {
  4692. tempIndex = ((gun_index==2) ? 1: 0);
  4693. }
  4694. else
  4695. {
  4696. tempIndex = gun_index;
  4697. }
  4698. for (int index = 0; index < CCS_QUANTITY; index++)
  4699. {
  4700. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4701. {
  4702. 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))
  4703. {
  4704. result = NO;
  4705. }
  4706. }
  4707. }
  4708. }
  4709. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4710. {
  4711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4712. {
  4713. tempIndex = ((gun_index==2) ? 1: 0);
  4714. }
  4715. else
  4716. {
  4717. tempIndex = gun_index;
  4718. }
  4719. for (int index = 0; index < GB_QUANTITY; index++)
  4720. {
  4721. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4722. {
  4723. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_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))
  4724. {
  4725. result = NO;
  4726. }
  4727. }
  4728. }
  4729. }
  4730. else if(gunType[gun_index] == GUN_TYPE_DO)
  4731. {
  4732. tempIndex = gun_index;
  4733. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4734. {
  4735. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4736. {
  4737. 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))
  4738. {
  4739. result = NO;
  4740. }
  4741. }
  4742. }
  4743. }
  4744. else
  4745. {
  4746. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4747. {
  4748. tempIndex = 2;
  4749. }
  4750. else
  4751. {
  4752. tempIndex = gun_index;
  4753. }
  4754. for (int index = 0; index < AC_QUANTITY; index++)
  4755. {
  4756. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4757. {
  4758. 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))
  4759. {
  4760. result = NO;
  4761. }
  4762. }
  4763. }// END
  4764. }
  4765. }
  4766. return result;
  4767. }
  4768. void CheckSystemValue(void)
  4769. {
  4770. char filenmae[100]={0};
  4771. char str[100]={0};
  4772. int tempIndex = 0;
  4773. //===============================
  4774. // send Heartbeat
  4775. //===============================
  4776. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4777. {
  4778. //parameter for test
  4779. sendHeartbeatRequest(0);
  4780. //===========================
  4781. // Reset Waiting Time
  4782. //===========================
  4783. HeartBeatWithNOResponse += 1;
  4784. }
  4785. //===============================
  4786. // Tcci credit deduct report
  4787. //===============================
  4788. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4789. {
  4790. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4791. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4792. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4793. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4794. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4795. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4796. }
  4797. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4798. {
  4799. OCPP_query_deduct_info();
  4800. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4801. }
  4802. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4803. {
  4804. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4805. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4806. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4807. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4808. }
  4809. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4810. {
  4811. OCPP_query_occupancyDeduct_info();
  4812. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4813. }
  4814. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4815. {
  4816. // ClockAlign MeterValue
  4817. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4818. {
  4819. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4820. {
  4821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4822. {
  4823. tempIndex = ((gun_index==2) ? 1: 0);
  4824. }
  4825. else
  4826. {
  4827. tempIndex = gun_index;
  4828. }
  4829. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4830. {
  4831. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4832. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4833. {
  4834. reqClockAlignMeter[gun_index] = 1;
  4835. }
  4836. }// End for CHAdeMO
  4837. }
  4838. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4839. {
  4840. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4841. {
  4842. tempIndex = ((gun_index==2) ? 1: 0);
  4843. }
  4844. else
  4845. {
  4846. tempIndex = gun_index;
  4847. }
  4848. for (int index = 0; index < CCS_QUANTITY; index++)
  4849. {
  4850. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4851. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4852. {
  4853. reqClockAlignMeter[gun_index] = 1;
  4854. }
  4855. } // End for CCS
  4856. }
  4857. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4858. {
  4859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4860. {
  4861. tempIndex = ((gun_index==2) ? 1: 0);
  4862. }
  4863. else
  4864. {
  4865. tempIndex = gun_index;
  4866. }
  4867. for (int index = 0; index < GB_QUANTITY; index++)
  4868. {
  4869. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4870. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4871. {
  4872. reqClockAlignMeter[gun_index] = 1;
  4873. }
  4874. }// End for GB
  4875. }
  4876. else if(gunType[gun_index] == GUN_TYPE_DO)
  4877. {
  4878. tempIndex = gun_index;
  4879. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4880. {
  4881. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4882. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4883. {
  4884. reqClockAlignMeter[gun_index] = 1;
  4885. }
  4886. }
  4887. }
  4888. else
  4889. {
  4890. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4891. {
  4892. tempIndex = 2;
  4893. }
  4894. else
  4895. {
  4896. tempIndex = gun_index;
  4897. }
  4898. for (int index = 0; index < AC_QUANTITY; index++)
  4899. {
  4900. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4901. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4902. {
  4903. reqClockAlignMeter[gun_index] = 1;
  4904. }
  4905. }//End for AC
  4906. }
  4907. }
  4908. }
  4909. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4910. {
  4911. //==========================================
  4912. // Check remote start without connector id
  4913. //==========================================
  4914. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4915. {
  4916. int connectorIdInt = -1;
  4917. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4918. {
  4919. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4920. {
  4921. connectorIdInt = (gun_index+1);
  4922. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4923. checkRemoteStart(connectorIdInt);
  4924. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4925. break;
  4926. }
  4927. }
  4928. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4929. {
  4930. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4931. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4932. }
  4933. }
  4934. //==========================================
  4935. // csu trigger DataTransferReq
  4936. //==========================================
  4937. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4938. {
  4939. sendDataTransferRequest(gun_index);
  4940. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4941. }
  4942. //==========================================
  4943. // CSU Trigger Authorize Request
  4944. //==========================================
  4945. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4946. {
  4947. sendAuthorizeRequest(0);
  4948. authorizeRetryTimes = authorizeRetryTimes + 1;
  4949. if(authorizeRetryTimes < 3)
  4950. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4951. }
  4952. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4953. {
  4954. authorizeRetryTimes = 0;
  4955. SetOcppConnStatus(FALSE);
  4956. server_sign = FALSE;
  4957. }
  4958. 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))
  4959. {
  4960. sendAuthorizeRequest(0);
  4961. }
  4962. //==========================================
  4963. // Charger start transaction
  4964. //==========================================
  4965. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4966. {
  4967. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4968. meterValueBufferClear(gun_index);
  4969. sendStartTransactionRequest(gun_index);
  4970. refreshStartTimer(&clientTime.StartTransaction);
  4971. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4972. storeTempStopTransaction(gun_index);
  4973. }
  4974. //==========================================
  4975. // Charger stop transaction
  4976. //==========================================
  4977. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4978. {
  4979. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4980. sendStopTransactionRequest(gun_index);
  4981. OCPP_updatePeriodEnergy(gun_index);
  4982. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4983. refreshStartTimer(&clientTime.StopTransaction);
  4984. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4985. }
  4986. //==========================================
  4987. // Charger OCMF message
  4988. //==========================================
  4989. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  4990. {
  4991. sendOcmfByDataTransferRequest(gun_index);
  4992. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  4993. }
  4994. //==========================================
  4995. // Charger status report
  4996. //==========================================
  4997. //--- Check Mode Change ---//
  4998. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4999. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5000. {
  5001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5002. {
  5003. tempIndex = ((gun_index==2) ? 1: 0);
  5004. }
  5005. else
  5006. {
  5007. tempIndex = gun_index;
  5008. }
  5009. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5010. {
  5011. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5012. {
  5013. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5014. {
  5015. // Sent unplug message for California pricing logic
  5016. 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])
  5017. {
  5018. uint8_t ts[36];
  5019. getNowDatetime(ts);
  5020. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5021. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5022. if(strcmp((char*)dmsVersion, "2.0")==0)
  5023. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5024. else
  5025. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5026. sendUnplugByDataTransferRequest(gun_index);
  5027. interLock.isSentUnplug[gun_index] = 1;
  5028. }
  5029. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5030. {
  5031. interLock.isSentUnplug[gun_index] = 0;
  5032. }
  5033. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5034. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5035. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5036. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5037. {
  5038. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5039. if((access(filenmae,F_OK))!=-1)
  5040. {
  5041. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5042. sprintf(str,"rm -f %s",filenmae);
  5043. system(str);
  5044. }
  5045. }
  5046. }
  5047. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5048. #if 1 // for TempStopTransaction
  5049. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5050. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5051. {
  5052. checkTempStopTransaction(gun_index);
  5053. }
  5054. #endif
  5055. }
  5056. }
  5057. }
  5058. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5059. {
  5060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5061. {
  5062. tempIndex = ((gun_index==2) ? 1: 0);
  5063. }
  5064. else
  5065. {
  5066. tempIndex = gun_index;
  5067. }
  5068. for (int index = 0; index < CCS_QUANTITY; index++)
  5069. {
  5070. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5071. {
  5072. 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]*/ )
  5073. {
  5074. // Sent unplug message for California pricing logic
  5075. 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])
  5076. {
  5077. uint8_t ts[36];
  5078. getNowDatetime(ts);
  5079. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5080. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5081. if(strcmp((char*)dmsVersion, "2.0")==0)
  5082. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5083. else
  5084. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5085. sendUnplugByDataTransferRequest(gun_index);
  5086. interLock.isSentUnplug[gun_index] = 1;
  5087. }
  5088. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5089. {
  5090. interLock.isSentUnplug[gun_index] = 0;
  5091. }
  5092. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5093. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5094. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5095. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5096. {
  5097. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5098. if((access(filenmae,F_OK))!=-1)
  5099. {
  5100. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5101. sprintf(str,"rm -f %s",filenmae);
  5102. system(str);
  5103. }
  5104. }
  5105. }
  5106. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5107. #if 1 // for TempStopTransaction
  5108. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5109. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5110. {
  5111. checkTempStopTransaction(gun_index);
  5112. }
  5113. #endif
  5114. }
  5115. }
  5116. }
  5117. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5118. {
  5119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5120. {
  5121. tempIndex = ((gun_index==2) ? 1: 0);
  5122. }
  5123. else
  5124. {
  5125. tempIndex = gun_index;
  5126. }
  5127. for (int index = 0; index < GB_QUANTITY; index++)
  5128. {
  5129. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5130. {
  5131. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5132. {
  5133. // Sent unplug message for California pricing logic
  5134. 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])
  5135. {
  5136. uint8_t ts[36];
  5137. getNowDatetime(ts);
  5138. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5139. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5140. if(strcmp((char*)dmsVersion, "2.0")==0)
  5141. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5142. else
  5143. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5144. sendUnplugByDataTransferRequest(gun_index);
  5145. interLock.isSentUnplug[gun_index] = 1;
  5146. }
  5147. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5148. {
  5149. interLock.isSentUnplug[gun_index] = 0;
  5150. }
  5151. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5152. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5153. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5154. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5155. {
  5156. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5157. if((access(filenmae,F_OK))!=-1)
  5158. {
  5159. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5160. sprintf(str,"rm -f %s",filenmae);
  5161. system(str);
  5162. }
  5163. }
  5164. }
  5165. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5166. #if 1 // for TempStopTransaction
  5167. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5168. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5169. {
  5170. checkTempStopTransaction(gun_index);
  5171. }
  5172. #endif
  5173. }
  5174. }
  5175. }
  5176. else if(gunType[gun_index] == GUN_TYPE_DO)
  5177. {
  5178. tempIndex = gun_index;
  5179. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5180. {
  5181. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5182. {
  5183. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5184. {
  5185. // Sent unplug message for California pricing logic
  5186. 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])
  5187. {
  5188. uint8_t ts[36];
  5189. getNowDatetime(ts);
  5190. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5191. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5192. if(strcmp((char*)dmsVersion, "2.0")==0)
  5193. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5194. else
  5195. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5196. sendUnplugByDataTransferRequest(gun_index);
  5197. interLock.isSentUnplug[gun_index] = 1;
  5198. }
  5199. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  5200. {
  5201. interLock.isSentUnplug[gun_index] = 0;
  5202. }
  5203. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5204. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5205. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5206. 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
  5207. {
  5208. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5209. if((access(filenmae,F_OK))!=-1)
  5210. {
  5211. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5212. sprintf(str,"rm -f %s",filenmae);
  5213. system(str);
  5214. }
  5215. }
  5216. }
  5217. 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);
  5218. #if 1 // for TempStopTransaction
  5219. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5220. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5221. {
  5222. checkTempStopTransaction(gun_index);
  5223. }
  5224. #endif
  5225. }
  5226. }
  5227. }
  5228. else
  5229. {
  5230. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5231. {
  5232. tempIndex = 2;
  5233. }
  5234. else
  5235. {
  5236. tempIndex = gun_index;
  5237. }
  5238. for (int index = 0; index < AC_QUANTITY; index++)
  5239. {
  5240. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5241. {
  5242. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5243. {
  5244. // Sent unplug message for California pricing logic
  5245. 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])
  5246. {
  5247. uint8_t ts[36];
  5248. getNowDatetime(ts);
  5249. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5250. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5251. if(strcmp((char*)dmsVersion, "2.0")==0)
  5252. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5253. else
  5254. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5255. sendUnplugByDataTransferRequest(gun_index);
  5256. interLock.isSentUnplug[gun_index] = 1;
  5257. }
  5258. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5259. {
  5260. interLock.isSentUnplug[gun_index] = 0;
  5261. }
  5262. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5263. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5264. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5265. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5266. {
  5267. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5268. if((access(filenmae,F_OK))!=-1)
  5269. {
  5270. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5271. sprintf(str,"rm -f %s",filenmae);
  5272. system(str);
  5273. }
  5274. }
  5275. }
  5276. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5277. #if 1 // for TempStopTransaction
  5278. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5279. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5280. {
  5281. checkTempStopTransaction(gun_index);
  5282. }
  5283. #endif
  5284. }
  5285. }// END
  5286. }
  5287. if(isWebsocketSendable && (server_sign == TRUE) && (isConnector0Unavailable() != Connector0PreviousSystemStatus))
  5288. {
  5289. sendConnector0StatusNotificationRequest();
  5290. Connector0PreviousSystemStatus = isConnector0Unavailable();
  5291. }
  5292. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5293. (
  5294. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5295. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5296. )
  5297. )
  5298. {
  5299. sendStatusNotificationRequest(gun_index);
  5300. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5301. }
  5302. //==============================================
  5303. // TCCI related DataTransfer messages
  5304. //==============================================
  5305. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5306. {
  5307. reportReaderStatus(gun_index);
  5308. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5309. }
  5310. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.GetOccupancyFee[gun_index].GetOccupancyFeeReq == 1))
  5311. {
  5312. getOccupancyFee(gun_index);
  5313. }
  5314. //==============================================
  5315. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5316. //==============================================
  5317. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5318. ((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))))
  5319. {
  5320. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5321. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5322. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5323. }
  5324. //==============================================
  5325. // Meter report
  5326. //==============================================
  5327. // Trigger MeterValue
  5328. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5329. {
  5330. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5331. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5332. }
  5333. // Clock-aligned Meter value
  5334. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5335. {
  5336. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5337. reqClockAlignMeter[gun_index] = 0;
  5338. }
  5339. // Sample period MeterValue
  5340. 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))))
  5341. {
  5342. //check Transaction active
  5343. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5344. {
  5345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5346. {
  5347. tempIndex = ((gun_index==2) ? 1: 0);
  5348. }
  5349. else
  5350. {
  5351. tempIndex = gun_index;
  5352. }
  5353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5354. {
  5355. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5356. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5357. {
  5358. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5359. {
  5360. reqSampleMeter[gun_index] = 1;
  5361. }
  5362. }
  5363. }// End for CHAdeMO
  5364. }
  5365. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5366. {
  5367. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5368. {
  5369. tempIndex = ((gun_index==2) ? 1: 0);
  5370. }
  5371. else
  5372. {
  5373. tempIndex = gun_index;
  5374. }
  5375. for (int index = 0; index < CCS_QUANTITY; index++)
  5376. {
  5377. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5378. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5379. {
  5380. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5381. {
  5382. reqSampleMeter[gun_index] = 1;
  5383. }
  5384. }
  5385. } // End for CCS
  5386. }
  5387. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5388. {
  5389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5390. {
  5391. tempIndex = ((gun_index==2) ? 1: 0);
  5392. }
  5393. else
  5394. {
  5395. tempIndex = gun_index;
  5396. }
  5397. for (int index = 0; index < GB_QUANTITY; index++)
  5398. {
  5399. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5400. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5401. {
  5402. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5403. {
  5404. reqSampleMeter[gun_index] = 1;
  5405. }
  5406. }
  5407. }// End for GB
  5408. }
  5409. else if(gunType[gun_index] == GUN_TYPE_DO)
  5410. {
  5411. tempIndex = gun_index;
  5412. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5413. {
  5414. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5415. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5416. {
  5417. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5418. {
  5419. reqSampleMeter[gun_index] = 1;
  5420. }
  5421. }
  5422. }
  5423. }
  5424. else
  5425. {
  5426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5427. {
  5428. tempIndex = 2;
  5429. }
  5430. else
  5431. {
  5432. tempIndex = gun_index;
  5433. }
  5434. for (int index = 0; index < AC_QUANTITY; index++)
  5435. {
  5436. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5437. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5438. {
  5439. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5440. {
  5441. reqSampleMeter[gun_index] = 1;
  5442. }
  5443. }
  5444. }//End for AC
  5445. }
  5446. if(reqSampleMeter[gun_index] == 1)
  5447. {
  5448. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5449. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5450. storeTempStopTransaction(gun_index);
  5451. reqSampleMeter[gun_index] = 0;
  5452. }
  5453. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5454. }
  5455. //==============================================
  5456. // Check Connector reserved
  5457. //==============================================
  5458. //===============================
  5459. // Check if Reserve is expired
  5460. //===============================
  5461. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5462. {
  5463. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5464. {
  5465. DEBUG_INFO("reserve expired.\n");
  5466. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5467. }
  5468. }//END OF Check if Reserve is expired
  5469. //==========================================
  5470. // csu trigger FirmwareStatusNotificationReq
  5471. //==========================================
  5472. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5473. {
  5474. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5475. }
  5476. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5477. {
  5478. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5479. }
  5480. //==========================================
  5481. // csu trigger DiagnosticsStatusNotificationReq
  5482. //==========================================
  5483. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5484. {
  5485. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5486. }
  5487. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5488. {
  5489. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5490. }
  5491. //==========================================
  5492. // csu trigger CancelReservationConf
  5493. //==========================================
  5494. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5495. {
  5496. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5497. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5498. }
  5499. //==========================================
  5500. // csu trigger ChangeAvailabilityConf
  5501. //==========================================
  5502. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5503. {
  5504. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5505. }
  5506. //==========================================
  5507. // csu trigger UnlockConnectorConf
  5508. //==========================================
  5509. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5510. {
  5511. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5512. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5513. }
  5514. //==========================================
  5515. // csu trigger ReserveNowConf
  5516. //==========================================
  5517. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5518. {
  5519. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5520. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5521. }
  5522. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5523. {
  5524. sendSignCertificateRequest();
  5525. }
  5526. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5527. {
  5528. sendSecurityEventNotificationRequest();
  5529. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5530. }
  5531. // Support 15118
  5532. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5533. {
  5534. json_object *data = json_object_new_object();
  5535. // Read csr file content
  5536. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5537. FILE *fp=fopen(CSR_V2G,"r");
  5538. char *line = NULL;
  5539. size_t len = 0;
  5540. while(getline(&line, &len, fp) != -1)
  5541. {
  5542. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5543. {
  5544. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5545. }
  5546. }
  5547. fclose(fp);
  5548. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5549. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5550. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5551. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5552. json_object_put(data);
  5553. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5554. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5555. }
  5556. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5557. {
  5558. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5559. int parseCertResult = FAIL;
  5560. json_object *data = json_object_new_object();
  5561. json_object *idToken = json_object_new_object();
  5562. json_object *iso15118CertificateHashData = json_object_new_array();
  5563. // Read CERTIFICATE_PnCAuth file content
  5564. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5565. {
  5566. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5567. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5568. char *line = NULL;
  5569. size_t len = 0;
  5570. while(getline(&line, &len, fp) != -1)
  5571. {
  5572. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5573. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5574. }
  5575. fclose(fp);
  5576. }
  5577. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5578. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5579. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5580. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5581. json_object_object_add(data, "idToken", idToken);
  5582. char parseData[512] = {0};
  5583. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5584. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5585. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5586. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5587. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5588. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5589. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5590. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5591. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5592. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5593. for(int idx=0; idx < 4; idx++)
  5594. {
  5595. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5596. {
  5597. json_object *OCSPRequestDataType = json_object_new_object();
  5598. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5599. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5600. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5601. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5602. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5603. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5604. parseCertResult = PASS;
  5605. }
  5606. }
  5607. if(parseCertResult == PASS)
  5608. {
  5609. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5610. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5611. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5612. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5613. json_object_put(data);
  5614. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5615. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5616. }
  5617. else
  5618. {
  5619. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5620. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5621. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5622. }
  5623. }
  5624. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5625. {
  5626. json_object *data = json_object_new_object();
  5627. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5628. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5629. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5630. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5631. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5632. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5633. json_object_put(data);
  5634. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5635. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5636. }
  5637. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5638. {
  5639. json_object *data = json_object_new_object();
  5640. json_object *OCSPRequestDataType = json_object_new_object();
  5641. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5642. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5643. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5644. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5645. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5646. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5647. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5648. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5649. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5650. json_object_put(data);
  5651. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5652. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5653. }
  5654. }
  5655. }
  5656. //==========================================
  5657. // send request routine
  5658. //==========================================
  5659. int sendAuthorizeRequest(int gun_index)
  5660. {
  5661. mtrace();
  5662. int result = FAIL;
  5663. char message[100]={0};
  5664. char guid[37];
  5665. char tempdata[65]={0};
  5666. DEBUG_INFO("sendAuthorizeRequest...\n");
  5667. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5668. //Local Authorize
  5669. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5670. {
  5671. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5672. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5673. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5674. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5675. result = PASS;
  5676. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5677. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5678. authorizeRetryTimes = 0;
  5679. return result;
  5680. }
  5681. 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))||
  5682. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5683. {
  5684. // Query from cache
  5685. DEBUG_INFO("Authorize from cache.\n");
  5686. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5687. // Query from list
  5688. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5689. {
  5690. DEBUG_INFO("Authorize from list.\n");
  5691. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5692. }
  5693. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5694. {
  5695. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5696. {
  5697. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5698. }
  5699. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5700. {
  5701. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5702. }
  5703. if(!GetOcppConnStatus())
  5704. {
  5705. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5706. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5707. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5708. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5709. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5710. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5711. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5712. authorizeRetryTimes = 0;
  5713. return result;
  5714. }
  5715. }
  5716. else
  5717. {
  5718. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5719. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5720. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5721. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5722. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5723. else
  5724. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5725. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5726. result = PASS;
  5727. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5728. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5729. authorizeRetryTimes = 0;
  5730. return result;
  5731. }
  5732. }
  5733. //initialize struct Authorize
  5734. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5735. //get data from shared memory
  5736. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5737. random_uuid(guid);
  5738. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5739. LWS_Send(message);
  5740. sprintf(tempdata, "Authorize,%d", gun_index);
  5741. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5742. {
  5743. result = PASS;
  5744. DEBUG_INFO("Authorize mapItem pass\n");
  5745. }
  5746. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5747. return result;
  5748. }
  5749. int sendBootNotificationRequest(void)
  5750. {
  5751. mtrace();
  5752. int result = FAIL;
  5753. char message[500]={0}, payload[700]={0};
  5754. char guid[37]={0};
  5755. char tempdata[65]={0};
  5756. // Fill BootNotification fields
  5757. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5758. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5759. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5760. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5761. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5762. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5763. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5764. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5765. ShmOCPP16Data->ChargeBoxId
  5766. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5767. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5768. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5769. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5770. ,ShmOCPP16Data->BootNotification.CpIccid
  5771. ,ShmOCPP16Data->BootNotification.CpImsi);
  5772. random_uuid(guid);
  5773. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5774. LWS_Send(message);
  5775. sprintf(tempdata, "BootNotification,0");
  5776. 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*/)
  5777. {
  5778. result = PASS;
  5779. }
  5780. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5781. strcpy(queuedata,message);
  5782. return result;
  5783. }
  5784. int sendDataTransferRequest(int gun_index)
  5785. {
  5786. mtrace();
  5787. char message[10240]={0};
  5788. char guid[37]={0};
  5789. char tempdata[65]={0};
  5790. int result = FAIL;
  5791. json_object *DataTransfer = json_object_new_object();
  5792. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5793. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5794. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5795. random_uuid(guid);
  5796. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5797. guid,
  5798. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5799. json_object_put(DataTransfer);
  5800. LWS_Send(message);
  5801. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5802. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5803. {
  5804. result = PASS;
  5805. DEBUG_INFO("DataTransfer mapItem pass\n");
  5806. }
  5807. return result;
  5808. }
  5809. int sendUnplugByDataTransferRequest(int gun_index)
  5810. {
  5811. mtrace();
  5812. char message[10752]={0};
  5813. char guid[37]={0};
  5814. char tempdata[65]={0};
  5815. int result = FAIL;
  5816. random_uuid(guid);
  5817. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5818. (gun_index+1),
  5819. MESSAGE_TYPE_CALL,
  5820. guid,
  5821. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5822. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5823. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5824. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5825. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5826. {
  5827. result = PASS;
  5828. DEBUG_INFO("DataTransfer mapItem pass\n");
  5829. }
  5830. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5831. return result;
  5832. }
  5833. int sendOcmfByDataTransferRequest(int gun_index)
  5834. {
  5835. mtrace();
  5836. json_object *DataTransfer = json_object_new_object();
  5837. json_object *data = json_object_new_object();
  5838. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5839. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5840. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5841. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5842. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5843. json_object_object_add(DataTransfer, "data", data);
  5844. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5845. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5846. char message[3000]={0};
  5847. char guid[37]={0};
  5848. char tempdata[65]={0};
  5849. int result = FAIL;
  5850. random_uuid(guid);
  5851. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5852. (gun_index+1),
  5853. MESSAGE_TYPE_CALL,
  5854. guid,
  5855. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5856. json_object_put(DataTransfer);
  5857. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5858. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5859. {
  5860. result = PASS;
  5861. DEBUG_INFO("DataTransfer mapItem pass\n");
  5862. }
  5863. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5864. return result;
  5865. }
  5866. int sendDiagnosticsStatusNotificationRequest(char *status)
  5867. {
  5868. mtrace();
  5869. int result = FAIL;
  5870. char message[110]={0};
  5871. char guid[37]={0};
  5872. char tempdata[65]={0};
  5873. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5874. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5875. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5876. random_uuid(guid);
  5877. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5878. LWS_SendNow(message);
  5879. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5880. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5881. {
  5882. result = PASS;
  5883. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5884. }
  5885. //#ifdef SystemLogMessage
  5886. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5887. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5888. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5889. //#endif
  5890. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5891. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5892. //record status
  5893. if(strcmp(status,"Idle")==0)
  5894. {
  5895. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5896. }
  5897. else if(strcmp(status,"Uploaded")==0)
  5898. {
  5899. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5900. }
  5901. else if(strcmp(status,"UploadFailed")==0)
  5902. {
  5903. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5904. }
  5905. else if(strcmp(status,"Uploading")==0)
  5906. {
  5907. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5908. }
  5909. return result;
  5910. }
  5911. int sendFirmwareStatusNotificationRequest(char *status)
  5912. {
  5913. mtrace();
  5914. int result = FAIL;
  5915. char message[110]={0};
  5916. char guid[37]={0};
  5917. char tempdata[65]={0};
  5918. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5919. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5920. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5921. random_uuid(guid);
  5922. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5923. LWS_SendNow(message);
  5924. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5925. 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*/)
  5926. {
  5927. result = PASS;
  5928. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5929. }
  5930. //#ifdef SystemLogMessage
  5931. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5932. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5933. //#endif
  5934. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5935. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5936. //record status
  5937. if(strcmp(status,"Downloaded")==0)
  5938. {
  5939. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5940. }
  5941. else if(strcmp(status,"DownloadFailed")==0)
  5942. {
  5943. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5944. }
  5945. else if(strcmp(status,"Downloading")==0)
  5946. {
  5947. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5948. }
  5949. else if(strcmp(status,"Idle")==0)
  5950. {
  5951. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5952. }
  5953. else if(strcmp(status,"InstallationFailed")==0)
  5954. {
  5955. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5956. }
  5957. else if(strcmp(status,"Installing")==0)
  5958. {
  5959. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5960. }
  5961. else if(strcmp(status,"Installed")==0)
  5962. {
  5963. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5964. }
  5965. return result;
  5966. }
  5967. int sendHeartbeatRequest(int gun_index)
  5968. {
  5969. mtrace();
  5970. int result = FAIL;
  5971. char message[80]={0};
  5972. char guid[37]={0};
  5973. char tempdata[65]={0};
  5974. random_uuid(guid);
  5975. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5976. , MESSAGE_TYPE_CALL
  5977. , guid );
  5978. LWS_Send(message);
  5979. sprintf(tempdata, "Heartbeat,%d", 0);
  5980. 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*/)
  5981. {
  5982. result = PASS;
  5983. }
  5984. return result;
  5985. }
  5986. int sendStartTransactionRequest(int gun_index)
  5987. {
  5988. mtrace();
  5989. int result = FAIL;
  5990. char message[250]={0};
  5991. char guid[37]={0};
  5992. struct timeval tmnow;
  5993. struct tm *tm;
  5994. char buf[28];//, usec_buf[6];
  5995. char tempdata[65]={0};
  5996. int tempIndex = 0;
  5997. DEBUG_INFO("sendStartTransactionRequest...\n");
  5998. gettimeofday(&tmnow, NULL);
  5999. time_t t;
  6000. t = time(NULL);
  6001. /*UTC time and date*/
  6002. tm = gmtime(&t);
  6003. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6004. #if 0 // remove temporally
  6005. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6006. strcat(buf,".");
  6007. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6008. strcat(buf,usec_buf);
  6009. #endif
  6010. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  6011. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  6012. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6013. // clear StartTransaction Response
  6014. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  6015. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  6016. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  6017. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  6018. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6019. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6020. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6021. {
  6022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6023. {
  6024. tempIndex = ((gun_index==2) ? 1: 0);
  6025. }
  6026. else
  6027. {
  6028. tempIndex = gun_index;
  6029. }
  6030. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6031. {
  6032. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6033. {
  6034. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6035. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  6036. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6037. }
  6038. }
  6039. }
  6040. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6041. {
  6042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6043. {
  6044. tempIndex = ((gun_index==2) ? 1: 0);
  6045. }
  6046. else
  6047. {
  6048. tempIndex = gun_index;
  6049. }
  6050. for (int index = 0; index < CCS_QUANTITY; index++)
  6051. {
  6052. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6053. {
  6054. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6055. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  6056. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6057. }
  6058. }
  6059. }
  6060. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6061. {
  6062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6063. {
  6064. tempIndex = ((gun_index==2) ? 1: 0);
  6065. }
  6066. else
  6067. {
  6068. tempIndex = gun_index;
  6069. }
  6070. for (int index = 0; index < GB_QUANTITY; index++)
  6071. {
  6072. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6073. {
  6074. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6075. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  6076. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6077. }
  6078. }
  6079. }
  6080. else if(gunType[gun_index] == GUN_TYPE_DO)
  6081. {
  6082. tempIndex = gun_index;
  6083. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6084. {
  6085. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6086. {
  6087. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6088. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  6089. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6090. }
  6091. }
  6092. }
  6093. else
  6094. {
  6095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6096. {
  6097. tempIndex = 2;
  6098. }
  6099. else
  6100. {
  6101. tempIndex = gun_index;
  6102. }
  6103. for (int index = 0; index < AC_QUANTITY; index++)
  6104. {
  6105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6106. {
  6107. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6108. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  6109. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6110. }
  6111. }
  6112. }
  6113. random_uuid(guid);
  6114. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  6115. {
  6116. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  6117. , gun_index +1
  6118. , MESSAGE_TYPE_CALL
  6119. , guid
  6120. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6121. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6122. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6123. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6124. }
  6125. else
  6126. {
  6127. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  6128. , gun_index +1
  6129. , MESSAGE_TYPE_CALL
  6130. , guid
  6131. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6132. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6133. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6134. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  6135. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6136. }
  6137. #if 1
  6138. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  6139. 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*/)
  6140. {
  6141. result = PASS;
  6142. }
  6143. #endif
  6144. strcpy(queuedata, message);
  6145. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6146. OCPP_insert_transaction_msg(YES, queuedata);
  6147. return result;
  6148. }
  6149. int sendConnector0StatusNotificationRequest()
  6150. {
  6151. mtrace();
  6152. int result = FAIL;
  6153. char message[600]={0};
  6154. char guid[37];
  6155. struct timeval tmnow;
  6156. struct tm *tm;
  6157. char buf[28];//, usec_buf[6];
  6158. char tempdata[65]={0};
  6159. DEBUG_INFO("sendConnector0StatusNotificationRequest...\n");
  6160. gettimeofday(&tmnow, NULL);
  6161. time_t t;
  6162. t = time(NULL);
  6163. /*UTC time and date*/
  6164. tm = gmtime(&t);
  6165. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6166. random_uuid(guid);
  6167. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":0,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6168. , MESSAGE_TYPE_CALL
  6169. , guid
  6170. , "NoError"
  6171. , ""
  6172. , (isConnector0Unavailable()==YES?"Unavailable":"Available")
  6173. , buf
  6174. , ShmSysConfigAndInfo->SysConfig.chargePointVendor
  6175. , "");
  6176. LWS_Send(message);
  6177. sprintf(tempdata, "StatusNotification,%d", 99);
  6178. 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*/)
  6179. {
  6180. //DEBUG_ERROR("statusNotification mapitem pass");
  6181. result = PASS;
  6182. }
  6183. return result;
  6184. }
  6185. int sendStatusNotificationRequest(int gun_index)
  6186. {
  6187. mtrace();
  6188. int result = FAIL;
  6189. char message[600]={0};
  6190. char guid[37];
  6191. int currentStatus = 0;
  6192. struct timeval tmnow;
  6193. struct tm *tm;
  6194. char buf[28];//, usec_buf[6];
  6195. char tempdata[65]={0};
  6196. int tempIndex = 0;
  6197. uint8_t isStateChanged = TRUE;
  6198. uint8_t isContentIllegal = TRUE;
  6199. DEBUG_INFO("sendStatusNotificationRequest...\n");
  6200. gettimeofday(&tmnow, NULL);
  6201. time_t t;
  6202. t = time(NULL);
  6203. /*UTC time and date*/
  6204. tm = gmtime(&t);
  6205. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6206. #if 0 // remove temporally
  6207. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6208. strcat(buf,".");
  6209. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6210. strcat(buf,usec_buf);
  6211. #endif
  6212. //printf("%s",buf);
  6213. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  6214. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6215. // it's option
  6216. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  6217. /*
  6218. enum _SYSTEM_STATUS
  6219. {
  6220. S_BOOTING = 0,
  6221. S_IDLE, = 1
  6222. S_AUTHORIZING, =2
  6223. S_REASSIGN_CHECK, =3
  6224. S_REASSIGN, =4
  6225. S_PRECHARGE, =5
  6226. S_PREPARING_FOR_EV, =6
  6227. S_PREPARING_FOR_EVSE, =7
  6228. S_CHARGING, =8
  6229. S_TERMINATING, =9
  6230. S_COMPLETE, =10
  6231. S_ALARM, =11
  6232. S_FAULT =12
  6233. }
  6234. */
  6235. //check Transaction active
  6236. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6237. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6238. {
  6239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6240. {
  6241. tempIndex = ((gun_index==2) ? 1: 0);
  6242. }
  6243. else
  6244. {
  6245. tempIndex = gun_index;
  6246. }
  6247. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6248. {
  6249. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6250. {
  6251. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6252. {
  6253. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6254. {
  6255. currentStatus = Preparing; //OCPP Status: Preparing
  6256. }
  6257. else
  6258. {
  6259. currentStatus = Available; //OCPP Status: Available
  6260. }
  6261. }
  6262. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6263. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6264. ) //S_PRECHARGE
  6265. {
  6266. currentStatus = Preparing; //OCPP Status: Preparing
  6267. }
  6268. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6269. {
  6270. currentStatus = Charging; //OCPP Status: Charging
  6271. }
  6272. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6273. {
  6274. currentStatus = Finishing; //OCPP Status: Finishing
  6275. }
  6276. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6277. {
  6278. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6279. }
  6280. 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
  6281. {
  6282. currentStatus = Unavailable; //OCPP Status: Unavailable
  6283. }
  6284. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6285. {
  6286. currentStatus = Faulted; //OCPP Status: Faulted
  6287. }
  6288. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6289. {
  6290. currentStatus = Reserved; //OCPP Status: Reserved
  6291. }
  6292. } //end of the same index
  6293. }//end of for CHAdeMO_QUANTITY
  6294. }
  6295. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6296. {
  6297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6298. {
  6299. tempIndex = ((gun_index==2) ? 1: 0);
  6300. }
  6301. else
  6302. {
  6303. tempIndex = gun_index;
  6304. }
  6305. for (int index = 0; index < CCS_QUANTITY; index++)
  6306. {
  6307. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6308. {
  6309. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6310. {
  6311. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6312. {
  6313. currentStatus = Preparing; //OCPP Status: Preparing
  6314. }
  6315. else
  6316. {
  6317. currentStatus = Available; //OCPP Status: Available
  6318. }
  6319. }
  6320. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6321. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6322. ) //S_PRECHARGE
  6323. {
  6324. currentStatus = Preparing; //OCPP Status: Preparing
  6325. }
  6326. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6327. {
  6328. currentStatus = Charging; //OCPP Status: Charging
  6329. }
  6330. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6331. {
  6332. currentStatus = Finishing; //OCPP Status: Finishing
  6333. }
  6334. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6335. {
  6336. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6337. }
  6338. 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
  6339. {
  6340. currentStatus = Unavailable; //OCPP Status : Unavailable
  6341. }
  6342. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6343. {
  6344. currentStatus = Faulted; //OCPP Status: Faulted
  6345. }
  6346. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6347. {
  6348. currentStatus = Reserved; //OCPP Status: Reserved
  6349. }
  6350. } //end of the same index
  6351. } // end of for CCS_QUANTITY
  6352. }
  6353. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  6364. {
  6365. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6366. {
  6367. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6368. {
  6369. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6370. {
  6371. currentStatus = Preparing; //OCPP Status: Preparing
  6372. }
  6373. else
  6374. {
  6375. currentStatus = Available; //OCPP Status: Available
  6376. }
  6377. }
  6378. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6379. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6380. ) //S_PRECHARGE
  6381. {
  6382. currentStatus = Preparing; //OCPP Status: Preparing
  6383. }
  6384. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6385. {
  6386. currentStatus = Charging; //OCPP Status: Charging
  6387. }
  6388. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6389. {
  6390. currentStatus = Finishing; //OCPP Status: Finishing
  6391. }
  6392. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6393. {
  6394. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6395. }
  6396. 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
  6397. {
  6398. currentStatus = Unavailable; //OCPP Status: Unavailable
  6399. }
  6400. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6401. {
  6402. currentStatus = Faulted; //OCPP Status: Faulted
  6403. }
  6404. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6405. {
  6406. currentStatus = Reserved; //OCPP Status: Reserved
  6407. }
  6408. } //end of the same index
  6409. } // end of for GB_QUANTITY
  6410. }
  6411. else if(gunType[gun_index] == GUN_TYPE_DO)
  6412. {
  6413. tempIndex = gun_index;
  6414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6415. {
  6416. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6417. {
  6418. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6419. {
  6420. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6421. {
  6422. currentStatus = Preparing; //OCPP Status: Preparing
  6423. }
  6424. else
  6425. {
  6426. currentStatus = Available; //OCPP Status: Available
  6427. }
  6428. }
  6429. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6430. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6431. ) //S_PRECHARGE
  6432. {
  6433. currentStatus = Preparing; //OCPP Status: Preparing
  6434. }
  6435. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6436. {
  6437. currentStatus = Charging; //OCPP Status: Charging
  6438. }
  6439. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6440. {
  6441. currentStatus = Finishing; //OCPP Status: Finishing
  6442. }
  6443. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6444. {
  6445. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6446. }
  6447. 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
  6448. {
  6449. currentStatus = Unavailable; //OCPP Status: Unavailable
  6450. }
  6451. 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
  6452. {
  6453. currentStatus = Faulted; //OCPP Status: Faulted
  6454. }
  6455. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6456. {
  6457. currentStatus = Reserved; //OCPP Status: Reserved
  6458. }
  6459. } //end of the same index
  6460. }
  6461. }
  6462. else
  6463. {
  6464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6465. {
  6466. tempIndex = 2;
  6467. }
  6468. else
  6469. {
  6470. tempIndex = gun_index;
  6471. }
  6472. for (int index = 0; index < AC_QUANTITY; index++)
  6473. {
  6474. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6475. {
  6476. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6477. {
  6478. 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))
  6479. {
  6480. currentStatus = Preparing; //OCPP Status: Preparing
  6481. }
  6482. else
  6483. {
  6484. currentStatus = Available; //OCPP Status: Available
  6485. }
  6486. }
  6487. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6488. {
  6489. currentStatus = Preparing; //OCPP Status: Preparing
  6490. }
  6491. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6492. {
  6493. currentStatus = Charging; //OCPP Status: Charging
  6494. }
  6495. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6496. {
  6497. currentStatus = Finishing; //OCPP Status: Finishing
  6498. }
  6499. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6500. {
  6501. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6502. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6503. else
  6504. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6505. }
  6506. 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
  6507. {
  6508. currentStatus = Unavailable; //OCPP Status: Unavailable
  6509. }
  6510. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6511. {
  6512. currentStatus = Faulted; //OCPP Status: Faulted
  6513. }
  6514. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6515. {
  6516. currentStatus = Reserved; //OCPP Status: Reserved
  6517. }
  6518. }//end of the same index
  6519. }//end of for AC_QUANTITY
  6520. }
  6521. //it's option
  6522. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6523. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6524. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6525. {
  6526. isStateChanged = FALSE;
  6527. }
  6528. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6529. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6530. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6531. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6532. isContentIllegal = TRUE;
  6533. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6534. {
  6535. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6536. {
  6537. isContentIllegal = FALSE;
  6538. break;
  6539. }
  6540. }
  6541. if(isContentIllegal)
  6542. {
  6543. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6544. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6545. }
  6546. random_uuid(guid);
  6547. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6548. , MESSAGE_TYPE_CALL
  6549. , guid
  6550. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6551. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6552. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6553. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6554. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6555. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6556. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6557. if((server_sign == TRUE) && isStateChanged)
  6558. {
  6559. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6560. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6561. LWS_Send(message);
  6562. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6563. 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*/)
  6564. {
  6565. //DEBUG_ERROR("statusNotification mapitem pass");
  6566. result = PASS;
  6567. }
  6568. }
  6569. else
  6570. {
  6571. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6572. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6573. result = PASS;
  6574. }
  6575. return result;
  6576. }
  6577. int sendStopTransactionRequest(int gun_index)
  6578. {
  6579. mtrace();
  6580. int result = FAIL;
  6581. //char message[1500]={0};
  6582. char guid[37]={0};
  6583. char tempdata[65]={0};
  6584. int tempIndex = 0;
  6585. char TempStopTransaction[256];
  6586. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6587. DEBUG_INFO("sendStopTransactionRequest \n");
  6588. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6589. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6590. //=========================== Stop Transaction Time ===============================================
  6591. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  6592. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6593. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6594. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6595. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6596. {
  6597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6598. {
  6599. tempIndex = ((gun_index==2) ? 1: 0);
  6600. }
  6601. else
  6602. {
  6603. tempIndex = gun_index;
  6604. }
  6605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6606. {
  6607. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6608. {
  6609. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6610. }
  6611. }// END OF CHAdeMO_QUANTITY
  6612. }
  6613. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6614. {
  6615. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6616. {
  6617. tempIndex = ((gun_index==2) ? 1: 0);
  6618. }
  6619. else
  6620. {
  6621. tempIndex = gun_index;
  6622. }
  6623. for (int index = 0; index < CCS_QUANTITY; index++)
  6624. {
  6625. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6626. {
  6627. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6628. }
  6629. }// END OF CCS_QUANTITY
  6630. }
  6631. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6632. {
  6633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6634. {
  6635. tempIndex = ((gun_index==2) ? 1: 0);
  6636. }
  6637. else
  6638. {
  6639. tempIndex = gun_index;
  6640. }
  6641. for (int index = 0; index < GB_QUANTITY; index++)
  6642. {
  6643. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6644. {
  6645. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6646. }
  6647. }// END OF GB_QUANTITY
  6648. }
  6649. else if(gunType[gun_index] == GUN_TYPE_DO)
  6650. {
  6651. tempIndex = gun_index;
  6652. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6653. {
  6654. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6655. {
  6656. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6657. }
  6658. }// END OF GB_QUANTITY
  6659. }
  6660. else
  6661. {
  6662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6663. {
  6664. tempIndex = 2;
  6665. }
  6666. else
  6667. {
  6668. tempIndex = gun_index;
  6669. }
  6670. for (int index = 0; index < AC_QUANTITY; index++)
  6671. {
  6672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6673. {
  6674. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6675. }
  6676. }// END OF AC_QUANTITY
  6677. }
  6678. //================================================ Message create ====================================================
  6679. json_object *StopTransaction = json_object_new_object();
  6680. json_object *transactionDatas = json_object_new_array();
  6681. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6682. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6683. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6684. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6685. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6686. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6687. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6688. meterValueBufferQuery(gun_index, transactionDatas);
  6689. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6690. random_uuid(guid);
  6691. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6692. ,MESSAGE_TYPE_CALL
  6693. ,guid
  6694. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6695. json_object_put(StopTransaction);
  6696. #if 1 // for TempStopTransaction
  6697. //Delete TempStopTransaction
  6698. if((access(TempStopTransaction,F_OK))!=-1)
  6699. {
  6700. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6701. }
  6702. #endif
  6703. #if 1
  6704. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6705. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6706. {
  6707. result = PASS;
  6708. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6709. }
  6710. #endif
  6711. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6712. OCPP_insert_transaction_msg(NO, queuedata);
  6713. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6714. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6715. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6716. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6717. {
  6718. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6719. }
  6720. //for test
  6721. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6722. return result;
  6723. }
  6724. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6725. {
  6726. mtrace();
  6727. int result = FAIL;
  6728. char guid[37]={0};
  6729. char tempdata[65]={0};
  6730. int tempIndex = 0;
  6731. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6732. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6733. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6734. //set value
  6735. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6736. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6737. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6738. -1);
  6739. random_uuid(guid);
  6740. //UTC Date time
  6741. struct timeval tmnow;
  6742. struct tm *tm;
  6743. char buf[28];//, usec_buf[6];
  6744. gettimeofday(&tmnow, NULL);
  6745. time_t t;
  6746. t = time(NULL);
  6747. /*UTC time and date*/
  6748. tm = gmtime(&t);
  6749. if(dataType == ReadingContext_Sample_Clock)
  6750. {
  6751. struct tm *tmTarget;
  6752. struct timeb tbTarget;
  6753. tbTarget.time = mktime(tm);
  6754. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6755. tmTarget = gmtime(&tbTarget.time);
  6756. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6757. }
  6758. else
  6759. {
  6760. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6761. }
  6762. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6763. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6764. //********************************(1)Current.Import L1************************************************/
  6765. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6766. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6767. (dataType == ReadingContext_Trigger))
  6768. {
  6769. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6770. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6771. {
  6772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6773. {
  6774. tempIndex = ((gun_index==2) ? 1: 0);
  6775. }
  6776. else
  6777. {
  6778. tempIndex = gun_index;
  6779. }
  6780. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6781. {
  6782. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6783. {
  6784. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6785. }
  6786. }
  6787. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6788. }
  6789. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6790. {
  6791. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6792. {
  6793. tempIndex = ((gun_index==2) ? 1: 0);
  6794. }
  6795. else
  6796. {
  6797. tempIndex = gun_index;
  6798. }
  6799. for (int index = 0; index < CCS_QUANTITY; index++)
  6800. {
  6801. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6802. {
  6803. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6804. }
  6805. }
  6806. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6807. }
  6808. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6809. {
  6810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6811. {
  6812. tempIndex = ((gun_index==2) ? 1: 0);
  6813. }
  6814. else
  6815. {
  6816. tempIndex = gun_index;
  6817. }
  6818. for (int index = 0; index < GB_QUANTITY; index++)
  6819. {
  6820. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6821. {
  6822. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6823. }
  6824. }
  6825. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6826. }
  6827. else if(gunType[gun_index] == GUN_TYPE_DO)
  6828. {
  6829. tempIndex = gun_index;
  6830. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6831. {
  6832. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6833. {
  6834. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6835. }
  6836. }
  6837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6838. }
  6839. else
  6840. {
  6841. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6842. {
  6843. tempIndex = 2;
  6844. }
  6845. else
  6846. {
  6847. tempIndex = gun_index;
  6848. }
  6849. for (int index = 0; index < AC_QUANTITY; index++)
  6850. {
  6851. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6852. {
  6853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6854. }
  6855. }
  6856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6857. }
  6858. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6859. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6860. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6861. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6862. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6863. }
  6864. //********************************(2)Energy.Active.Import.Register ************************************************/
  6865. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6866. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6867. (dataType == ReadingContext_Trigger))
  6868. {
  6869. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6870. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6871. {
  6872. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6873. {
  6874. tempIndex = ((gun_index==2) ? 1: 0);
  6875. }
  6876. else
  6877. {
  6878. tempIndex = gun_index;
  6879. }
  6880. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6881. {
  6882. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6883. {
  6884. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6885. }
  6886. }
  6887. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6888. }
  6889. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6890. {
  6891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6892. {
  6893. tempIndex = ((gun_index==2) ? 1: 0);
  6894. }
  6895. else
  6896. {
  6897. tempIndex = gun_index;
  6898. }
  6899. for (int index = 0; index < CCS_QUANTITY; index++)
  6900. {
  6901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6902. {
  6903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6904. }
  6905. }
  6906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6907. }
  6908. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6909. {
  6910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6911. {
  6912. tempIndex = ((gun_index==2) ? 1: 0);
  6913. }
  6914. else
  6915. {
  6916. tempIndex = gun_index;
  6917. }
  6918. for (int index = 0; index < GB_QUANTITY; index++)
  6919. {
  6920. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6921. {
  6922. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6923. }
  6924. }
  6925. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6926. }
  6927. else if(gunType[gun_index] == GUN_TYPE_DO)
  6928. {
  6929. tempIndex = gun_index;
  6930. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6931. {
  6932. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6933. {
  6934. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6935. }
  6936. }
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6938. }
  6939. else
  6940. {
  6941. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6942. {
  6943. tempIndex = 2;
  6944. }
  6945. else
  6946. {
  6947. tempIndex = gun_index;
  6948. }
  6949. for (int index = 0; index < AC_QUANTITY; index++)
  6950. {
  6951. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6952. {
  6953. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6954. }
  6955. }
  6956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6957. }
  6958. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6959. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6960. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6961. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6962. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6963. }
  6964. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6965. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6966. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6967. (dataType == ReadingContext_Trigger))
  6968. {
  6969. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6970. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6971. {
  6972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6973. {
  6974. tempIndex = ((gun_index==2) ? 1: 0);
  6975. }
  6976. else
  6977. {
  6978. tempIndex = gun_index;
  6979. }
  6980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6981. {
  6982. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6983. {
  6984. if(dataType == ReadingContext_Sample_Clock)
  6985. {
  6986. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6987. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6988. }
  6989. else if(dataType == ReadingContext_Sample_Periodic)
  6990. {
  6991. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6992. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6993. }
  6994. else
  6995. {
  6996. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6997. }
  6998. }
  6999. } // END OF FOR CHAdeMO_QUANTITY
  7000. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7001. }
  7002. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7003. {
  7004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7005. {
  7006. tempIndex = ((gun_index==2) ? 1: 0);
  7007. }
  7008. else
  7009. {
  7010. tempIndex = gun_index;
  7011. }
  7012. for (int index = 0; index < CCS_QUANTITY; index++)
  7013. {
  7014. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7015. {
  7016. if(dataType == ReadingContext_Sample_Clock)
  7017. {
  7018. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7019. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7020. }
  7021. else if(dataType == ReadingContext_Sample_Periodic)
  7022. {
  7023. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7024. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7025. }
  7026. else
  7027. {
  7028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7029. }
  7030. }
  7031. } // END OF CCS_QUANTITY
  7032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7033. }
  7034. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7035. {
  7036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7037. {
  7038. tempIndex = ((gun_index==2) ? 1: 0);
  7039. }
  7040. else
  7041. {
  7042. tempIndex = gun_index;
  7043. }
  7044. for (int index = 0; index < GB_QUANTITY; index++)
  7045. {
  7046. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7047. {
  7048. if(dataType == ReadingContext_Sample_Clock)
  7049. {
  7050. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7051. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7052. }
  7053. else if(dataType == ReadingContext_Sample_Periodic)
  7054. {
  7055. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7056. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7057. }
  7058. else
  7059. {
  7060. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7061. }
  7062. }
  7063. } // END OF GB_QUANTITY
  7064. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7065. }
  7066. else if(gunType[gun_index] == GUN_TYPE_DO)
  7067. {
  7068. tempIndex = gun_index;
  7069. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7070. {
  7071. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7072. {
  7073. if(dataType == ReadingContext_Sample_Clock)
  7074. {
  7075. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7076. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7077. }
  7078. else if(dataType == ReadingContext_Sample_Periodic)
  7079. {
  7080. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7081. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7082. }
  7083. else
  7084. {
  7085. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7086. }
  7087. }
  7088. }
  7089. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7090. }
  7091. else
  7092. {
  7093. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7094. {
  7095. tempIndex = 2;
  7096. }
  7097. else
  7098. {
  7099. tempIndex = gun_index;
  7100. }
  7101. for (int index = 0; index < AC_QUANTITY; index++)
  7102. {
  7103. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7104. {
  7105. if(dataType == ReadingContext_Sample_Clock)
  7106. {
  7107. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7108. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7109. }
  7110. else if(dataType == ReadingContext_Sample_Periodic)
  7111. {
  7112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7113. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7114. }
  7115. else
  7116. {
  7117. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7118. }
  7119. }
  7120. }
  7121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7122. }
  7123. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7125. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7126. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7127. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7128. }
  7129. //********************************(4)Power.Active.Import************************************************/
  7130. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7131. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7132. (dataType == ReadingContext_Trigger))
  7133. {
  7134. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7135. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7136. {
  7137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7138. {
  7139. tempIndex = ((gun_index==2) ? 1: 0);
  7140. }
  7141. else
  7142. {
  7143. tempIndex = gun_index;
  7144. }
  7145. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7146. {
  7147. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7148. {
  7149. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7150. }
  7151. } // END OF FOR
  7152. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7153. }
  7154. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7155. {
  7156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7157. {
  7158. tempIndex = ((gun_index==2) ? 1: 0);
  7159. }
  7160. else
  7161. {
  7162. tempIndex = gun_index;
  7163. }
  7164. for (int index = 0; index < CCS_QUANTITY; index++)
  7165. {
  7166. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7167. {
  7168. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7169. }
  7170. }
  7171. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7172. }
  7173. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7174. {
  7175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7176. {
  7177. tempIndex = ((gun_index==2) ? 1: 0);
  7178. }
  7179. else
  7180. {
  7181. tempIndex = gun_index;
  7182. }
  7183. for (int index = 0; index < GB_QUANTITY; index++)
  7184. {
  7185. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7186. {
  7187. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7188. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7189. }
  7190. }
  7191. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7192. }
  7193. else if(gunType[gun_index] == GUN_TYPE_DO)
  7194. {
  7195. tempIndex = gun_index;
  7196. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7197. {
  7198. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7199. {
  7200. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7201. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7202. }
  7203. }
  7204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7205. }
  7206. else
  7207. {
  7208. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7209. {
  7210. tempIndex = 2;
  7211. }
  7212. else
  7213. {
  7214. tempIndex = gun_index;
  7215. }
  7216. for (int index = 0; index < AC_QUANTITY; index++)
  7217. {
  7218. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7219. {
  7220. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7221. }
  7222. }
  7223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7224. }
  7225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7228. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7230. }
  7231. //***********************************************(5)VOLTAGE L1******************************************************/
  7232. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7233. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7234. (dataType == ReadingContext_Trigger))
  7235. {
  7236. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7237. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7238. {
  7239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7240. {
  7241. tempIndex = ((gun_index==2) ? 1: 0);
  7242. }
  7243. else
  7244. {
  7245. tempIndex = gun_index;
  7246. }
  7247. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7248. {
  7249. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7250. {
  7251. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7252. }
  7253. }
  7254. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7255. }
  7256. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7257. {
  7258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7259. {
  7260. tempIndex = ((gun_index==2) ? 1: 0);
  7261. }
  7262. else
  7263. {
  7264. tempIndex = gun_index;
  7265. }
  7266. for (int index = 0; index < CCS_QUANTITY; index++)
  7267. {
  7268. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7269. {
  7270. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7271. }
  7272. }
  7273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7274. }
  7275. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7276. {
  7277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7278. {
  7279. tempIndex = ((gun_index==2) ? 1: 0);
  7280. }
  7281. else
  7282. {
  7283. tempIndex = gun_index;
  7284. }
  7285. for (int index = 0; index < GB_QUANTITY; index++)
  7286. {
  7287. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7288. {
  7289. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7290. }
  7291. }
  7292. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7293. }
  7294. else if(gunType[gun_index] == GUN_TYPE_DO)
  7295. {
  7296. tempIndex = gun_index;
  7297. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7298. {
  7299. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7300. {
  7301. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7302. }
  7303. }
  7304. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7305. }
  7306. else
  7307. {
  7308. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7309. {
  7310. tempIndex = 2;
  7311. }
  7312. else
  7313. {
  7314. tempIndex = gun_index;
  7315. }
  7316. for (int index = 0; index < AC_QUANTITY; index++)
  7317. {
  7318. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7319. {
  7320. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7321. }
  7322. }
  7323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7324. }
  7325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7326. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7328. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7330. }
  7331. //***********************************************(6)SOC******************************************************/
  7332. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7333. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7334. (dataType == ReadingContext_Trigger))
  7335. {
  7336. 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))
  7337. {
  7338. //idx_sample=5;
  7339. //sampledValue = NULL;
  7340. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7341. {
  7342. tempIndex = ((gun_index==2) ? 1: 0);
  7343. }
  7344. else
  7345. {
  7346. tempIndex = gun_index;
  7347. }
  7348. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7349. {
  7350. //tempIndex = ((gun_index==2) ? 1: 0);
  7351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7352. {
  7353. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7354. {
  7355. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7356. }
  7357. }
  7358. }
  7359. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7360. {
  7361. //tempIndex = ((gun_index==2) ? 1: 0);
  7362. for (int index = 0; index < CCS_QUANTITY; index++)
  7363. {
  7364. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7365. {
  7366. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7367. }
  7368. }
  7369. }
  7370. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7371. {
  7372. //tempIndex = ((gun_index==2) ? 1: 0);
  7373. for (int index = 0; index < GB_QUANTITY; index++)
  7374. {
  7375. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7376. {
  7377. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7378. }
  7379. }
  7380. }
  7381. else if(gunType[gun_index] == GUN_TYPE_DO)
  7382. {
  7383. //tempIndex = ((gun_index==2) ? 1: 0);
  7384. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7385. {
  7386. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7387. {
  7388. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7389. }
  7390. }
  7391. }
  7392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7395. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7398. }
  7399. }
  7400. //********************************(7)Current.Import L2************************************************/
  7401. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7402. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7403. (dataType == ReadingContext_Trigger))
  7404. {
  7405. // Only for AC 3 phase
  7406. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7407. {
  7408. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7409. {
  7410. tempIndex = 2;
  7411. }
  7412. else
  7413. {
  7414. tempIndex = gun_index;
  7415. }
  7416. for (int index = 0; index < AC_QUANTITY; index++)
  7417. {
  7418. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7419. {
  7420. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7421. }
  7422. }
  7423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7424. }
  7425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7430. }
  7431. //********************************(8)Current.Import L3************************************************/
  7432. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7433. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7434. (dataType == ReadingContext_Trigger))
  7435. {
  7436. // Only for AC 3 phase
  7437. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7438. {
  7439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7440. {
  7441. tempIndex = 2;
  7442. }
  7443. else
  7444. {
  7445. tempIndex = gun_index;
  7446. }
  7447. for (int index = 0; index < AC_QUANTITY; index++)
  7448. {
  7449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7450. {
  7451. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7452. }
  7453. }
  7454. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7455. }
  7456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7457. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7459. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7461. }
  7462. //***********************************************(9)VOLTAGE L2******************************************************/
  7463. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7464. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7465. (dataType == ReadingContext_Trigger))
  7466. {
  7467. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7468. {
  7469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7470. {
  7471. tempIndex = 2;
  7472. }
  7473. else
  7474. {
  7475. tempIndex = gun_index;
  7476. }
  7477. for (int index = 0; index < AC_QUANTITY; index++)
  7478. {
  7479. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7480. {
  7481. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7482. }
  7483. }
  7484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7485. }
  7486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7491. }
  7492. //***********************************************(10)VOLTAGE L3******************************************************/
  7493. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7494. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7495. (dataType == ReadingContext_Trigger))
  7496. {
  7497. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7498. {
  7499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7500. {
  7501. tempIndex = 2;
  7502. }
  7503. else
  7504. {
  7505. tempIndex = gun_index;
  7506. }
  7507. for (int index = 0; index < AC_QUANTITY; index++)
  7508. {
  7509. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7510. {
  7511. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7512. }
  7513. }
  7514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7515. }
  7516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7521. }
  7522. //***********************************************(11)Current.Offered******************************************************/
  7523. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7524. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7525. (dataType == ReadingContext_Trigger))
  7526. {
  7527. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7528. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7529. {
  7530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7531. {
  7532. tempIndex = ((gun_index==2) ? 1: 0);
  7533. }
  7534. else
  7535. {
  7536. tempIndex = gun_index;
  7537. }
  7538. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7539. {
  7540. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7541. {
  7542. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7543. }
  7544. } // END OF FOR CHAdeMO_QUANTITY
  7545. }
  7546. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7547. {
  7548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7549. {
  7550. tempIndex = ((gun_index==2) ? 1: 0);
  7551. }
  7552. else
  7553. {
  7554. tempIndex = gun_index;
  7555. }
  7556. for (int index = 0; index < CCS_QUANTITY; index++)
  7557. {
  7558. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7559. {
  7560. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7561. }
  7562. } // END OF CCS_QUANTITY
  7563. }
  7564. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7565. {
  7566. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7567. {
  7568. tempIndex = ((gun_index==2) ? 1: 0);
  7569. }
  7570. else
  7571. {
  7572. tempIndex = gun_index;
  7573. }
  7574. for (int index = 0; index < GB_QUANTITY; index++)
  7575. {
  7576. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7577. {
  7578. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7579. }
  7580. } // END OF GB_QUANTITY
  7581. }
  7582. else if(gunType[gun_index] == GUN_TYPE_DO)
  7583. {
  7584. tempIndex = gun_index;
  7585. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7586. {
  7587. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7588. {
  7589. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7590. }
  7591. }
  7592. }
  7593. else
  7594. {
  7595. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7596. {
  7597. tempIndex = 2;
  7598. }
  7599. else
  7600. {
  7601. tempIndex = gun_index;
  7602. }
  7603. for (int index = 0; index < AC_QUANTITY; index++)
  7604. {
  7605. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7606. {
  7607. uint16_t currentOffer;
  7608. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7609. {
  7610. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7611. }
  7612. else
  7613. {
  7614. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7615. }
  7616. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7617. }
  7618. }
  7619. }
  7620. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7621. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7622. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7623. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7624. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7625. }
  7626. //***********************************************(12)Power.Offered******************************************************/
  7627. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7628. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7629. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7630. {
  7631. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7632. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7633. {
  7634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7635. {
  7636. tempIndex = ((gun_index==2) ? 1: 0);
  7637. }
  7638. else
  7639. {
  7640. tempIndex = gun_index;
  7641. }
  7642. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7643. {
  7644. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7645. {
  7646. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7647. }
  7648. } // END OF FOR CHAdeMO_QUANTITY
  7649. }
  7650. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7651. {
  7652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7653. {
  7654. tempIndex = ((gun_index==2) ? 1: 0);
  7655. }
  7656. else
  7657. {
  7658. tempIndex = gun_index;
  7659. }
  7660. for (int index = 0; index < CCS_QUANTITY; index++)
  7661. {
  7662. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7663. {
  7664. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7665. }
  7666. } // END OF CCS_QUANTITY
  7667. }
  7668. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7669. {
  7670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7671. {
  7672. tempIndex = ((gun_index==2) ? 1: 0);
  7673. }
  7674. else
  7675. {
  7676. tempIndex = gun_index;
  7677. }
  7678. for (int index = 0; index < GB_QUANTITY; index++)
  7679. {
  7680. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7681. {
  7682. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7683. }
  7684. } // END OF GB_QUANTITY
  7685. }
  7686. else if(gunType[gun_index] == GUN_TYPE_DO)
  7687. {
  7688. tempIndex = gun_index;
  7689. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7690. {
  7691. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7692. {
  7693. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7694. }
  7695. }
  7696. }
  7697. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7699. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7700. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7702. }
  7703. // Message create ====================================================================================================
  7704. if(TRUE)
  7705. {
  7706. json_object *MeterValueReq = json_object_new_object();
  7707. json_object *MeterValues = json_object_new_array();
  7708. json_object *sampledValues = json_object_new_array();
  7709. json_object *sampledValuesBuffer = json_object_new_array();
  7710. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7711. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7712. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7713. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7714. {
  7715. json_object *MeterValue = json_object_new_object();
  7716. json_object *MeterValueBuffer = json_object_new_object();
  7717. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7718. {
  7719. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7720. {
  7721. json_object *sampledValue = json_object_new_object();
  7722. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7723. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7724. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7725. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7726. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7727. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7728. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7729. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7730. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7731. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7732. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7733. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7734. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7735. json_object_array_add(sampledValues, sampledValue);
  7736. // For StopTxn data
  7737. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, (char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand ) != NULL) && (strlen((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData) > 0)) ||
  7738. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, (char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) != NULL) && (strlen((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData) > 0)))
  7739. {
  7740. json_object *sampledValue = json_object_new_object();
  7741. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7742. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7743. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7744. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7745. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7746. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7747. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7748. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7749. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7750. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7751. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7752. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7753. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7754. json_object_array_add(sampledValuesBuffer, sampledValue);
  7755. }
  7756. }
  7757. }
  7758. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7759. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7760. json_object_array_add(MeterValues, MeterValue);
  7761. // For StopTxn data
  7762. if((dataType != ReadingContext_Trigger) &&
  7763. (json_object_array_length(sampledValuesBuffer) > 0))
  7764. {
  7765. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7766. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  7767. if(meterValueBufferDataQuantity(gun_index, dataType) < 250) meterValueBufferInsert(gun_index, dataType, ShmOCPP16Data->MeterValues[gun_index].TransactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  7768. json_object_put(MeterValueBuffer);
  7769. }
  7770. else
  7771. {
  7772. json_object_put(sampledValuesBuffer);
  7773. json_object_put(MeterValueBuffer);
  7774. }
  7775. }
  7776. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7777. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7778. ,gun_index + 1
  7779. ,MESSAGE_TYPE_CALL
  7780. ,guid
  7781. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7782. json_object_put(MeterValueReq);
  7783. }
  7784. // Put request guid to hash map
  7785. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7786. 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*/)
  7787. {
  7788. result = PASS;
  7789. //DEBUG_INFO("MeterValues mapitem pass\n");
  7790. }
  7791. if((dataType != ReadingContext_Trigger) &&
  7792. (dataType != ReadingContext_Sample_Clock) &&
  7793. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7794. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7795. else
  7796. {
  7797. if(FirstHeartBeat)
  7798. LWS_Send(queuedata +2);
  7799. }
  7800. return result;
  7801. }
  7802. int sendLogStatusNotificationRequest(char *status)
  7803. {
  7804. mtrace();
  7805. int result = PASS;
  7806. char message[4096]={0};
  7807. char guid[37]={0};
  7808. char tempdata[128]={0};
  7809. json_object *LogStatusNotification = json_object_new_object();
  7810. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7811. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7812. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7813. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7814. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7815. random_uuid(guid);
  7816. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7817. json_object_put(LogStatusNotification);
  7818. LWS_Send(message);
  7819. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7820. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7821. {
  7822. result = PASS;
  7823. }
  7824. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7825. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7826. return result;
  7827. }
  7828. int sendSecurityEventNotificationRequest()
  7829. {
  7830. mtrace();
  7831. int result = PASS;
  7832. char message[4096]={0};
  7833. char guid[37]={0};
  7834. char tempdata[128]={0};
  7835. json_object *SecurityEventNotification = json_object_new_object();
  7836. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7837. //Stop Transaction Time
  7838. struct timeval tmnow;
  7839. struct tm *tm;
  7840. gettimeofday(&tmnow, NULL);
  7841. time_t t;
  7842. t = time(NULL);
  7843. /*UTC time and date*/
  7844. tm = gmtime(&t);
  7845. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7846. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7847. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7848. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7849. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7850. random_uuid(guid);
  7851. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7852. json_object_put(SecurityEventNotification);
  7853. LWS_Send(message);
  7854. sprintf(tempdata, "SecurityEventNotification,0");
  7855. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7856. {
  7857. result = PASS;
  7858. }
  7859. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7860. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7861. return result;
  7862. }
  7863. int sendSignCertificateRequest()
  7864. {
  7865. mtrace();
  7866. int result = PASS;
  7867. char message[4096]={0};
  7868. char guid[37]={0};
  7869. char tempdata[128]={0};
  7870. json_object *SignCertificate = json_object_new_object();
  7871. DEBUG_INFO("sendSignCertificateRequest...\n");
  7872. // Read csr file content
  7873. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7874. FILE *fp=fopen(CSR_CP,"r");
  7875. char *line = NULL;
  7876. size_t len = 0;
  7877. while(getline(&line, &len, fp) != -1)
  7878. {
  7879. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7880. {
  7881. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7882. }
  7883. }
  7884. fclose(fp);
  7885. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7886. random_uuid(guid);
  7887. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7888. json_object_put(SignCertificate);
  7889. LWS_Send(message);
  7890. sprintf(tempdata, "SignCertificate,0");
  7891. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7892. {
  7893. result = PASS;
  7894. }
  7895. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7896. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7897. return result;
  7898. }
  7899. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7900. {
  7901. mtrace();
  7902. int result = PASS;
  7903. char message[4096]={0};
  7904. char guid[37]={0};
  7905. char tempdata[128]={0};
  7906. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  7907. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7908. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7909. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7910. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7911. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7912. random_uuid(guid);
  7913. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7914. json_object_put(SignedFirmwareStatusNotification);
  7915. LWS_Send(message);
  7916. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  7917. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7918. {
  7919. result = PASS;
  7920. }
  7921. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7922. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7923. return result;
  7924. }
  7925. //==========================================
  7926. // send confirm routine
  7927. //==========================================
  7928. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7929. {
  7930. mtrace();
  7931. int result = FAIL;
  7932. char message[100]={0};
  7933. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7934. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7935. LWS_Send(message);
  7936. result = TRUE;
  7937. return result;
  7938. }
  7939. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7940. {
  7941. mtrace();
  7942. int result = FAIL;
  7943. char message[100]={0};
  7944. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7945. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7946. LWS_Send(message);
  7947. result = TRUE;
  7948. return result;
  7949. }
  7950. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7951. {
  7952. mtrace();
  7953. int result = FAIL;
  7954. char message[100]={0};
  7955. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7956. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7957. LWS_Send(message);
  7958. result = TRUE;
  7959. return result;
  7960. }
  7961. int sendClearCacheConfirmation(char *uuid,char *payload)
  7962. {
  7963. mtrace();
  7964. int result = FAIL;
  7965. char message[500]={0};
  7966. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7967. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7968. LWS_Send(message);
  7969. return result;
  7970. }
  7971. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7972. {
  7973. mtrace();
  7974. int result = FAIL;
  7975. char message[500]={0};
  7976. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7977. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7978. LWS_Send(message);
  7979. return result;
  7980. }
  7981. int sendDataTransferConfirmation(char *uuid,char *payload)
  7982. {
  7983. mtrace();
  7984. char statusStr[20]={0};
  7985. char dataStr[10]={0};
  7986. char sstr[20]={0};
  7987. int c = 0;
  7988. char *loc;
  7989. int result = FAIL;
  7990. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7991. /**********************status**************************/
  7992. loc = strstr(payload, "status");
  7993. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7994. c = 0;
  7995. while (loc[3+strlen("status")+c] != '\"')
  7996. {
  7997. sstr[c] = loc[3+strlen("status")+c];
  7998. c++;
  7999. }
  8000. sstr[c] = '\0';
  8001. strcpy(statusStr, sstr);
  8002. /**********************data**************************/
  8003. loc = strstr(payload, "data");
  8004. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8005. c = 0;
  8006. while (loc[3+strlen("data")+c] != '\"')
  8007. {
  8008. sstr[c] = loc[3+strlen("data")+c];
  8009. c++;
  8010. }
  8011. sstr[c] = '\0';
  8012. strcpy(dataStr, sstr);
  8013. return result;
  8014. }
  8015. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8016. {
  8017. mtrace();
  8018. int result = FAIL;
  8019. char message[1000]={0};
  8020. int CompositeScheduleIndex = 0;
  8021. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8022. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8023. if(nPeriod == 0)
  8024. {
  8025. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8026. {
  8027. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8028. ,MESSAGE_TYPE_CALLRESULT
  8029. ,uuid
  8030. ,payload
  8031. ,connectorIdInt);
  8032. }
  8033. else
  8034. {
  8035. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8036. ,MESSAGE_TYPE_CALLRESULT
  8037. ,uuid
  8038. ,payload
  8039. ,connectorIdInt
  8040. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8041. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8042. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8043. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8044. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8045. }
  8046. }
  8047. else
  8048. {
  8049. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8050. ,MESSAGE_TYPE_CALLRESULT
  8051. ,uuid
  8052. ,payload
  8053. ,connectorIdInt
  8054. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8055. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8056. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8057. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8058. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8059. {
  8060. if (idx_sample == 0)
  8061. {
  8062. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8063. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8064. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8065. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8066. }
  8067. else
  8068. {
  8069. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8070. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8071. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8072. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8073. }
  8074. }
  8075. sprintf(message + strlen(message), "]}}]");
  8076. }
  8077. LWS_Send(message);
  8078. result = TRUE;
  8079. return result;
  8080. }
  8081. int sendGetConfigurationConfirmation(char *uuid)
  8082. {
  8083. mtrace();
  8084. int result = FAIL;
  8085. int MaxKeySupported = 0;
  8086. int sentConfigurationNumber= 0;
  8087. int sentunConfigurationNumber= 0;
  8088. char message[1024*10]={0};
  8089. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8090. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8091. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8092. ,MESSAGE_TYPE_CALLRESULT
  8093. ,uuid );
  8094. //configuration key
  8095. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8096. {
  8097. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8098. {
  8099. if (sentConfigurationNumber == 0)
  8100. {
  8101. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8102. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8103. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8104. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8105. }
  8106. else
  8107. {
  8108. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8109. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8110. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8111. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8112. }
  8113. sentConfigurationNumber = sentConfigurationNumber + 1;
  8114. }
  8115. }
  8116. sprintf(message + strlen(message), "]");
  8117. if(UnknownKeynum != 0)
  8118. {
  8119. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8120. //unkown key
  8121. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8122. {
  8123. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8124. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8125. if(sentunConfigurationNumber == 0)
  8126. {
  8127. sprintf(message + strlen(message), "\"%s\""
  8128. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8129. }
  8130. else
  8131. {
  8132. sprintf(message + strlen(message), ",\"%s\""
  8133. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8134. }
  8135. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8136. }
  8137. sprintf(message + strlen(message), "]");
  8138. }
  8139. sprintf(message + strlen(message), "}]");
  8140. LWS_Send(message);
  8141. return result;
  8142. }
  8143. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8144. {
  8145. mtrace();
  8146. int result = FAIL;
  8147. char message[400]={0};
  8148. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8149. if(strcmp(payload,"")==0)
  8150. {
  8151. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8152. }
  8153. else
  8154. {
  8155. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8156. }
  8157. LWS_Send(message);
  8158. result = TRUE;
  8159. return result;
  8160. }
  8161. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8162. {
  8163. mtrace();
  8164. int result = FAIL;
  8165. char message[80]={0};
  8166. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8167. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8168. LWS_Send(message);
  8169. result = TRUE;
  8170. return result;
  8171. }
  8172. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8173. {
  8174. mtrace();
  8175. int result = FAIL;
  8176. char message[80]={0};
  8177. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8178. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8179. LWS_Send(message);
  8180. result = TRUE;
  8181. return result;
  8182. }
  8183. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8184. {
  8185. mtrace();
  8186. int result = FAIL;
  8187. char message[80]={0};
  8188. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8189. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8190. LWS_Send(message);
  8191. result = TRUE;
  8192. return result;
  8193. }
  8194. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8195. {
  8196. mtrace();
  8197. int result = FAIL;
  8198. char message[80]={0};
  8199. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8200. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8201. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8202. LWS_Send(message);
  8203. result = TRUE;
  8204. return result;
  8205. }
  8206. int sendResetConfirmation(char *uuid,char *payload)
  8207. {
  8208. mtrace();
  8209. int result = FAIL;
  8210. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8211. char message[80]={0};
  8212. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8213. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8214. LWS_Send(message);
  8215. result = TRUE;
  8216. return result;
  8217. }
  8218. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8219. {
  8220. mtrace();
  8221. int result = FAIL;
  8222. char message[500]={0};
  8223. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8224. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8225. LWS_Send(message);
  8226. result = TRUE;
  8227. return result;
  8228. }
  8229. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8230. {
  8231. mtrace();
  8232. int result = FAIL;
  8233. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8234. char message[80]={0};
  8235. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8236. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8237. LWS_Send(message);
  8238. result = TRUE;
  8239. return result;
  8240. }
  8241. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8242. {
  8243. mtrace();
  8244. int result = FAIL;
  8245. char message[80]={0};
  8246. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8247. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8248. LWS_Send(message);
  8249. result = TRUE;
  8250. return result;
  8251. }
  8252. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8253. {
  8254. mtrace();
  8255. int result = FAIL;
  8256. char message[80]={0};
  8257. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8258. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8259. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8260. LWS_Send(message);
  8261. result = TRUE;
  8262. return result;
  8263. }
  8264. int sendUpdateFirmwareConfirmation(char *uuid)
  8265. {
  8266. mtrace();
  8267. int result = FAIL;
  8268. char message[60]={0};
  8269. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8270. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8271. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8272. LWS_Send(message);
  8273. result = TRUE;
  8274. return result;
  8275. }
  8276. int sendCertificateSignedConfirmation(char *uuid)
  8277. {
  8278. mtrace();
  8279. int result = PASS;
  8280. char message[4096]={0};
  8281. json_object *CertificateSigned = json_object_new_object();
  8282. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8283. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8284. sprintf(message,"[%d,\"%s\",%s]"
  8285. ,MESSAGE_TYPE_CALLRESULT
  8286. ,uuid
  8287. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8288. json_object_put(CertificateSigned);
  8289. LWS_Send(message);
  8290. return result;
  8291. }
  8292. int sendDeleteCertificateConfirmation(char *uuid)
  8293. {
  8294. mtrace();
  8295. int result = PASS;
  8296. char message[4096]={0};
  8297. json_object *DeleteCertificate = json_object_new_object();
  8298. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8299. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8300. sprintf(message,"[%d,\"%s\",%s]"
  8301. ,MESSAGE_TYPE_CALLRESULT
  8302. ,uuid
  8303. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8304. json_object_put(DeleteCertificate);
  8305. LWS_Send(message);
  8306. return result;
  8307. }
  8308. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8309. {
  8310. mtrace();
  8311. int result = PASS;
  8312. char message[4096]={0};
  8313. json_object *ExtendedTriggerMessage = json_object_new_object();
  8314. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8315. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8316. sprintf(message,"[%d,\"%s\",%s]"
  8317. ,MESSAGE_TYPE_CALLRESULT
  8318. ,uuid
  8319. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8320. json_object_put(ExtendedTriggerMessage);
  8321. LWS_Send(message);
  8322. return result;
  8323. }
  8324. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8325. {
  8326. mtrace();
  8327. int result = PASS;
  8328. char message[4096]={0};
  8329. json_object *GetInstalledCertificateIds = json_object_new_object();
  8330. json_object *certificateHashDataDatas = json_object_new_array();
  8331. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8332. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8333. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8334. {
  8335. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8336. {
  8337. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8338. {
  8339. json_object *certificateHashData = json_object_new_object();
  8340. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8341. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8342. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8343. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8344. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8345. }
  8346. }
  8347. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8348. }
  8349. else
  8350. {
  8351. json_object_put(certificateHashDataDatas);
  8352. }
  8353. sprintf(message,"[%d,\"%s\",%s]"
  8354. ,MESSAGE_TYPE_CALLRESULT
  8355. ,uuid
  8356. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8357. json_object_put(GetInstalledCertificateIds);
  8358. LWS_Send(message);
  8359. return result;
  8360. }
  8361. int sendGetLogConfirmation(char *uuid)
  8362. {
  8363. mtrace();
  8364. int result = PASS;
  8365. char message[4096]={0};
  8366. json_object *GetLog = json_object_new_object();
  8367. DEBUG_INFO("sendGetLogConfirmation...\n");
  8368. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8369. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8370. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8371. sprintf(message,"[%d,\"%s\",%s]"
  8372. ,MESSAGE_TYPE_CALLRESULT
  8373. ,uuid
  8374. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8375. json_object_put(GetLog);
  8376. LWS_Send(message);
  8377. return result;
  8378. }
  8379. int sendInstallCertificateConfirmation(char *uuid)
  8380. {
  8381. mtrace();
  8382. int result = PASS;
  8383. char message[4096]={0};
  8384. json_object *InstallCertificate = json_object_new_object();
  8385. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8386. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8387. sprintf(message,"[%d,\"%s\",%s]"
  8388. ,MESSAGE_TYPE_CALLRESULT
  8389. ,uuid
  8390. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8391. json_object_put(InstallCertificate);
  8392. LWS_Send(message);
  8393. return result;
  8394. }
  8395. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8396. {
  8397. mtrace();
  8398. int result = PASS;
  8399. char message[4096]={0};
  8400. json_object *SignedUpdateFirmware = json_object_new_object();
  8401. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8402. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8403. sprintf(message,"[%d,\"%s\",%s]"
  8404. ,MESSAGE_TYPE_CALLRESULT
  8405. ,uuid
  8406. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8407. json_object_put(SignedUpdateFirmware);
  8408. LWS_Send(message);
  8409. return result;
  8410. }
  8411. int sendUnknownConfirmation(char *uuid)
  8412. {
  8413. mtrace();
  8414. int result = PASS;
  8415. char message[256]={0};
  8416. DEBUG_INFO("sendUnknownConfirmation...\n");
  8417. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8418. LWS_Send(message);
  8419. return result;
  8420. }
  8421. //==========================================
  8422. // Handle server request routine Start
  8423. //==========================================
  8424. int handleCancelReservationRequest(char *uuid, char *payload)
  8425. {
  8426. mtrace();
  8427. int result = FAIL;
  8428. int gunNO = 0;
  8429. int reservationIdInt = -1;
  8430. char comfirmstr[20];
  8431. DEBUG_INFO("handleCancelReservationRequest...\n");
  8432. json_object *CancelReservation;
  8433. CancelReservation = json_tokener_parse(payload);
  8434. if(!is_error(CancelReservation))
  8435. {
  8436. // Required data
  8437. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8438. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8439. }
  8440. json_object_put(CancelReservation);
  8441. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8442. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8443. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8444. if(reservationIdInt != -1)
  8445. {
  8446. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8447. //check Transaction active
  8448. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8449. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8450. {
  8451. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8452. {
  8453. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8454. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8455. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8456. {
  8457. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8458. }
  8459. else
  8460. {
  8461. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8462. }
  8463. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8464. goto end;
  8465. }
  8466. }
  8467. for (int index = 0; index < CCS_QUANTITY; index++)
  8468. {
  8469. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8470. {
  8471. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8472. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8473. if(gunType[2] == GUN_TYPE_CCS)
  8474. {
  8475. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8476. }
  8477. else
  8478. {
  8479. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8480. }
  8481. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8482. goto end;
  8483. }
  8484. }
  8485. for (int index = 0; index < GB_QUANTITY; index++)
  8486. {
  8487. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8488. {
  8489. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8490. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8491. if(gunType[2] == GUN_TYPE_GBT)
  8492. {
  8493. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8494. }
  8495. else
  8496. {
  8497. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8498. }
  8499. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8500. goto end;
  8501. }
  8502. }
  8503. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8504. {
  8505. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8506. {
  8507. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8508. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8509. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8510. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8511. goto end;
  8512. }
  8513. }
  8514. for (int index = 0; index < AC_QUANTITY; index++)
  8515. {
  8516. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8517. {
  8518. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8519. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8520. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8521. {
  8522. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8523. }
  8524. else
  8525. {
  8526. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8527. }
  8528. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8529. goto end;
  8530. }
  8531. }
  8532. }
  8533. //The reservationId does NOT match the reservationId
  8534. sendCancelReservationConfirmation(uuid, comfirmstr);
  8535. end:
  8536. // Fill in ocpp packet uuid
  8537. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8538. return result;
  8539. }
  8540. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8541. {
  8542. mtrace();
  8543. int result = FAIL;
  8544. int gunIndex = -1;
  8545. char typeStr[16]={0};
  8546. char comfirmstr[20];
  8547. int specificId = FALSE;
  8548. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8549. json_object *ChangeAvailability;
  8550. ChangeAvailability = json_tokener_parse(payload);
  8551. if(!is_error(ChangeAvailability))
  8552. {
  8553. // Required data
  8554. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8555. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8556. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8557. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8558. }
  8559. json_object_put(ChangeAvailability);
  8560. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8561. {
  8562. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8563. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8564. }
  8565. else if(gunIndex == 0)
  8566. {
  8567. for(int i=0; i < gunTotalNumber; i++)
  8568. {
  8569. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8570. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8571. }
  8572. }
  8573. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8574. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8575. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8576. {
  8577. specificId = TRUE;
  8578. }
  8579. if(specificId == FALSE)
  8580. goto end;
  8581. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8582. {
  8583. //----------------------gunIndex is 0 ------------------------------------------------//
  8584. if(gunIndex == 0)
  8585. {
  8586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8587. {
  8588. for(int i=0; i < gunTotalNumber; i++)
  8589. {
  8590. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8591. {
  8592. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8593. {
  8594. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8595. {
  8596. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8597. goto end;
  8598. }
  8599. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8600. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8601. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8602. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8603. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8604. {
  8605. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8606. goto end;
  8607. }
  8608. }
  8609. }//END FOR CHAdeMO_QUANTITY
  8610. for (int index = 0; index < CCS_QUANTITY; index++)
  8611. {
  8612. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8613. {
  8614. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8615. {
  8616. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8617. goto end;
  8618. }
  8619. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8620. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8621. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8622. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8623. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8624. {
  8625. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8626. goto end;
  8627. }
  8628. }
  8629. }//END FOR CCS_QUANTITY
  8630. for (int index = 0; index < GB_QUANTITY; index++)
  8631. {
  8632. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8633. {
  8634. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8635. {
  8636. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8637. goto end;
  8638. }
  8639. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8640. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8641. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8642. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8643. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8644. {
  8645. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8646. goto end;
  8647. }
  8648. }
  8649. }// END FOR GB_QUANTITY
  8650. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8651. {
  8652. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8653. {
  8654. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8655. {
  8656. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8657. goto end;
  8658. }
  8659. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8660. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8661. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8662. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8663. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8664. {
  8665. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8666. goto end;
  8667. }
  8668. }
  8669. }// END FOR GENERAL_GUN_QUANTITY
  8670. for (int index = 0; index < AC_QUANTITY; index++)
  8671. {
  8672. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8673. {
  8674. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8675. {
  8676. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8677. goto end;
  8678. }
  8679. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8680. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8681. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8682. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8683. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8684. {
  8685. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8686. goto end;
  8687. }
  8688. }
  8689. }//END FOR AC_QUANTITY
  8690. }// END FOR gunTotalNumber
  8691. }
  8692. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8693. {
  8694. for(int i=0; i < gunTotalNumber; i++)
  8695. {
  8696. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8697. {
  8698. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8699. goto end;
  8700. }
  8701. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8702. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8703. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8704. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8705. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8706. {
  8707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8708. goto end;
  8709. }
  8710. }
  8711. }
  8712. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8713. goto end;
  8714. }
  8715. //----------------------gunIndex is not 0 ------------------------------------------------//
  8716. //check Transaction active
  8717. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8718. {
  8719. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8720. {
  8721. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8722. {
  8723. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8724. goto end;
  8725. }
  8726. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8727. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8728. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8729. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8730. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8731. {
  8732. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8733. goto end;
  8734. }
  8735. else
  8736. {
  8737. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8738. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8739. goto end;
  8740. }
  8741. }
  8742. }//END FOR CHAdeMO_QUANTITY
  8743. for (int index = 0; index < CCS_QUANTITY; index++)
  8744. {
  8745. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8746. {
  8747. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8748. {
  8749. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8750. goto end;
  8751. }
  8752. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8753. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8754. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8755. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8756. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8757. {
  8758. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8759. goto end;
  8760. }
  8761. else
  8762. {
  8763. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8764. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8765. goto end;
  8766. }
  8767. }
  8768. }//END FOR CCS_QUANTITY
  8769. for (int index = 0; index < GB_QUANTITY; index++)
  8770. {
  8771. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8772. {
  8773. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8774. {
  8775. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8776. goto end;
  8777. }
  8778. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8779. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8780. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8781. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8782. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8783. {
  8784. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8785. goto end;
  8786. }
  8787. else
  8788. {
  8789. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8790. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8791. goto end;
  8792. }
  8793. }
  8794. }// END FOR GB_QUANTITY
  8795. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8796. {
  8797. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8798. {
  8799. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8800. {
  8801. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8802. goto end;
  8803. }
  8804. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8805. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8806. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8807. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8808. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8809. {
  8810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8811. goto end;
  8812. }
  8813. else
  8814. {
  8815. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8816. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8817. goto end;
  8818. }
  8819. }
  8820. }// END FOR GENERAL_GUN_QUANTITY
  8821. for (int index = 0; index < AC_QUANTITY; index++)
  8822. {
  8823. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8824. {
  8825. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8826. {
  8827. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8828. goto end;
  8829. }
  8830. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8831. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8832. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8833. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8834. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8835. {
  8836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8837. goto end;
  8838. }
  8839. else
  8840. {
  8841. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8842. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8843. goto end;
  8844. }
  8845. }
  8846. }//END FOR AC_QUANTITY
  8847. }//END FOR AvailabilityTypeStr[Inoperative]
  8848. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8849. {
  8850. //----------------------gunIndex is 0 ------------------------------------------------//
  8851. if(gunIndex == 0)
  8852. {
  8853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8854. {
  8855. for(int i=0; i < gunTotalNumber; i++)
  8856. {
  8857. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8858. {
  8859. 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
  8860. {
  8861. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8862. goto end;
  8863. }
  8864. }//END FOR CHAdeMO_QUANTITY
  8865. for (int index = 0; index < CCS_QUANTITY; index++)
  8866. {
  8867. 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
  8868. {
  8869. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8870. goto end;
  8871. }
  8872. }//END FOR CCS_QUANTITY
  8873. for (int index = 0; index < GB_QUANTITY; index++)
  8874. {
  8875. 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
  8876. {
  8877. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8878. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8879. goto end;
  8880. }
  8881. }// END FOR GB_QUANTITY
  8882. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8883. {
  8884. 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
  8885. {
  8886. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8887. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8888. goto end;
  8889. }
  8890. }// END FOR GENERAL_GUN_QUANTITY
  8891. for (int index = 0; index < AC_QUANTITY; index++)
  8892. {
  8893. 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
  8894. {
  8895. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8896. goto end;
  8897. }
  8898. }//END FOR CHAdeMO_QUANTITY
  8899. }// END FOR gunTotalNumber
  8900. }
  8901. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8902. {
  8903. for(int i=0; i < gunTotalNumber; i++)
  8904. {
  8905. for (int index = 0; index < AC_QUANTITY; index++)
  8906. {
  8907. 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
  8908. {
  8909. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8910. goto end;
  8911. }
  8912. }//END FOR CHAdeMO_QUANTITY
  8913. } // END FOR gunTotalNumber
  8914. }
  8915. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8916. goto end;
  8917. }
  8918. //----------------------gunIndex is not 0 ------------------------------------------------//
  8919. //check Transaction active
  8920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8921. {
  8922. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8923. {
  8924. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8925. goto end;
  8926. }
  8927. }//END FOR CHAdeMO_QUANTITY
  8928. for (int index = 0; index < CCS_QUANTITY; index++)
  8929. {
  8930. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8931. {
  8932. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8933. goto end;
  8934. }
  8935. }//END FOR CCS_QUANTITY
  8936. for (int index = 0; index < GB_QUANTITY; index++)
  8937. {
  8938. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8939. {
  8940. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8941. goto end;
  8942. }
  8943. }// END FOR GB_QUANTITY
  8944. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8945. {
  8946. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8947. {
  8948. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8949. goto end;
  8950. }
  8951. }// END FOR GENERAL_GUN_QUANTITY
  8952. for (int index = 0; index < AC_QUANTITY; index++)
  8953. {
  8954. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8955. {
  8956. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8957. goto end;
  8958. }
  8959. }//END FOR AC_QUANTITY
  8960. }//END FOR AvailabilityTypeStr[Operative]
  8961. end:
  8962. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8963. {
  8964. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8965. }
  8966. else
  8967. {
  8968. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8969. }
  8970. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8971. {
  8972. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8973. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8974. }
  8975. else if(gunIndex == 0)
  8976. {
  8977. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8978. {
  8979. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8980. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8981. }
  8982. }
  8983. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8984. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8985. return result;
  8986. }
  8987. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8988. {
  8989. mtrace();
  8990. int valueInvalid = NO;
  8991. int result = FAIL;
  8992. char keystr[40]={0};
  8993. char valuestr[501]={0}; //value should be limited in 500 bytes
  8994. char comfirmstr[20]={0};
  8995. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8996. json_object *ChangeConfiguration;
  8997. ChangeConfiguration = json_tokener_parse(payload);
  8998. if(!is_error(ChangeConfiguration))
  8999. {
  9000. // Required data
  9001. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9002. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9003. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9004. {
  9005. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9006. }
  9007. else
  9008. {
  9009. valueInvalid = YES;
  9010. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9011. }
  9012. }
  9013. json_object_put(ChangeConfiguration);
  9014. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9015. {
  9016. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9017. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9018. }
  9019. else
  9020. {
  9021. int status = setKeyValue(keystr, valuestr);
  9022. switch(status)
  9023. {
  9024. case ConfigurationStatus_Accepted:
  9025. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9026. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9027. StoreConfigurationTable();
  9028. break;
  9029. case RebootRequired:
  9030. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9031. StoreConfigurationTable();
  9032. break;
  9033. case NotSupported:
  9034. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9035. break;
  9036. case ConfigurationStatus_Rejected:
  9037. default:
  9038. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9039. break;
  9040. }
  9041. }
  9042. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9043. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9044. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9045. {
  9046. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9047. SetOcppConnStatus(FALSE);
  9048. }
  9049. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9050. {
  9051. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9052. }
  9053. return result;
  9054. }
  9055. int handleClearCacheRequest(char *uuid, char *payload)
  9056. {
  9057. mtrace();
  9058. int result = FAIL;
  9059. char comfirmstr[20];
  9060. char rmFileCmd[100]={0};
  9061. struct stat stats;
  9062. DEBUG_INFO("handleClearCacheRequest...\n");
  9063. stat("/Storage/OCPP", &stats);
  9064. // Check for directory existence
  9065. if (S_ISDIR(stats.st_mode) == 1)
  9066. {}
  9067. else
  9068. {
  9069. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9070. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9071. system(rmFileCmd);
  9072. }
  9073. if(OCPP_cleanLocalCache())
  9074. {
  9075. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9076. }
  9077. else
  9078. {
  9079. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9080. }
  9081. sendClearCacheConfirmation(uuid, comfirmstr);
  9082. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9083. return result;
  9084. }
  9085. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9086. {
  9087. mtrace();
  9088. int result = FAIL;
  9089. int resultRename;
  9090. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9091. char chargingProfilePurposeStr[26]={0};
  9092. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9093. char tempchargingProfilePurposeStr[26]={0};
  9094. char str[100]={0};
  9095. char fname[200]={0};
  9096. char comfirmstr[20]={0};
  9097. char word[1600]={0};
  9098. int clearflag = FALSE;
  9099. int chargingProfileIdIsNULL = FALSE;
  9100. int connectorIsNULL = FALSE;
  9101. int chargingProfilePurposeIsNULL = FALSE;
  9102. int stackLevelIsNULL = FALSE;
  9103. //int GotoEnd = FALSE;
  9104. FILE *fptr1, *fptr2;
  9105. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9106. int n_chargingProfile=0;
  9107. int isEmptyFile = FALSE;
  9108. char sLineWord[1600]={0};
  9109. char chargingProfiles[10][100]={0};
  9110. int ChargeProfileCount = 0;
  9111. int ch;
  9112. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9113. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9114. json_object *ClearChargingProfile;
  9115. ClearChargingProfile = json_tokener_parse(payload);
  9116. if(!is_error(ClearChargingProfile))
  9117. {
  9118. // Optional data
  9119. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9120. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9121. else
  9122. chargingProfileIdIsNULL = TRUE;
  9123. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9124. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9125. else
  9126. connectorIsNULL = TRUE;
  9127. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9128. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9129. else
  9130. chargingProfilePurposeIsNULL = TRUE;
  9131. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9132. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9133. else
  9134. stackLevelIsNULL = TRUE;
  9135. }
  9136. json_object_put(ClearChargingProfile);
  9137. if(connectorIsNULL == FALSE)
  9138. {
  9139. switch(connectorIdInt)
  9140. {
  9141. case 0:
  9142. if(chargingProfilePurposeIsNULL == TRUE)
  9143. {
  9144. int l = 0;
  9145. strcpy(fname, ChargePointMaxProfile_JSON);
  9146. if((access(fname,F_OK))!=-1)
  9147. {
  9148. strcpy(chargingProfiles[l], fname);
  9149. l = l + 1;
  9150. }
  9151. strcpy(fname, TxDefaultProfile_0_JSON);
  9152. if((access(fname,F_OK))!=-1)
  9153. {
  9154. strcpy(chargingProfiles[l], fname);
  9155. l = l + 1;
  9156. }
  9157. ChargeProfileCount = l;
  9158. }
  9159. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9160. {
  9161. strcpy(fname, ChargePointMaxProfile_JSON);
  9162. if((access(fname,F_OK))!=-1)
  9163. {
  9164. strcpy(chargingProfiles[0], fname);
  9165. ChargeProfileCount = 1;
  9166. }
  9167. }
  9168. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9169. {
  9170. strcpy(fname, TxDefaultProfile_0_JSON);
  9171. if((access(fname,F_OK))!=-1)
  9172. {
  9173. strcpy(chargingProfiles[0], fname);
  9174. ChargeProfileCount = 1;
  9175. }
  9176. }
  9177. break;
  9178. default:
  9179. if(chargingProfilePurposeIsNULL == TRUE)
  9180. {
  9181. int m = 0;
  9182. memset(fname, 0, ARRAY_SIZE(fname));
  9183. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9184. if((access(fname,F_OK))!=-1)
  9185. {
  9186. strcpy(chargingProfiles[m], fname);
  9187. m = m + 1;
  9188. }
  9189. memset(fname, 0, ARRAY_SIZE(fname));
  9190. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9191. if((access(fname,F_OK))!=-1)
  9192. {
  9193. strcpy(chargingProfiles[m], fname);
  9194. m = m + 1;
  9195. }
  9196. ChargeProfileCount = m;
  9197. }
  9198. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9199. {
  9200. //strcpy(fname, TxDefaultProfile_1_JSON);
  9201. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9202. if((access(fname,F_OK))!=-1)
  9203. {
  9204. strcpy(chargingProfiles[0], fname);
  9205. ChargeProfileCount = 1;
  9206. }
  9207. }
  9208. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9209. {
  9210. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9211. if((access(fname,F_OK))!=-1)
  9212. {
  9213. strcpy(chargingProfiles[0], fname);
  9214. ChargeProfileCount = 1;
  9215. }
  9216. //strcpy(fname, TxProfile_1_JSON);
  9217. }
  9218. //strcpy(fname, ChargePointMaxProfile_JSON );
  9219. break;
  9220. }
  9221. }
  9222. else // Check all Charging Profiles
  9223. {
  9224. int i = 0;
  9225. char fnametemp[200]={0};
  9226. ChargeProfileCount = 0;
  9227. //Check ChargePointMaxProfile.json exit
  9228. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9229. {
  9230. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9231. i = i + 1;
  9232. }
  9233. //Check TxDefaultProfile_0.json exit
  9234. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9235. {
  9236. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9237. i = i + 1;
  9238. }
  9239. //Check TxDefaultProfile_%d.json
  9240. for(int j=1; j <= gunTotalNumber; j++)
  9241. {
  9242. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9243. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9244. if((access(fnametemp,F_OK))!=-1)
  9245. {
  9246. strcpy(chargingProfiles[i], fnametemp);
  9247. i = i + 1;
  9248. }
  9249. }
  9250. //Check TxProfile_%d.json
  9251. for(int j=1; j <= gunTotalNumber; j++)
  9252. {
  9253. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9254. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9255. if((access(fnametemp,F_OK))!=-1)
  9256. {
  9257. strcpy(chargingProfiles[i], fnametemp);
  9258. i = i + 1;
  9259. }
  9260. }
  9261. ChargeProfileCount = i;
  9262. }// End connectorIsNULL is TRUE
  9263. if(ChargeProfileCount == 0)
  9264. {
  9265. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9266. goto end;
  9267. }
  9268. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9269. {
  9270. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9271. goto end;
  9272. }
  9273. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9274. {
  9275. memset(str, 0, ARRAY_SIZE(str));
  9276. // clear temp file
  9277. sprintf(str,"rm -f %s",temp);
  9278. system(str);
  9279. for(int k=0; k < ChargeProfileCount; k++)
  9280. {
  9281. memset(str, 0, ARRAY_SIZE(str));
  9282. //clear file in C
  9283. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9284. system(str);
  9285. }
  9286. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9287. goto end;
  9288. }
  9289. else if(connectorIsNULL == TRUE)
  9290. {
  9291. for(int k=0; k < ChargeProfileCount; k++)
  9292. {
  9293. fptr1 = fopen(chargingProfiles[k], "r");
  9294. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9295. //Check Charging Profile Count
  9296. while(fscanf(fptr1, "%s", word) != EOF)
  9297. {
  9298. //DEBUG_INFO("word=%s\n",word);
  9299. if(strstr(word, "chargingProfileId")!= NULL)
  9300. {
  9301. //DEBUG_INFO("test chargingProfileId \n");
  9302. n_chargingProfile = n_chargingProfile + 1;
  9303. //DEBUG_INFO("chargingProfileId Found\n");
  9304. }
  9305. }
  9306. rewind(fptr1);
  9307. //search Charging Profile Element
  9308. //int i= 0;
  9309. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9310. {
  9311. json_object *tmpProfilee;
  9312. tmpProfilee = json_tokener_parse(sLineWord);
  9313. if(!is_error(tmpProfilee))
  9314. {
  9315. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9316. {
  9317. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9318. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9319. }
  9320. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9321. {
  9322. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9323. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9324. }
  9325. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9326. {
  9327. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9328. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9329. }
  9330. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9331. {
  9332. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9333. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9334. }
  9335. }
  9336. json_object_put(tmpProfilee);
  9337. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9338. {
  9339. //------- not write to fptr2-------//
  9340. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9341. //clearflag = TRUE;
  9342. }
  9343. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9344. {
  9345. //------- not write to fptr2-------//
  9346. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9347. }
  9348. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9349. {
  9350. //------- not write to fptr2-------//
  9351. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9352. }
  9353. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9354. {
  9355. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9356. }
  9357. else
  9358. {
  9359. fprintf(fptr2, sLineWord);//writing data into file
  9360. }
  9361. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9362. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9363. if(clearflag == TRUE)
  9364. {
  9365. fclose(fptr1);
  9366. fclose(fptr2);
  9367. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9368. system(str);
  9369. // clear temp file
  9370. sprintf(str,"rm -f %s",temp);
  9371. system(str);
  9372. }
  9373. else
  9374. {
  9375. fclose(fptr1);
  9376. fclose(fptr2);
  9377. memset(str, 0, ARRAY_SIZE(str));
  9378. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9379. system(str);
  9380. resultRename = rename(temp, chargingProfiles[k]);
  9381. if(resultRename == 0)
  9382. {
  9383. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9384. }
  9385. else
  9386. {
  9387. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9388. }
  9389. if(comfirmstr[0]== 0)
  9390. {
  9391. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9392. }
  9393. //Check chargingProfile is empty file
  9394. /*------ Read the file ----------------*/
  9395. fptr1=fopen(chargingProfiles[k],"r");
  9396. ch=fgetc(fptr1);
  9397. rewind(fptr1);
  9398. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9399. if(ch!=EOF)
  9400. {
  9401. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9402. {
  9403. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9404. if(sLineWord[0]=='\0')
  9405. {
  9406. isEmptyFile = TRUE;
  9407. break;
  9408. }
  9409. else
  9410. {
  9411. isEmptyFile = FALSE;
  9412. break;
  9413. }
  9414. }
  9415. }
  9416. else
  9417. isEmptyFile = TRUE;
  9418. fclose(fptr1);
  9419. if(isEmptyFile == TRUE)
  9420. {
  9421. memset(str, 0, ARRAY_SIZE(str));
  9422. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9423. system(str);
  9424. }
  9425. }
  9426. }// End of while(int k=0; k < ChargePointCount; k++)
  9427. }
  9428. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9429. {
  9430. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9431. for(int k=0; k < ChargeProfileCount; k++)
  9432. {
  9433. fptr1 = fopen(chargingProfiles[k], "r");
  9434. fptr2 = fopen(temp, "w+");
  9435. //Check Charging Profile Count
  9436. while(fscanf(fptr1, "%s", word) != EOF)
  9437. {
  9438. //DEBUG_INFO("word=%s\n",word);
  9439. if(strstr(word, "chargingProfileId")!= NULL)
  9440. {
  9441. n_chargingProfile = n_chargingProfile + 1;
  9442. }
  9443. }
  9444. rewind(fptr1);
  9445. //search Charging Profile Element
  9446. //int i= 0;
  9447. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9448. {
  9449. json_object *tmpProfilee;
  9450. tmpProfilee = json_tokener_parse(sLineWord);
  9451. if(!is_error(tmpProfilee))
  9452. {
  9453. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9454. {
  9455. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9456. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9457. }
  9458. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9459. {
  9460. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9461. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9462. }
  9463. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9464. {
  9465. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9466. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9467. }
  9468. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9469. {
  9470. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9471. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9472. }
  9473. }
  9474. json_object_put(tmpProfilee);
  9475. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9476. {
  9477. //------- not write to fptr2-------//
  9478. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9479. //clearflag = TRUE;
  9480. }
  9481. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9482. {
  9483. //------- not write to fptr2-------//
  9484. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9485. }
  9486. else if(stackLevelIsNULL == TRUE)
  9487. {
  9488. //Clear Whole File
  9489. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9490. clearflag = TRUE;
  9491. break;
  9492. }
  9493. else
  9494. {
  9495. fprintf(fptr2, sLineWord);//writing data into file
  9496. }
  9497. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9498. }
  9499. if(clearflag == TRUE)
  9500. {
  9501. fclose(fptr1);
  9502. fclose(fptr2);
  9503. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9504. system(str);
  9505. // clear temp file
  9506. sprintf(str,"rm -f %s",temp);
  9507. system(str);
  9508. }
  9509. else
  9510. {
  9511. fclose(fptr1);
  9512. fclose(fptr2);
  9513. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9514. system(str);
  9515. resultRename = rename(temp, chargingProfiles[k]);
  9516. if(resultRename == 0)
  9517. {
  9518. DEBUG_INFO("File ChargingProfile renamed successfully");
  9519. }
  9520. else
  9521. {
  9522. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9523. }
  9524. if(comfirmstr[0]== 0)
  9525. {
  9526. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9527. }
  9528. //Check chargingProfile is empty file
  9529. /*------ Read the file ----------------*/
  9530. fptr1=fopen(chargingProfiles[k],"r");
  9531. ch=fgetc(fptr1);
  9532. rewind(fptr1);
  9533. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9534. if(ch!=EOF)
  9535. {
  9536. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9537. {
  9538. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9539. if(sLineWord[0]=='\0')
  9540. {
  9541. isEmptyFile = TRUE;
  9542. break;
  9543. }
  9544. else
  9545. {
  9546. isEmptyFile = FALSE;
  9547. break;
  9548. }
  9549. }
  9550. }
  9551. else
  9552. isEmptyFile = TRUE;
  9553. fclose(fptr1);
  9554. if(isEmptyFile == TRUE)
  9555. {
  9556. memset(str, 0, ARRAY_SIZE(str));
  9557. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9558. system(str);
  9559. }
  9560. /*------- End of reading ---------------*/
  9561. }
  9562. } // while(int k=0; k < ChargeProfileCount; k++)
  9563. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9564. end:
  9565. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9566. {
  9567. if(connectorIdInt == 0)
  9568. {
  9569. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9570. {
  9571. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9572. }
  9573. }
  9574. else
  9575. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9576. }
  9577. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9578. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9579. return result;
  9580. }
  9581. void createFirmwareVersionByDataTransfer(void)
  9582. {
  9583. json_object *FirmwareDataTransfer = json_object_new_object();
  9584. // AC & DC model
  9585. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9586. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9587. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9588. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9589. // DC model
  9590. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9591. {
  9592. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9593. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9594. (gunType[3] != GUN_TYPE_UNKNOWN))
  9595. {
  9596. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9597. }
  9598. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9599. {
  9600. // DS DM DW
  9601. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9602. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9603. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9604. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9605. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9606. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9607. }
  9608. else
  9609. {
  9610. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9611. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9612. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9613. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9614. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9615. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9616. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9617. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9618. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9619. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9620. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9621. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9622. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9623. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9624. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9625. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9626. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9627. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9628. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9629. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9630. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9631. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9632. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9633. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9634. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9635. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9636. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9637. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9638. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9639. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9640. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9641. }
  9642. }
  9643. // 4G model
  9644. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9645. {
  9646. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9647. }
  9648. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9649. json_object_put(FirmwareDataTransfer);
  9650. }
  9651. int handleDataTransferRequest(char *uuid, char *payload)
  9652. {
  9653. mtrace();
  9654. json_object *response = json_object_new_object();
  9655. int result = FAIL;
  9656. char tempvendorId[255]={0};
  9657. char tempmessageId[50]={0};
  9658. char tempdata[10240]={0};
  9659. char message[20480]={0};
  9660. DEBUG_INFO("handleDataTransferRequest...\n");
  9661. if((uuid != NULL) && (payload != NULL))
  9662. {
  9663. json_object *DataTransfer;
  9664. DataTransfer = json_tokener_parse(payload);
  9665. if(!is_error(DataTransfer))
  9666. {
  9667. // Required data
  9668. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9669. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9670. // Optional data
  9671. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9672. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9673. if(json_object_object_get(DataTransfer, "data") != NULL)
  9674. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9675. result = PASS;
  9676. }
  9677. json_object_put(DataTransfer);
  9678. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9679. {
  9680. // Send all moudle firmware version on EVSE
  9681. createFirmwareVersionByDataTransfer();
  9682. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9683. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9684. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9685. json_object_put(response);
  9686. }
  9687. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9688. {
  9689. system("/usr/bin/run_tmate_restart.sh &");
  9690. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9691. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9692. json_object_put(response);
  9693. }
  9694. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9695. {
  9696. json_object *data;
  9697. data = json_tokener_parse(tempdata);
  9698. if(!is_error(data))
  9699. {
  9700. 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))
  9701. {
  9702. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9703. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9704. if(json_object_object_get(data, "SOC") != NULL)
  9705. {
  9706. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9707. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9708. }
  9709. if(json_object_object_get(data, "Energy") != NULL)
  9710. {
  9711. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9712. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9713. }
  9714. if(json_object_object_get(data, "Duration") != NULL)
  9715. {
  9716. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9717. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9718. }
  9719. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9720. }
  9721. else
  9722. {
  9723. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9724. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9725. }
  9726. }
  9727. else
  9728. {
  9729. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9730. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9731. }
  9732. json_object_put(data);
  9733. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9734. json_object_put(response);
  9735. }
  9736. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9737. {
  9738. json_object *data;
  9739. data = json_tokener_parse(tempdata);
  9740. if(!is_error(data))
  9741. {
  9742. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9743. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9744. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9745. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9746. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9747. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9748. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9749. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9750. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9751. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9752. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9753. }
  9754. else
  9755. {
  9756. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9757. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9758. }
  9759. json_object_put(data);
  9760. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9761. json_object_put(response);
  9762. }
  9763. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9764. {
  9765. json_object *data;
  9766. data = json_tokener_parse(tempdata);
  9767. if(!is_error(data))
  9768. {
  9769. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9770. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9771. if(json_object_object_get(data, "idToken") != NULL)
  9772. {
  9773. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9774. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9775. }
  9776. else
  9777. {
  9778. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9779. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9780. }
  9781. if(json_object_object_get(data, "price") != NULL) //v1.0
  9782. {
  9783. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9784. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9785. }
  9786. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9787. {
  9788. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9789. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9790. }
  9791. else
  9792. {
  9793. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9794. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9795. }
  9796. }
  9797. else
  9798. {
  9799. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9800. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9801. }
  9802. json_object_put(data);
  9803. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9804. json_object_put(response);
  9805. }
  9806. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9807. {
  9808. json_object *data;
  9809. data = json_tokener_parse(tempdata);
  9810. if(!is_error(data))
  9811. {
  9812. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9813. if(json_object_object_get(data, "txId") != NULL)
  9814. {
  9815. // California pricing V1.0
  9816. DEBUG_INFO("California pricing V1.0\n");
  9817. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9818. sprintf((char*)dmsVersion, "1.0");
  9819. for(int idx = 0;idx<gunTotalNumber;idx++)
  9820. {
  9821. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9822. {
  9823. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9824. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9825. if(json_object_object_get(data, "description") != NULL)
  9826. {
  9827. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9828. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9829. }
  9830. else
  9831. {
  9832. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9833. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9834. }
  9835. }
  9836. }
  9837. }
  9838. else if(json_object_object_get(data, "transactionId") != NULL)
  9839. {
  9840. // California pricing V2.0
  9841. DEBUG_INFO("California pricing V2.0\n");
  9842. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9843. sprintf((char*)dmsVersion, "2.0");
  9844. for(int idx=0;idx<gunTotalNumber;idx++)
  9845. {
  9846. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9847. {
  9848. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9849. if(json_object_object_get(data, "timestamp") != NULL)
  9850. {
  9851. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9852. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9853. }
  9854. else
  9855. {
  9856. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9857. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9858. }
  9859. if(json_object_object_get(data, "meterValue") != NULL)
  9860. {
  9861. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9862. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9863. }
  9864. else
  9865. {
  9866. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9867. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9868. }
  9869. if(json_object_object_get(data, "cost") != NULL)
  9870. {
  9871. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9872. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9873. }
  9874. else
  9875. {
  9876. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9877. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9878. }
  9879. if(json_object_object_get(data, "state") != NULL)
  9880. {
  9881. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9882. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9883. }
  9884. else
  9885. {
  9886. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9887. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9888. }
  9889. if(json_object_object_get(data, "chargingPrice") != NULL)
  9890. {
  9891. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9892. {
  9893. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9894. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9895. }
  9896. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9897. {
  9898. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9899. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9900. }
  9901. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9902. {
  9903. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9904. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9905. }
  9906. }
  9907. else
  9908. {
  9909. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9910. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9911. }
  9912. if(json_object_object_get(data, "idlePrice") != NULL)
  9913. {
  9914. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9915. {
  9916. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9917. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9918. }
  9919. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9920. {
  9921. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9922. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9923. }
  9924. }
  9925. if(json_object_object_get(data, "nextPeriod") != NULL)
  9926. {
  9927. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9928. {
  9929. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9930. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9931. }
  9932. else
  9933. {
  9934. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9935. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9936. }
  9937. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9938. {
  9939. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9940. {
  9941. 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")));
  9942. 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"));
  9943. }
  9944. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9945. {
  9946. 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")));
  9947. 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"));
  9948. }
  9949. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9950. {
  9951. 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")));
  9952. 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"));
  9953. }
  9954. }
  9955. else
  9956. {
  9957. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9958. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9959. }
  9960. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9961. {
  9962. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9963. {
  9964. 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")));
  9965. 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"));
  9966. }
  9967. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9968. {
  9969. 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")));
  9970. 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"));
  9971. }
  9972. }
  9973. }
  9974. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9975. {
  9976. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9977. {
  9978. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9979. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9980. }
  9981. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9982. {
  9983. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9984. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9985. }
  9986. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9987. {
  9988. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9989. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9990. }
  9991. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9992. {
  9993. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9994. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9995. }
  9996. }
  9997. }
  9998. }
  9999. }
  10000. else
  10001. {
  10002. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10003. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10004. }
  10005. }
  10006. else
  10007. {
  10008. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10009. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10010. }
  10011. json_object_put(data);
  10012. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10013. json_object_put(response);
  10014. }
  10015. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10016. {
  10017. json_object *data;
  10018. data = json_tokener_parse(tempdata);
  10019. if(!is_error(data))
  10020. {
  10021. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10022. if(json_object_object_get(data, "txId") != NULL)
  10023. {
  10024. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10025. for(int idx = 0;idx<gunTotalNumber;idx++)
  10026. {
  10027. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10028. {
  10029. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10030. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10031. if(json_object_object_get(data, "description") != NULL)
  10032. {
  10033. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10034. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10035. }
  10036. else
  10037. {
  10038. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10039. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10040. }
  10041. }
  10042. }
  10043. }
  10044. else if(json_object_object_get(data, "transactionId") != NULL)
  10045. {
  10046. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10047. for(int idx = 0;idx<gunTotalNumber;idx++)
  10048. {
  10049. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10050. {
  10051. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10052. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10053. if(json_object_object_get(data, "cost") != NULL)
  10054. {
  10055. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10056. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10057. }
  10058. else
  10059. {
  10060. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10061. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10062. }
  10063. if(json_object_object_get(data, "priceText") != NULL)
  10064. {
  10065. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10066. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10067. }
  10068. else
  10069. {
  10070. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10071. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10072. }
  10073. if(json_object_object_get(data, "qrCodeText") != NULL)
  10074. {
  10075. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10076. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10077. }
  10078. }
  10079. }
  10080. }
  10081. else
  10082. {
  10083. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10084. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10085. }
  10086. }
  10087. else
  10088. {
  10089. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10090. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10091. }
  10092. json_object_put(data);
  10093. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10094. json_object_put(response);
  10095. }
  10096. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10097. {
  10098. json_object *data;
  10099. data = json_tokener_parse(tempdata);
  10100. if(!is_error(data))
  10101. {
  10102. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10103. if(json_object_object_get(data, "Content_Type") != NULL)
  10104. {
  10105. 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))
  10106. {
  10107. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10108. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10109. {
  10110. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10111. }
  10112. }
  10113. else
  10114. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10115. }
  10116. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10117. }
  10118. else
  10119. {
  10120. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10121. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10122. }
  10123. json_object_put(data);
  10124. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10125. json_object_put(response);
  10126. }
  10127. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10128. {
  10129. json_object *data;
  10130. data = json_tokener_parse(tempdata);
  10131. if(!is_error(data))
  10132. {
  10133. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10134. if(json_object_object_get(data, "ConnectorId") != NULL)
  10135. {
  10136. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10137. }
  10138. if(json_object_object_get(data, "SerialNo") != NULL)
  10139. {
  10140. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10141. }
  10142. if(json_object_object_get(data, "Page_Index") != NULL)
  10143. {
  10144. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10145. }
  10146. if(json_object_object_get(data, "Duration") != NULL)
  10147. {
  10148. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10149. }
  10150. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10151. }
  10152. else
  10153. {
  10154. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10155. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10156. }
  10157. json_object_put(data);
  10158. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10159. json_object_put(response);
  10160. }
  10161. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10162. {
  10163. json_object *data;
  10164. data = json_tokener_parse(tempdata);
  10165. if(!is_error(data))
  10166. {
  10167. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10168. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10169. {
  10170. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10171. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10172. else
  10173. {
  10174. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10175. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10176. }
  10177. }
  10178. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10179. {
  10180. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10181. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10182. else
  10183. {
  10184. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10185. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10186. }
  10187. }
  10188. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10189. {
  10190. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10191. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10192. else
  10193. {
  10194. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10195. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10196. }
  10197. }
  10198. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10199. {
  10200. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10201. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10202. else
  10203. {
  10204. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10205. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10206. }
  10207. }
  10208. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10209. {
  10210. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10211. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10212. else
  10213. {
  10214. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10215. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10216. }
  10217. }
  10218. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10219. {
  10220. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10221. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10222. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10223. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10224. else
  10225. {
  10226. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10227. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10228. }
  10229. }
  10230. if(json_object_object_get(data, "isAuthentication") != NULL)
  10231. {
  10232. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10233. {
  10234. case 0:
  10235. case 1:
  10236. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10237. break;
  10238. default:
  10239. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10240. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10241. break;
  10242. }
  10243. }
  10244. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10245. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10246. }
  10247. else
  10248. {
  10249. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10250. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10251. }
  10252. json_object_put(data);
  10253. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10254. json_object_put(response);
  10255. }
  10256. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10257. {
  10258. json_object *data;
  10259. data = json_tokener_parse(tempdata);
  10260. if(!is_error(data))
  10261. {
  10262. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10263. {
  10264. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10265. {
  10266. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10267. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10268. }
  10269. else
  10270. {
  10271. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10272. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10273. }
  10274. }
  10275. else
  10276. {
  10277. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10278. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10279. }
  10280. }
  10281. else
  10282. {
  10283. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10284. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10285. }
  10286. json_object_put(data);
  10287. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10288. json_object_put(response);
  10289. }
  10290. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10291. {
  10292. json_object *data;
  10293. data = json_tokener_parse(tempdata);
  10294. if(!is_error(data))
  10295. {
  10296. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10297. if(json_object_object_get(data, "stationName") != NULL)
  10298. {
  10299. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10300. }
  10301. else
  10302. {
  10303. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10304. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10305. }
  10306. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10307. {
  10308. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10309. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10310. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10311. }
  10312. }
  10313. else
  10314. {
  10315. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10316. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10317. }
  10318. json_object_put(data);
  10319. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10320. json_object_put(response);
  10321. }
  10322. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10323. {
  10324. json_object *data;
  10325. data = json_tokener_parse(tempdata);
  10326. if(!is_error(data))
  10327. {
  10328. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10329. if(json_object_object_get(data, "weatherId") != NULL)
  10330. {
  10331. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10332. }
  10333. else
  10334. {
  10335. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10336. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10337. }
  10338. if(json_object_object_get(data, "Temperature") != NULL)
  10339. {
  10340. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10341. }
  10342. else
  10343. {
  10344. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10345. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10346. }
  10347. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10348. {
  10349. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10350. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10351. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10352. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10353. );
  10354. }
  10355. }
  10356. else
  10357. {
  10358. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10359. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10360. }
  10361. json_object_put(data);
  10362. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10363. json_object_put(response);
  10364. }
  10365. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10366. {
  10367. json_object *data;
  10368. data = json_tokener_parse(tempdata);
  10369. if(!is_error(data))
  10370. {
  10371. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10372. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10373. {
  10374. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10375. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10376. }
  10377. else
  10378. {
  10379. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10380. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10381. }
  10382. }
  10383. else
  10384. {
  10385. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10386. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10387. }
  10388. json_object_put(data);
  10389. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10390. json_object_put(response);
  10391. }
  10392. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10393. {
  10394. json_object *data;
  10395. data = json_tokener_parse(tempdata);
  10396. if(!is_error(data))
  10397. {
  10398. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10399. {
  10400. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10401. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10402. if(gun_index < gunTotalNumber)
  10403. {
  10404. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10405. {
  10406. json_object *responsedata = json_object_new_object();
  10407. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10408. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10409. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10410. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10411. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10412. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10413. }
  10414. else
  10415. {
  10416. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10417. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10418. }
  10419. }
  10420. else
  10421. {
  10422. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10423. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10424. }
  10425. }
  10426. else
  10427. {
  10428. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10429. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10430. }
  10431. }
  10432. else
  10433. {
  10434. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10435. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10436. }
  10437. json_object_put(data);
  10438. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10439. json_object_put(response);
  10440. }
  10441. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10442. {
  10443. json_object *data;
  10444. data = json_tokener_parse(tempdata);
  10445. if(!is_error(data))
  10446. {
  10447. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10448. int gun_index = 0;
  10449. if(json_object_object_get(data, "ConnectorId") != NULL)
  10450. {
  10451. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10452. if(json_object_object_get(data, "occupancySN") != NULL)
  10453. {
  10454. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10455. }
  10456. else
  10457. {
  10458. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10459. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10460. }
  10461. if(json_object_object_get(data, "actionId") != NULL)
  10462. {
  10463. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10464. }
  10465. else
  10466. {
  10467. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10468. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10469. }
  10470. }
  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("ConnectorId data can not get."));
  10475. }
  10476. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10477. {
  10478. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10479. }
  10480. }
  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("OccupancyFeeDisplay content got something wrong."));
  10485. }
  10486. json_object_put(data);
  10487. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10488. json_object_put(response);
  10489. }
  10490. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10491. {
  10492. json_object *data;
  10493. data = json_tokener_parse(tempdata);
  10494. if(!is_error(data))
  10495. {
  10496. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10497. if(json_object_object_get(data, "price") != NULL)
  10498. {
  10499. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10500. }
  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("price data can not get."));
  10505. }
  10506. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10507. {
  10508. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10509. }
  10510. }
  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("SetOccupancyPrice content got something wrong."));
  10515. }
  10516. json_object_put(data);
  10517. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10518. json_object_put(response);
  10519. }
  10520. // Support ISO-15118 related message
  10521. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10522. {
  10523. char cmdBuf[1024]={0};
  10524. 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);
  10525. system(cmdBuf);
  10526. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10527. json_object *responsedata = json_object_new_object();
  10528. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10529. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10530. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10531. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10532. json_object_put(response);
  10533. }
  10534. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10535. {
  10536. json_object *data;
  10537. data = json_tokener_parse(tempdata);
  10538. if(!is_error(data))
  10539. {
  10540. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10541. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10542. fclose(fp);
  10543. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10544. json_object *responsedata = json_object_new_object();
  10545. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10546. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10547. else
  10548. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10549. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10550. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10551. }
  10552. else
  10553. {
  10554. json_object *responsedata = json_object_new_object();
  10555. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10556. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10557. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10558. }
  10559. json_object_put(data);
  10560. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10561. json_object_put(response);
  10562. }
  10563. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10564. {
  10565. json_object *data;
  10566. data = json_tokener_parse(tempdata);
  10567. DEBUG_INFO("DeleteCertificate processing...\n");
  10568. if(!is_error(data))
  10569. {
  10570. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10571. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10572. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10573. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10574. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10575. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10576. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10577. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10578. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10579. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10580. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10581. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10582. char temp[256] = {0};
  10583. char compareData[256] = {0};
  10584. int isMatch = TRUE;
  10585. // Check certV2G
  10586. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10587. {
  10588. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10589. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10590. isMatch = FALSE;
  10591. if(isMatch == TRUE)
  10592. {
  10593. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10594. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10595. isMatch = FALSE;
  10596. }
  10597. if(isMatch == TRUE)
  10598. {
  10599. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10600. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10601. isMatch = FALSE;
  10602. }
  10603. if(isMatch == TRUE)
  10604. {
  10605. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10606. system(temp);
  10607. json_object *responsedata = json_object_new_object();
  10608. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10609. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10610. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10611. }
  10612. else
  10613. {
  10614. json_object *responsedata = json_object_new_object();
  10615. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10616. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10617. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10618. }
  10619. }
  10620. else
  10621. {
  10622. json_object *responsedata = json_object_new_object();
  10623. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10624. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10625. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10626. }
  10627. }
  10628. else
  10629. {
  10630. json_object *responsedata = json_object_new_object();
  10631. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10632. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10633. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10634. }
  10635. json_object_put(data);
  10636. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10637. json_object_put(response);
  10638. }
  10639. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10640. {
  10641. json_object *data;
  10642. data = json_tokener_parse(tempdata);
  10643. if(!is_error(data))
  10644. {
  10645. /*
  10646. * TODO:
  10647. * 1. Query certificate to response
  10648. */
  10649. json_object *responsedata = json_object_new_object();
  10650. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10651. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10652. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10653. }
  10654. else
  10655. {
  10656. json_object *responsedata = json_object_new_object();
  10657. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10658. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10659. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10660. }
  10661. json_object_put(data);
  10662. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10663. json_object_put(response);
  10664. }
  10665. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10666. {
  10667. json_object *data;
  10668. data = json_tokener_parse(tempdata);
  10669. if(!is_error(data))
  10670. {
  10671. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10672. if(json_object_object_get(data, "certificateType") != NULL)
  10673. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10674. if(json_object_object_get(data, "certificate") != NULL)
  10675. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10676. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10677. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10678. char temp[1024];
  10679. FILE *fp = fopen(tempCert, "w");
  10680. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10681. fclose(fp);
  10682. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10683. char strExpDate[30];
  10684. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10685. fp = popen(temp, "r");
  10686. if(fp)
  10687. {
  10688. while(fgets(temp, sizeof(temp), fp) != NULL)
  10689. {
  10690. if(strstr(temp, "notAfter=") != NULL)
  10691. {
  10692. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10693. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10694. break;
  10695. }
  10696. }
  10697. }
  10698. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10699. struct tm tmExpDate;
  10700. struct timeb tbExpDate;
  10701. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10702. tbExpDate.time = mktime(&tmExpDate);
  10703. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10704. {
  10705. DEBUG_INFO("The enddate is already expired...\n");
  10706. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10707. }
  10708. else
  10709. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10710. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10711. {
  10712. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10713. {
  10714. if(access(ROOTCA_V2G,F_OK) != -1)
  10715. {
  10716. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10717. rename(ROOTCA_V2G, "/Storage/OCPP/rootCaV2g_fallback.pem");
  10718. rename(tempCert, ROOTCA_V2G);
  10719. }
  10720. else
  10721. {
  10722. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10723. rename(tempCert, ROOTCA_V2G);
  10724. }
  10725. json_object *responsedata = json_object_new_object();
  10726. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10727. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10728. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10729. }
  10730. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10731. {
  10732. if(access(ROOTCA_MO,F_OK) != -1)
  10733. {
  10734. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10735. rename(ROOTCA_MO, "/Storage/OCPP/rootCaMo_fallback.pem");
  10736. rename(tempCert, ROOTCA_MO);
  10737. }
  10738. else
  10739. {
  10740. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10741. rename(tempCert, ROOTCA_MO);
  10742. }
  10743. json_object *responsedata = json_object_new_object();
  10744. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10745. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10746. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10747. }
  10748. else
  10749. {
  10750. json_object *responsedata = json_object_new_object();
  10751. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10752. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10753. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10754. }
  10755. }
  10756. else
  10757. {
  10758. json_object *responsedata = json_object_new_object();
  10759. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10760. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10761. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10762. }
  10763. }
  10764. else
  10765. {
  10766. json_object *responsedata = json_object_new_object();
  10767. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10768. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10769. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10770. }
  10771. json_object_put(data);
  10772. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10773. json_object_put(response);
  10774. }
  10775. else
  10776. {
  10777. // Can not find valid message id
  10778. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10779. }
  10780. }
  10781. else
  10782. {
  10783. // Payload is null
  10784. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10785. }
  10786. LWS_Send(message);
  10787. return result;
  10788. }
  10789. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10790. {
  10791. mtrace();
  10792. int result = FAIL;
  10793. int connectorIdInt, durationInt;
  10794. char chargingRateUnitStr[4]={0};
  10795. char comfirmstr[20];
  10796. int confirmPeriods = 0;
  10797. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10798. json_object *GetCompositeSchedule;
  10799. GetCompositeSchedule = json_tokener_parse(payload);
  10800. if(!is_error(GetCompositeSchedule))
  10801. {
  10802. // Required data
  10803. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10804. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10805. else
  10806. connectorIdInt = -1;
  10807. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10808. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10809. else
  10810. durationInt = 86400;
  10811. // Optional data
  10812. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10813. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10814. }
  10815. json_object_put(GetCompositeSchedule);
  10816. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10817. if((connectorIdInt == 0) ||
  10818. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10819. {
  10820. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10821. struct StructChargingProfile tmpProfile[1];
  10822. if(strstr(chargingRateUnitStr, "W") != NULL)
  10823. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10824. else
  10825. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10826. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10827. {
  10828. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10829. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10830. }
  10831. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10832. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10833. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10834. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10835. {
  10836. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10837. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10838. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10839. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10840. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10841. {
  10842. confirmPeriods = idx;
  10843. break;
  10844. }
  10845. }
  10846. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10847. {
  10848. confirmPeriods += 1;
  10849. }
  10850. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10851. }
  10852. else
  10853. {
  10854. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10855. }
  10856. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10857. return result;
  10858. }
  10859. int handleGetConfigurationRequest(char *uuid, char *payload)
  10860. {
  10861. mtrace();
  10862. int result = FAIL;
  10863. int MaxKeySupported = 0;
  10864. int n_keys = 0;
  10865. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10866. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10867. json_object *GetConfiguration;
  10868. GetConfiguration = json_tokener_parse(payload);
  10869. if(!is_error(GetConfiguration))
  10870. {
  10871. // Optional data
  10872. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10873. {
  10874. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10875. {
  10876. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10877. n_keys = idx + 1;
  10878. }
  10879. }
  10880. }
  10881. json_object_put(GetConfiguration);
  10882. UnknownKeynum = 0;
  10883. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10884. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10885. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10886. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10887. if(n_keys != 0)
  10888. {
  10889. for(int i=0;i<n_keys;i++)
  10890. {
  10891. getKeyValue(requestKey[i]);
  10892. }
  10893. }
  10894. else
  10895. {
  10896. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10897. getKeyValue("");
  10898. }
  10899. processUnkownKey();
  10900. sendGetConfigurationConfirmation(uuid);
  10901. return result;
  10902. }
  10903. static char fnamePlusPath[100]={0};
  10904. static char fnamePWithNoPath[60]={0};
  10905. void checkUploadLog(void)
  10906. {
  10907. FILE *fp;
  10908. /* Open the command for reading. */
  10909. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10910. if (fp == NULL) {
  10911. DEBUG_WARN("Failed to run command\n" );
  10912. exit(1);
  10913. }
  10914. int ftppathlen = 0;
  10915. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10916. int i = 0;
  10917. /* Read the output a line at a time - output it. */
  10918. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10919. if(i==0)
  10920. {
  10921. ftppathlen = strlen(fnamePlusPath);
  10922. DEBUG_INFO("%s\n", fnamePlusPath);
  10923. fnamePlusPath[ftppathlen]='\0';
  10924. break;
  10925. }
  10926. i= i+1;
  10927. }
  10928. /* close */
  10929. pclose(fp);
  10930. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10931. {
  10932. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10933. {
  10934. fnamePlusPath[k]='\0';
  10935. }
  10936. }
  10937. i=1;
  10938. //char fname[60]={0};
  10939. while(i < ftppathlen)
  10940. {
  10941. int len=ftppathlen-i;
  10942. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10943. {
  10944. DEBUG_INFO("compare '/' all right\n");
  10945. break;
  10946. }
  10947. i=i+1;
  10948. }
  10949. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10950. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10951. fnamePWithNoPath[i+1] = '\0';
  10952. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10953. {
  10954. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10955. {
  10956. fnamePWithNoPath[j]='\0';
  10957. }
  10958. }
  10959. FILE* fp1 = fopen(fnamePlusPath, "r");
  10960. if (fp1)
  10961. {
  10962. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10963. // file exists
  10964. fclose(fp1);
  10965. }
  10966. else
  10967. {
  10968. // file doesn't exist
  10969. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10970. }
  10971. }
  10972. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10973. {
  10974. mtrace();
  10975. int result = FAIL;
  10976. time_t CurrentTime;
  10977. struct tm *tm;
  10978. pthread_t th_Status;
  10979. CurrentTime = time(NULL);
  10980. tm = localtime(&CurrentTime);
  10981. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10982. 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);
  10983. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10984. if(!interLock.isGetDiagnosticGoing)
  10985. {
  10986. interLock.isGetDiagnosticGoing = 1;
  10987. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  10988. sleep(1);
  10989. }
  10990. else
  10991. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10992. return result;
  10993. }
  10994. void* GetDiagnosticsProcess(void* data)
  10995. {
  10996. pthread_detach(pthread_self());
  10997. mtrace();
  10998. int retriesInt=0, retryIntervalInt=0;
  10999. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11000. 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};
  11001. int port=0;
  11002. int isSuccess = FALSE;
  11003. char cmdBuf[2048];
  11004. struct tm *tmNow;
  11005. time_t CurrentTime;
  11006. struct tm tmStart;
  11007. struct tm tmStop;
  11008. CurrentTime = time(NULL);
  11009. tmNow=localtime(&CurrentTime);
  11010. uint16_t targetYear, targetMonth;
  11011. json_object *GetDiagnostics;
  11012. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11013. GetDiagnostics = json_tokener_parse(data);
  11014. if(!is_error(GetDiagnostics))
  11015. {
  11016. // Required data
  11017. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11018. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11019. // Optional data
  11020. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11021. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11022. else
  11023. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11024. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11025. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11026. else
  11027. retryIntervalInt = 30;
  11028. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11029. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11030. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11031. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11032. }
  11033. json_object_put(GetDiagnostics);
  11034. // Pack log to compress file
  11035. 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) &&
  11036. (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))
  11037. {
  11038. // Pack system log
  11039. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11040. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11041. targetYear = tmStart.tm_year;
  11042. targetMonth = tmStart.tm_mon;
  11043. do
  11044. {
  11045. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11046. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11047. if(targetMonth+1>=13)
  11048. {
  11049. targetYear += 1;
  11050. targetMonth = 1;
  11051. }
  11052. else
  11053. {
  11054. targetMonth += 1;
  11055. }
  11056. }while((targetYear < (tmNow->tm_year+1900)) ||
  11057. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11058. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11059. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11060. system(cmdBuf);
  11061. // Pack charging & event log
  11062. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11063. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11064. targetYear = tmStart.tm_year;
  11065. targetMonth = tmStart.tm_mon;
  11066. do
  11067. {
  11068. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11069. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  11070. if(targetMonth+1>=13)
  11071. {
  11072. targetYear += 1;
  11073. targetMonth = 1;
  11074. }
  11075. else
  11076. {
  11077. targetMonth += 1;
  11078. }
  11079. }while((targetYear < (tmNow->tm_year+1900)) ||
  11080. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11081. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11082. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11083. system(cmdBuf);
  11084. // Combine log file
  11085. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11086. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11087. }
  11088. else
  11089. {
  11090. system("exec /root/logPackTools 'log' 6");
  11091. }
  11092. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11093. system(cmdBuf);
  11094. checkUploadLog();
  11095. //****************location*******************/
  11096. if(strcmp(locationstr,"")==0)
  11097. {
  11098. DEBUG_INFO("location is <Empty>!\n");
  11099. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11100. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11101. goto end;
  11102. }
  11103. memset(protocol, 0, ARRAY_SIZE(protocol));
  11104. memset(user, 0, ARRAY_SIZE(user) );
  11105. memset(password, 0, ARRAY_SIZE(password));
  11106. memset(host, 0, ARRAY_SIZE(host));
  11107. memset(path, 0, ARRAY_SIZE(path));
  11108. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11109. memset(host1, 0, ARRAY_SIZE(host1));
  11110. memset(path1, 0, ARRAY_SIZE(path1));
  11111. /*location: ftp://user:password@host:port/path*/
  11112. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11113. if((access(fnamePlusPath,F_OK))!=-1)
  11114. {
  11115. DEBUG_INFO("fnamePlusPath exist.\n");
  11116. }
  11117. else
  11118. {
  11119. DEBUG_INFO("fnamePlusPath not exist!\n");
  11120. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11121. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11122. goto end;
  11123. }
  11124. if(strchr(locationstr,'@')==NULL)
  11125. {
  11126. sscanf(locationstr,
  11127. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11128. protocol, host, &port, path);
  11129. strcpy(user,"anonymous");
  11130. strcpy(password,"");
  11131. }
  11132. else
  11133. {
  11134. //DEBUG_INFO("pch=%s\n", pch);
  11135. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11136. protocol, user, password, host, &port, path);
  11137. }
  11138. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11139. {
  11140. DEBUG_INFO("protocol is not ftp/http ! \n");
  11141. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11142. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11143. goto end;
  11144. }
  11145. if(strncmp(locationstr,"http", 4) == 0)
  11146. {
  11147. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11148. sprintf(ftppath,"/%s", path);
  11149. do
  11150. {
  11151. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11152. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11153. sleep(3);
  11154. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11155. if(!isSuccess)
  11156. {
  11157. DEBUG_INFO("Diagnostics fail.\n");
  11158. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11159. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11160. sleep(retryIntervalInt);
  11161. }
  11162. else
  11163. {
  11164. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11165. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11166. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11167. }
  11168. retriesInt--;
  11169. }while((isSuccess == 0)&&(retriesInt >= 0));
  11170. }
  11171. else
  11172. {
  11173. sscanf(host,"%[^/]%s",host1, path1);
  11174. if(strlen(path) > 0)
  11175. sprintf(ftppath,"/%s", path);
  11176. else
  11177. sprintf(ftppath,"/%s", path1);
  11178. int ftppathlen=strlen(ftppath);
  11179. int i=1;
  11180. char filenametemp[50];
  11181. while(i < ftppathlen)
  11182. {
  11183. int len=ftppathlen-i;
  11184. if(ftppath[len]== 47) // '/' ascll code: 47
  11185. {
  11186. DEBUG_INFO("find '/' all right\n");
  11187. break;
  11188. }
  11189. i=i+1;
  11190. }
  11191. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11192. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11193. filenametemp[i+1] = 0;
  11194. if(port == 0)
  11195. port = 21;
  11196. do
  11197. {
  11198. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11199. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11200. sleep(3);
  11201. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11202. if(!isSuccess)
  11203. {
  11204. DEBUG_INFO("Diagnostics fail.\n");
  11205. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11206. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11207. sleep(retryIntervalInt);
  11208. }
  11209. else
  11210. {
  11211. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11212. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11213. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11214. }
  11215. retriesInt--;
  11216. }while((!isSuccess)&&(retriesInt >= 0));
  11217. }
  11218. end:
  11219. system("rm -f /mnt/*");
  11220. sleep(5);
  11221. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11222. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11223. interLock.isGetDiagnosticGoing = 0;
  11224. pthread_exit(NULL);
  11225. }
  11226. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11227. {
  11228. mtrace();
  11229. int result = FAIL;
  11230. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11231. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11232. {
  11233. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11234. locallistVersion = -1;
  11235. }
  11236. else
  11237. {
  11238. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11239. locallistVersion = 0;
  11240. OCPP_getListVerion();
  11241. }
  11242. //from db.OCPP_getListVerion
  11243. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11244. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11245. sendGetLocalListVersionConfirmation(uuid,"");
  11246. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11247. return result;
  11248. }
  11249. int handleRemoteStartRequest(char *uuid, char *payload)
  11250. {
  11251. mtrace();
  11252. int result = PASS;
  11253. int connectorIdInt=-1;
  11254. int tempIndex = 0;
  11255. char comfirmstr[20]={0};
  11256. char cmdBuf[512];
  11257. json_object *RemoteStartTransaction;
  11258. FILE *fp;
  11259. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11260. if(server_pending == TRUE)
  11261. {
  11262. result = FAIL;
  11263. }
  11264. RemoteStartTransaction = json_tokener_parse(payload);
  11265. if(!is_error(RemoteStartTransaction))
  11266. {
  11267. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11268. {
  11269. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11270. }
  11271. else
  11272. {
  11273. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11274. {
  11275. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11276. {
  11277. connectorIdInt = (gun_index+1);
  11278. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11279. break;
  11280. }
  11281. }
  11282. }
  11283. if(connectorIdInt == 0)
  11284. {
  11285. DEBUG_WARN("Connector id shall not equal 0.\n");
  11286. result = FAIL;
  11287. }
  11288. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11289. {
  11290. DEBUG_WARN("idTag should not be NULL.\n");
  11291. result = FAIL;
  11292. }
  11293. else if(connectorIdInt == -1)
  11294. {
  11295. DEBUG_INFO("Connector id does not specific.\n");
  11296. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11297. {
  11298. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11299. // Required data
  11300. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11301. // Optional data
  11302. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11303. {
  11304. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11305. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11306. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11307. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11308. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11309. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11310. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11311. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11312. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11313. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11314. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11315. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11316. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11317. {
  11318. 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")));
  11319. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11320. 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"));
  11321. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11322. 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"));
  11323. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11324. 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")));
  11325. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11326. {
  11327. 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++)
  11328. {
  11329. 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"));
  11330. 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"));
  11331. 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)
  11332. 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"));
  11333. }
  11334. }
  11335. }
  11336. }
  11337. else
  11338. {
  11339. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11340. }
  11341. }
  11342. }
  11343. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11344. {
  11345. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11346. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11347. // Required data
  11348. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11349. // Optional data
  11350. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11351. {
  11352. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11353. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11354. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11355. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11356. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11357. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11358. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11359. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11360. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11361. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11362. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11363. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11364. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11365. {
  11366. 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")));
  11367. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11368. 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"));
  11369. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11370. 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"));
  11371. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11372. 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")));
  11373. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11374. {
  11375. 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++)
  11376. {
  11377. 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"));
  11378. 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"));
  11379. 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)
  11380. 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"));
  11381. }
  11382. }
  11383. }
  11384. }
  11385. else
  11386. {
  11387. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11388. }
  11389. }
  11390. else
  11391. {
  11392. DEBUG_WARN("Connector id is over maximun value.\n");
  11393. result = FAIL;
  11394. }
  11395. }
  11396. if(result == PASS)
  11397. {
  11398. if(connectorIdInt > 0)
  11399. {
  11400. //check Transaction active
  11401. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11402. {
  11403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11404. {
  11405. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11406. }
  11407. else
  11408. {
  11409. tempIndex = connectorIdInt -1;
  11410. }
  11411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11412. {
  11413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11414. {
  11415. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11416. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11417. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11418. {
  11419. //Reserved
  11420. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11421. }
  11422. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11423. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11424. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11425. {
  11426. //Reserved
  11427. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11428. {
  11429. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11430. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11431. goto end;
  11432. }
  11433. }
  11434. else
  11435. {
  11436. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11437. {
  11438. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11439. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11440. goto end;
  11441. }
  11442. }//END FOR ELSE
  11443. }
  11444. }// END FOR CHAdeMO_QUANTITY
  11445. }
  11446. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11447. {
  11448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11449. {
  11450. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11451. }
  11452. else
  11453. {
  11454. tempIndex = connectorIdInt -1;
  11455. }
  11456. for (int index = 0; index < CCS_QUANTITY; index++)
  11457. {
  11458. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11459. {
  11460. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11461. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11462. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11463. {
  11464. //Reserved
  11465. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11466. }
  11467. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11468. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11469. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11470. {
  11471. //Reserved
  11472. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11473. {
  11474. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11475. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11476. goto end;
  11477. }
  11478. }
  11479. else
  11480. {
  11481. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11482. {
  11483. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11485. goto end;
  11486. }
  11487. }// END FOR ELSE
  11488. }
  11489. }// END FOR CCS_QUANTITY
  11490. }
  11491. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11492. {
  11493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11494. {
  11495. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11496. }
  11497. else
  11498. {
  11499. tempIndex = connectorIdInt -1;
  11500. }
  11501. for (int index = 0; index < GB_QUANTITY; index++)
  11502. {
  11503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11504. {
  11505. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11506. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11507. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11508. {
  11509. //Reserved
  11510. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11511. }
  11512. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11513. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11514. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11515. {
  11516. //Reserved
  11517. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11518. {
  11519. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11520. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11521. goto end;
  11522. }
  11523. }
  11524. else
  11525. {
  11526. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11527. {
  11528. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11529. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11530. goto end;
  11531. }
  11532. }// END FOR ELSE
  11533. }
  11534. } // END FOR GB_QUANTITY
  11535. }
  11536. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11537. {
  11538. tempIndex = connectorIdInt -1;
  11539. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11540. {
  11541. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11542. {
  11543. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11544. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11545. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11546. {
  11547. //Reserved
  11548. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11549. }
  11550. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11551. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11552. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11553. {
  11554. //Reserved
  11555. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11556. {
  11557. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11558. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11559. goto end;
  11560. }
  11561. }
  11562. else
  11563. {
  11564. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11565. {
  11566. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11567. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11568. goto end;
  11569. }
  11570. }// END FOR ELSE
  11571. }
  11572. } // END FOR GB_QUANTITY
  11573. }
  11574. else
  11575. {
  11576. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11577. {
  11578. tempIndex = 2;
  11579. }
  11580. else
  11581. {
  11582. tempIndex = connectorIdInt -1;
  11583. }
  11584. for (int index = 0; index < AC_QUANTITY; index++)
  11585. {
  11586. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11587. {
  11588. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11589. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11590. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11591. {
  11592. //Reserved
  11593. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11594. }
  11595. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11596. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11597. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11598. {
  11599. //Reserved
  11600. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11601. {
  11602. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11603. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11604. goto end;
  11605. }
  11606. }
  11607. else
  11608. {
  11609. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11610. {
  11611. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11612. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11613. goto end;
  11614. }
  11615. }//END FOR ELSE
  11616. }
  11617. }// END FOR AC_QUANTITY
  11618. }
  11619. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11620. {
  11621. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11622. {
  11623. // Save profile to file
  11624. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11625. system(cmdBuf);
  11626. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11627. fp = fopen(cmdBuf, "w");
  11628. 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));
  11629. fclose(fp);
  11630. }
  11631. else
  11632. {
  11633. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11634. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11635. goto end;
  11636. }
  11637. }
  11638. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11639. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11640. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11641. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11642. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11643. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11644. }
  11645. else
  11646. {
  11647. uint8_t isHasIdleConnector = FALSE;
  11648. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11649. {
  11650. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11651. {
  11652. isHasIdleConnector = TRUE;
  11653. break;
  11654. }
  11655. }
  11656. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11657. {
  11658. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11659. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11660. {
  11661. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11662. {
  11663. // Save profile to file
  11664. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11665. system(cmdBuf);
  11666. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11667. fp = fopen(cmdBuf, "w");
  11668. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11669. fclose(fp);
  11670. refreshStartTimer(&clientTime.RemoteStartWait);
  11671. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11672. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11673. }
  11674. else
  11675. {
  11676. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11677. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11678. }
  11679. }
  11680. else
  11681. {
  11682. refreshStartTimer(&clientTime.RemoteStartWait);
  11683. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11684. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11685. }
  11686. }
  11687. else
  11688. {
  11689. DEBUG_INFO("There is not any connector is idle.\n");
  11690. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11691. }
  11692. }
  11693. }
  11694. else
  11695. {
  11696. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11697. }
  11698. end:
  11699. json_object_put(RemoteStartTransaction);
  11700. sendRemoteStartConfirmation(uuid, comfirmstr);
  11701. return result;
  11702. }
  11703. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11704. {
  11705. mtrace();
  11706. int result = FAIL;
  11707. int match = FALSE;
  11708. int GunNO = 0;
  11709. int tempIndex = 0;
  11710. int transactionIdInt=0;
  11711. int transactionIdIsNULL= TRUE;
  11712. char comfirmstr[20];
  11713. json_object *RemoteStopTransaction;
  11714. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11715. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11716. if(server_pending == TRUE)
  11717. {
  11718. return 0;
  11719. }
  11720. RemoteStopTransaction = json_tokener_parse(payload);
  11721. if(!is_error(RemoteStopTransaction))
  11722. {
  11723. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11724. {
  11725. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11726. transactionIdIsNULL = FALSE;
  11727. }
  11728. }
  11729. json_object_put(RemoteStopTransaction);
  11730. if(transactionIdIsNULL == FALSE)
  11731. {
  11732. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11733. {
  11734. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11735. {
  11736. //check Transaction active
  11737. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11738. {
  11739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11740. {
  11741. tempIndex = ((gun_index==2) ? 1: 0);
  11742. }
  11743. else
  11744. {
  11745. tempIndex = gun_index;
  11746. }
  11747. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11748. {
  11749. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11750. {
  11751. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11752. {
  11753. match = TRUE;
  11754. GunNO = gun_index;
  11755. }
  11756. }
  11757. }// END FOR CHAdeMO_QUANTITY
  11758. }
  11759. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11760. {
  11761. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11762. {
  11763. tempIndex = ((gun_index==2) ? 1: 0);
  11764. }
  11765. else
  11766. {
  11767. tempIndex = gun_index;
  11768. }
  11769. for (int index = 0; index < CCS_QUANTITY; index++)
  11770. {
  11771. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11772. {
  11773. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11774. {
  11775. match = TRUE;
  11776. GunNO = gun_index;
  11777. }
  11778. }
  11779. }// END FOR CCS_QUANTITY
  11780. }
  11781. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11782. {
  11783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11784. {
  11785. tempIndex = ((gun_index==2) ? 1: 0);
  11786. }
  11787. else
  11788. {
  11789. tempIndex = gun_index;
  11790. }
  11791. for (int index = 0; index < GB_QUANTITY; index++)
  11792. {
  11793. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11794. {
  11795. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11796. {
  11797. match = TRUE;
  11798. GunNO = gun_index;
  11799. }
  11800. }
  11801. }// END FOR GB_QUANTITY
  11802. }
  11803. else if(gunType[gun_index] == GUN_TYPE_DO)
  11804. {
  11805. tempIndex = gun_index;
  11806. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11807. {
  11808. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11809. {
  11810. 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
  11811. {
  11812. match = TRUE;
  11813. GunNO = gun_index;
  11814. }
  11815. }
  11816. }// END FOR GB_QUANTITY
  11817. }
  11818. else
  11819. {
  11820. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11821. {
  11822. tempIndex = 2;
  11823. }
  11824. else
  11825. {
  11826. tempIndex = gun_index;
  11827. }
  11828. for (int index = 0; index < AC_QUANTITY; index++)
  11829. {
  11830. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11831. {
  11832. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11833. {
  11834. match = TRUE;
  11835. GunNO = gun_index;
  11836. }
  11837. }
  11838. }// END FOR CHAdeMO_QUANTITY
  11839. } // END FOR AC ELSE
  11840. }// CHECK IF ResponseTransactionId == transactionIdInt
  11841. }//END FOR
  11842. if( match == TRUE)
  11843. {
  11844. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11845. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11846. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11847. }
  11848. else
  11849. {
  11850. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11851. }
  11852. }
  11853. else
  11854. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11855. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11856. return result;
  11857. }
  11858. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11859. {
  11860. mtrace();
  11861. int result = FAIL;
  11862. int connectorIdInt=0, reservationIdInt=0;
  11863. int tempIndex = 0;
  11864. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11865. char comfirmstr[20]={0};
  11866. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11867. int c = 0;
  11868. char *loc;
  11869. //char *ptr;
  11870. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11871. strcpy(sstrtemp, stringtrimspace(payload));
  11872. //***(1)connectorId ****/
  11873. c=0;
  11874. loc = strstr(sstrtemp, "connectorId");
  11875. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11876. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11877. {
  11878. sstr[c] = loc[strlen("connectorId")+2+c];
  11879. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11880. c++;
  11881. }
  11882. sstr[c] = '\0';
  11883. connectorIdInt = atoi(sstr);
  11884. //***(2)expiryDate ****/
  11885. loc = strstr(sstrtemp, "expiryDate");
  11886. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11887. c = 0;
  11888. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11889. {
  11890. sstr[c] = loc[3+strlen("expiryDate")+c];
  11891. c++;
  11892. }
  11893. sstr[c] = '\0';
  11894. strcpy(expiryDatestr, sstr);
  11895. //***(3)idTag ****/
  11896. loc = strstr(sstrtemp, "idTag");
  11897. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11898. c = 0;
  11899. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11900. {
  11901. sstr[c] = loc[3+strlen("idTag")+c];
  11902. c++;
  11903. }
  11904. sstr[c] = '\0';
  11905. strcpy(idTagstr, sstr);
  11906. //***(4)parentIdTag ****/
  11907. loc = strstr(sstrtemp, "parentIdTag");
  11908. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11909. c = 0;
  11910. if(loc == NULL)
  11911. {
  11912. strcpy(parentIdTagstr, "");
  11913. }
  11914. else
  11915. {
  11916. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11917. {
  11918. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11919. c++;
  11920. }
  11921. sstr[c] = '\0';
  11922. strcpy(parentIdTagstr, sstr);
  11923. }
  11924. //***(5)reservationId ****/
  11925. c=0;
  11926. loc = strstr(sstrtemp, "reservationId");
  11927. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11928. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11929. {
  11930. sstr[c] = loc[strlen("reservationId")+2+c];
  11931. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11932. c++;
  11933. }
  11934. sstr[c] = '\0';
  11935. reservationIdInt = atoi(sstr);
  11936. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11937. /*
  11938. enum SYSTEM_STATUS
  11939. {
  11940. SYS_MODE_BOOTING = 0,
  11941. SYS_MODE_IDLE = 1,
  11942. SYS_MODE_AUTHORIZING = 2,
  11943. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11944. SYS_MODE_REASSIGN = 4,
  11945. SYS_MODE_PREPARING = 5,
  11946. SYS_MODE_PREPARE_FOR_EV = 6,
  11947. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11948. SYS_MODE_CHARGING = 8,
  11949. SYS_MODE_TERMINATING = 9,
  11950. SYS_MODE_COMPLETE = 10,
  11951. SYS_MODE_ALARM = 11,
  11952. SYS_MODE_FAULT = 12,
  11953. SYS_MODE_RESERVATION = 13,
  11954. SYS_MODE_BOOKING = 14,
  11955. SYS_MODE_MAINTAIN = 15,
  11956. SYS_MODE_DEBUG = 16,
  11957. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11958. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11959. SYS_MODE_UPDATE = 19
  11960. };
  11961. */
  11962. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11963. {
  11964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11965. goto end;
  11966. }
  11967. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11968. {
  11969. //check Transaction active
  11970. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11971. {
  11972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11973. {
  11974. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11975. }
  11976. else
  11977. {
  11978. tempIndex = connectorIdInt -1;
  11979. }
  11980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11981. {
  11982. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11983. {
  11984. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11985. {
  11986. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11987. {
  11988. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11989. {
  11990. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11991. {
  11992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11993. }
  11994. else
  11995. {
  11996. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11998. }
  11999. }
  12000. 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'))
  12001. {
  12002. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12003. }
  12004. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12005. {
  12006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12007. }
  12008. else
  12009. {
  12010. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12011. }
  12012. }
  12013. 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
  12014. {
  12015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12016. }
  12017. }
  12018. else
  12019. {
  12020. //replace reservation
  12021. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12023. }
  12024. }
  12025. } // END FOR CHAdeMO_QUANTITY
  12026. }
  12027. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12028. {
  12029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12030. {
  12031. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12032. }
  12033. else
  12034. {
  12035. tempIndex = connectorIdInt -1;
  12036. }
  12037. for (int index = 0; index < CCS_QUANTITY; index++)
  12038. {
  12039. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12040. {
  12041. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12042. {
  12043. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12044. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12045. {
  12046. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12047. {
  12048. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12049. {
  12050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12051. }
  12052. else
  12053. {
  12054. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12056. }
  12057. }
  12058. 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'))
  12059. {
  12060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12061. }
  12062. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12063. {
  12064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12065. }
  12066. else
  12067. {
  12068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12069. }
  12070. }
  12071. 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
  12072. {
  12073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12074. }
  12075. }
  12076. else
  12077. {
  12078. //replace reservation
  12079. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12081. }
  12082. }
  12083. } // END FOR CCS_QUANTITY
  12084. }
  12085. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12086. {
  12087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12088. {
  12089. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12090. }
  12091. else
  12092. {
  12093. tempIndex = connectorIdInt -1;
  12094. }
  12095. for (int index = 0; index < GB_QUANTITY; index++)
  12096. {
  12097. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12098. {
  12099. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12100. {
  12101. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12102. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12103. {
  12104. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12105. {
  12106. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12107. {
  12108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12109. }
  12110. else
  12111. {
  12112. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12114. }
  12115. }
  12116. 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'))
  12117. {
  12118. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12119. }
  12120. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12121. {
  12122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12123. }
  12124. else
  12125. {
  12126. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12127. }
  12128. }
  12129. 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
  12130. {
  12131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12132. }
  12133. }
  12134. else
  12135. {
  12136. //replace reservation
  12137. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12139. }
  12140. }
  12141. }// END FOR GB_QUANTITY
  12142. }
  12143. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12144. {
  12145. tempIndex = connectorIdInt -1;
  12146. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12147. {
  12148. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12149. {
  12150. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12151. {
  12152. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12153. 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
  12154. {
  12155. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12156. {
  12157. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12158. {
  12159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12160. }
  12161. else
  12162. {
  12163. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12164. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12165. }
  12166. }
  12167. 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'))
  12168. {
  12169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12170. }
  12171. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12172. {
  12173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12174. }
  12175. else
  12176. {
  12177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12178. }
  12179. }
  12180. 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
  12181. {
  12182. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12183. }
  12184. }
  12185. else
  12186. {
  12187. //replace reservation
  12188. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12190. }
  12191. }
  12192. }// END FOR GB_QUANTITY
  12193. }
  12194. else
  12195. {
  12196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12197. {
  12198. tempIndex = 2;
  12199. }
  12200. else
  12201. {
  12202. tempIndex = (connectorIdInt -1);
  12203. }
  12204. for (int index = 0; index < AC_QUANTITY; index++)
  12205. {
  12206. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12207. {
  12208. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12209. {
  12210. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12211. {
  12212. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12213. {
  12214. 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))
  12215. {
  12216. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12217. }
  12218. else
  12219. {
  12220. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12221. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12222. }
  12223. }
  12224. 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'))
  12225. {
  12226. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12227. }
  12228. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12229. {
  12230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12231. }
  12232. else
  12233. {
  12234. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12235. }
  12236. }
  12237. 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
  12238. {
  12239. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12240. }
  12241. }
  12242. else
  12243. {
  12244. //replace reservation
  12245. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12246. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12247. }
  12248. }
  12249. } // END FOR AC_QUANTITY
  12250. }
  12251. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12252. }
  12253. else if(connectorIdInt == 0)
  12254. {
  12255. //check Transaction active
  12256. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12257. {
  12258. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12259. {
  12260. 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'))
  12261. {
  12262. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12263. goto end;
  12264. }
  12265. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12266. {
  12267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12268. goto end;
  12269. }
  12270. 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
  12271. {
  12272. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12273. goto end;
  12274. }
  12275. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12276. {
  12277. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12278. goto end;
  12279. }
  12280. }
  12281. }// END FOR CHAdeMO_QUANTITY
  12282. for (int index = 0; index < CCS_QUANTITY; index++)
  12283. {
  12284. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12285. {
  12286. 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'))
  12287. {
  12288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12289. goto end;
  12290. }
  12291. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12292. {
  12293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12294. goto end;
  12295. }
  12296. 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
  12297. {
  12298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12299. goto end;
  12300. }
  12301. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12302. {
  12303. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12304. goto end;
  12305. }
  12306. }
  12307. } // END FOR CCS_QUANTITY
  12308. for (int index = 0; index < GB_QUANTITY; index++)
  12309. {
  12310. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12311. {
  12312. 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'))
  12313. {
  12314. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12315. goto end;
  12316. }
  12317. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12318. {
  12319. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12320. goto end;
  12321. }
  12322. 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
  12323. {
  12324. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12325. goto end;
  12326. }
  12327. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12328. {
  12329. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12330. goto end;
  12331. }
  12332. }
  12333. } // END FOR GB_QUANTITY
  12334. for (int index = 0; index < AC_QUANTITY; index++)
  12335. {
  12336. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12337. {
  12338. 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'))
  12339. {
  12340. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12341. goto end;
  12342. }
  12343. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12344. {
  12345. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12346. goto end;
  12347. }
  12348. 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
  12349. {
  12350. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12351. goto end;
  12352. }
  12353. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12354. {
  12355. 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))
  12356. {
  12357. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12358. goto end;
  12359. }
  12360. }
  12361. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12362. {
  12363. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12364. goto end;
  12365. }
  12366. }
  12367. }// END FOR AC_QUANTITY
  12368. //The connectorId is 0
  12369. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12371. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12372. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12373. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12374. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12375. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12376. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12377. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12378. result = TRUE;
  12379. return result;
  12380. }
  12381. else
  12382. {
  12383. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12384. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12385. }
  12386. if(strcmp(comfirmstr,"Accepted") == 0)
  12387. {
  12388. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12389. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12390. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12391. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12392. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12393. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12394. result = TRUE;
  12395. return result;
  12396. }
  12397. end:
  12398. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12399. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12400. return result;
  12401. }
  12402. int handleResetRequest(char *uuid, char *payload)
  12403. {
  12404. mtrace();
  12405. int result = FAIL;
  12406. char sstr[10]={0},sstrtemp[30]={ 0 };
  12407. char typestr[10]={0};
  12408. char comfirmstr[20]={0};
  12409. int c = 0;
  12410. char *loc;
  12411. DEBUG_INFO("handleResetRequest...\n");
  12412. strcpy(sstrtemp, stringtrimspace(payload));
  12413. loc = strstr(sstrtemp, "type");
  12414. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12415. c = 0;
  12416. while (loc[3+strlen("type")+c] != '\"')
  12417. {
  12418. sstr[c] = loc[3+strlen("type")+c];
  12419. c++;
  12420. }
  12421. sstr[c] = '\0';
  12422. strcpy(typestr,sstr);
  12423. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12424. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12425. {
  12426. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12427. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12428. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12429. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12430. }
  12431. else
  12432. {
  12433. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12434. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12435. result = PASS;
  12436. }
  12437. sendResetConfirmation(uuid, comfirmstr);
  12438. return result;
  12439. }
  12440. int handleSendLocalListRequest(char *uuid, char *payload)
  12441. {
  12442. mtrace();
  12443. int result = FAIL;
  12444. char comfirmstr[20];
  12445. int checkState_Faulted = FALSE;
  12446. json_object *SendLocalList;
  12447. DEBUG_INFO("handleSendLocalListRequest...\n");
  12448. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12449. {
  12450. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12451. goto end;
  12452. }
  12453. //check Charge Point state
  12454. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12455. {
  12456. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12457. {
  12458. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12459. }
  12460. }
  12461. for (int index = 0; index < CCS_QUANTITY; index++)
  12462. {
  12463. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12464. {
  12465. checkState_Faulted = TRUE; //OCPP Status
  12466. }
  12467. }
  12468. for (int index = 0; index < GB_QUANTITY; index++)
  12469. {
  12470. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12471. {
  12472. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12473. }
  12474. }
  12475. //check Charge Point state
  12476. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12477. {
  12478. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12479. {
  12480. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12481. }
  12482. }
  12483. //check Charge Point state
  12484. for (int index = 0; index < AC_QUANTITY; index++)
  12485. {
  12486. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12487. {
  12488. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12489. }
  12490. }
  12491. if(checkState_Faulted == TRUE)
  12492. {
  12493. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12494. goto end;
  12495. }
  12496. // Parsing payload
  12497. SendLocalList = json_tokener_parse(payload);
  12498. if(!is_error(SendLocalList))
  12499. {
  12500. // Required data
  12501. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12502. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12503. // Optional data
  12504. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12505. {
  12506. //Check UpdateType
  12507. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12508. {
  12509. //Local list full update
  12510. DEBUG_INFO("Local list full update.\n");
  12511. locallistVersion = 0;
  12512. OCPP_getListVerion();
  12513. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12514. {
  12515. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12516. goto end;
  12517. }
  12518. OCPP_cleanLocalList();
  12519. }
  12520. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12521. {
  12522. //Local list different update
  12523. DEBUG_INFO("Local list different update.\n");
  12524. locallistVersion = 0;
  12525. OCPP_getListVerion();
  12526. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12527. {
  12528. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12529. goto end;
  12530. }
  12531. }
  12532. else
  12533. {
  12534. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12535. goto end;
  12536. }
  12537. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12538. {
  12539. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12540. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12541. goto end;
  12542. }
  12543. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12544. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12545. {
  12546. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag"))));
  12547. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12548. {
  12549. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", stringtrimspace((char *)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"))));
  12550. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12551. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", stringtrimspace((char *)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"))));
  12552. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12553. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", stringtrimspace((char *)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"))));
  12554. }
  12555. // Add to db
  12556. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12557. {
  12558. //Local list full update
  12559. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12560. idx,
  12561. ShmOCPP16Data->SendLocalList.ListVersion,
  12562. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12563. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12564. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12565. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12566. // update list
  12567. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12568. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12569. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12570. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12571. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12572. }
  12573. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12574. {
  12575. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12576. idx,
  12577. ShmOCPP16Data->SendLocalList.ListVersion,
  12578. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12579. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12580. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12581. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12582. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12583. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12584. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12585. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12586. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12587. }
  12588. }
  12589. }
  12590. else
  12591. {
  12592. //Check UpdateType
  12593. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12594. {
  12595. //Local list full update
  12596. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12597. OCPP_cleanLocalList();
  12598. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12599. goto end;
  12600. }
  12601. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12602. {
  12603. //Local list different update
  12604. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12605. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12606. goto end;
  12607. }
  12608. }
  12609. result = PASS;
  12610. }
  12611. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12612. end:
  12613. json_object_put(SendLocalList);
  12614. sendSendLocalListConfirmation(uuid, comfirmstr);
  12615. return result;
  12616. }
  12617. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12618. {
  12619. mtrace();
  12620. int result = FAIL;
  12621. struct StructSetChargingProfile SetProfileReq = {0};
  12622. int tempchargingProfileIdInt;
  12623. int tempstackLevelInt;
  12624. int chargingSchedulePeriodCount = 0;
  12625. char comfirmstr[20]={0};
  12626. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12627. char rmFileCmd[128]={0};
  12628. int profileQuantity = 0;
  12629. int replaceableProfileCnt = 0;
  12630. json_object *SetChargingProfile;
  12631. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12632. SetChargingProfile = json_tokener_parse(payload);
  12633. if(!is_error(SetChargingProfile))
  12634. {
  12635. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12636. {
  12637. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12638. }
  12639. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12640. {
  12641. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12642. {
  12643. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12644. }
  12645. else
  12646. {
  12647. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12648. DEBUG_WARN("Cannot find chargingProfileId field.");
  12649. goto end;
  12650. }
  12651. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12652. {
  12653. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12654. }
  12655. else
  12656. {
  12657. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12658. DEBUG_WARN("Cannot find stackLevel field.");
  12659. goto end;
  12660. }
  12661. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12662. {
  12663. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12664. }
  12665. else
  12666. {
  12667. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12668. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12669. goto end;
  12670. }
  12671. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12672. {
  12673. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12674. }
  12675. else
  12676. {
  12677. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12678. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12679. goto end;
  12680. }
  12681. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12682. {
  12683. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12684. }
  12685. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12686. {
  12687. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12688. }
  12689. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12690. {
  12691. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12692. }
  12693. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12694. {
  12695. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12696. }
  12697. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12698. {
  12699. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12700. {
  12701. 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")));
  12702. }
  12703. else
  12704. {
  12705. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12706. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12707. goto end;
  12708. }
  12709. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12710. {
  12711. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12712. }
  12713. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12714. {
  12715. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12716. }
  12717. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12718. {
  12719. 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")));
  12720. }
  12721. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12722. {
  12723. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12724. if(chargingSchedulePeriodCount <= 10)
  12725. {
  12726. 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++)
  12727. {
  12728. 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)
  12729. {
  12730. 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"));
  12731. }
  12732. else
  12733. {
  12734. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12735. DEBUG_WARN("Cannot find startPeriod field.");
  12736. goto end;
  12737. }
  12738. 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)
  12739. {
  12740. 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"));
  12741. }
  12742. else
  12743. {
  12744. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12745. DEBUG_WARN("Cannot find limit field.");
  12746. goto end;
  12747. }
  12748. 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)
  12749. {
  12750. 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"));
  12751. }
  12752. }
  12753. }
  12754. }
  12755. else
  12756. {
  12757. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12758. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12759. goto end;
  12760. }
  12761. }
  12762. else
  12763. {
  12764. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12765. DEBUG_WARN("Cannot find chargingSchedule field.");
  12766. goto end;
  12767. }
  12768. }
  12769. }
  12770. // Profile periods quantity check
  12771. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12772. {
  12773. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12774. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12775. goto end;
  12776. }
  12777. // Check invalid limit
  12778. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12779. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12780. {
  12781. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12782. {
  12783. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12784. {
  12785. 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)))) ||
  12786. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12787. {
  12788. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12789. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12790. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12791. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12792. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12793. goto end;
  12794. }
  12795. }
  12796. }
  12797. else
  12798. {
  12799. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12800. {
  12801. 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) ||
  12802. (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)))
  12803. {
  12804. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12805. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12806. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12807. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12808. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12809. goto end;
  12810. }
  12811. }
  12812. }
  12813. }
  12814. // Profile purpose info check
  12815. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12816. {
  12817. FILE *fp;
  12818. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12819. if(SetProfileReq.ConnectorId != 0)
  12820. {
  12821. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12822. DEBUG_WARN("Profile connector id is not 0.\n");
  12823. goto end;
  12824. }
  12825. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12826. if (!fp)
  12827. {
  12828. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12829. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12830. }
  12831. else
  12832. {
  12833. char *line = NULL;
  12834. size_t len = 0;
  12835. while(getline(&line, &len, fp) != -1)
  12836. {
  12837. json_object *obj = NULL;
  12838. obj = json_tokener_parse(line);
  12839. if(is_error(obj))
  12840. {
  12841. DEBUG_ERROR("Parse txProfile from file error.\n");
  12842. }
  12843. else
  12844. {
  12845. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12846. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12847. {
  12848. profileQuantity += 1;
  12849. }
  12850. else
  12851. replaceableProfileCnt += 1;
  12852. }
  12853. }
  12854. }
  12855. fclose(fp);
  12856. }
  12857. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12858. {
  12859. FILE *fp;
  12860. char filename[128]={0};
  12861. int tmpProfileQuantity;
  12862. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12863. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12864. {
  12865. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12866. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12867. goto end;
  12868. }
  12869. if(SetProfileReq.ConnectorId == 0)
  12870. {
  12871. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12872. {
  12873. tmpProfileQuantity = 0;
  12874. memset(filename, 0, ARRAY_SIZE(filename));
  12875. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12876. fp = fopen(filename, "r");
  12877. if (!fp)
  12878. {
  12879. DEBUG_INFO("%s does not create.\n", filename);
  12880. fp = fopen(filename, "w+");
  12881. }
  12882. else
  12883. {
  12884. char *line = NULL;
  12885. size_t len = 0;
  12886. while(getline(&line, &len, fp) != -1)
  12887. {
  12888. json_object *obj = NULL;
  12889. obj = json_tokener_parse(line);
  12890. if(is_error(obj))
  12891. {
  12892. DEBUG_ERROR("Parse txProfile from file error.\n");
  12893. }
  12894. else
  12895. {
  12896. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12897. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12898. {
  12899. tmpProfileQuantity += 1;
  12900. }
  12901. else
  12902. replaceableProfileCnt += 1;
  12903. }
  12904. }
  12905. }
  12906. fclose(fp);
  12907. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12908. }
  12909. }
  12910. else
  12911. {
  12912. memset(filename, 0, ARRAY_SIZE(filename));
  12913. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12914. fp = fopen(filename, "r");
  12915. if (!fp)
  12916. {
  12917. DEBUG_INFO("%s does not create.\n", filename);
  12918. fp = fopen(filename, "w+");
  12919. }
  12920. else
  12921. {
  12922. char *line = NULL;
  12923. size_t len = 0;
  12924. while(getline(&line, &len, fp) != -1)
  12925. {
  12926. json_object *obj = NULL;
  12927. obj = json_tokener_parse(line);
  12928. if(is_error(obj))
  12929. {
  12930. DEBUG_ERROR("Parse txProfile from file error.\n");
  12931. }
  12932. else
  12933. {
  12934. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12935. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12936. {
  12937. profileQuantity += 1;
  12938. }
  12939. else
  12940. replaceableProfileCnt += 1;
  12941. }
  12942. }
  12943. }
  12944. fclose(fp);
  12945. }
  12946. }
  12947. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12948. {
  12949. int isMatchTransactiodId= FALSE;
  12950. FILE *fp;
  12951. char filename[128]={0};
  12952. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12953. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12954. if(SetProfileReq.ConnectorId == 0)
  12955. {
  12956. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12957. DEBUG_WARN("Profile connector id is 0.\n");
  12958. goto end;
  12959. }
  12960. int tempIndex = 0;
  12961. //check Transaction active
  12962. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12963. {
  12964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12965. {
  12966. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12967. }
  12968. else
  12969. {
  12970. tempIndex = SetProfileReq.ConnectorId -1;
  12971. }
  12972. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12973. {
  12974. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12975. {
  12976. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12977. {
  12978. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12979. {
  12980. isMatchTransactiodId = TRUE;
  12981. break;
  12982. }
  12983. }
  12984. }
  12985. }
  12986. }
  12987. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12988. {
  12989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12990. {
  12991. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12992. }
  12993. else
  12994. {
  12995. tempIndex = SetProfileReq.ConnectorId -1;
  12996. }
  12997. for (int index = 0; index < CCS_QUANTITY; index++)
  12998. {
  12999. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13000. {
  13001. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13002. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13003. {
  13004. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13005. {
  13006. isMatchTransactiodId = TRUE;
  13007. break;
  13008. }
  13009. }
  13010. }
  13011. }
  13012. }
  13013. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13014. {
  13015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13016. {
  13017. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13018. }
  13019. else
  13020. {
  13021. tempIndex = SetProfileReq.ConnectorId -1;
  13022. }
  13023. for (int index = 0; index < GB_QUANTITY; index++)
  13024. {
  13025. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13026. {
  13027. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13028. {
  13029. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13030. {
  13031. isMatchTransactiodId = TRUE;
  13032. break;
  13033. }
  13034. }
  13035. }
  13036. }
  13037. }
  13038. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13039. {
  13040. tempIndex = SetProfileReq.ConnectorId -1;
  13041. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13042. {
  13043. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13044. {
  13045. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13046. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13047. {
  13048. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13049. {
  13050. isMatchTransactiodId = TRUE;
  13051. break;
  13052. }
  13053. }
  13054. }
  13055. }
  13056. }
  13057. else
  13058. {
  13059. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13060. {
  13061. tempIndex = 2;
  13062. }
  13063. else
  13064. {
  13065. tempIndex = (SetProfileReq.ConnectorId -1);
  13066. }
  13067. for (int index = 0; index < AC_QUANTITY; index++)
  13068. {
  13069. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13070. {
  13071. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13072. {
  13073. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13074. {
  13075. isMatchTransactiodId = TRUE;
  13076. break;
  13077. }
  13078. }
  13079. }
  13080. }
  13081. }
  13082. //check Transaction active
  13083. if(isMatchTransactiodId == FALSE)
  13084. {
  13085. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13086. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13087. goto end;
  13088. }
  13089. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13090. {
  13091. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13092. DEBUG_WARN("Connector id is over max gun number.\n");
  13093. goto end;
  13094. }
  13095. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  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. profileQuantity += 1;
  13120. }
  13121. else
  13122. replaceableProfileCnt += 1;
  13123. }
  13124. }
  13125. }
  13126. fclose(fp);
  13127. }
  13128. // Check ChargeProfileMaxStackLevel
  13129. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13130. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13131. {
  13132. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13133. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13134. goto end;
  13135. }
  13136. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13137. {
  13138. FILE *fp;
  13139. char dataLine[4096]={0};
  13140. char fnametemp[128]={0};
  13141. int tmpProfileQuantity;
  13142. //Check ChargePointMaxProfile.json exit
  13143. profileQuantity = 0;
  13144. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13145. {
  13146. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13147. //Check Charging Profile Count
  13148. tmpProfileQuantity = 0;
  13149. while(fscanf(fp, "%s", dataLine) != EOF)
  13150. {
  13151. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13152. {
  13153. profileQuantity += 1;
  13154. tmpProfileQuantity += 1;
  13155. }
  13156. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13157. }
  13158. fclose(fp);
  13159. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13160. }
  13161. //Check TxDefaultProfile_%d.json
  13162. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13163. {
  13164. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13165. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13166. if((access(fnametemp,F_OK))!=-1)
  13167. {
  13168. fp = fopen(fnametemp, "r");
  13169. //Check Charging Profile Count
  13170. tmpProfileQuantity = 0;
  13171. while(fscanf(fp, "%s", dataLine) != EOF)
  13172. {
  13173. //DEBUG_INFO("word=%s\n",word);
  13174. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13175. {
  13176. profileQuantity += 1;
  13177. tmpProfileQuantity += 1;
  13178. }
  13179. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13180. }
  13181. fclose(fp);
  13182. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13183. }
  13184. }
  13185. //Check TxProfile_%d.json
  13186. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13187. {
  13188. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13189. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13190. if((access(fnametemp,F_OK))!=-1)
  13191. {
  13192. fp = fopen(fnametemp, "r");
  13193. //Check Charging Profile Count
  13194. tmpProfileQuantity = 0;
  13195. while(fscanf(fp, "%s", dataLine) != EOF)
  13196. {
  13197. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13198. {
  13199. profileQuantity += 1;
  13200. tmpProfileQuantity += 1;
  13201. }
  13202. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13203. }
  13204. fclose(fp);
  13205. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13206. }
  13207. }
  13208. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13209. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13210. // To check total Profile quantity
  13211. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13212. {
  13213. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13214. {
  13215. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13216. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13217. goto end;
  13218. }
  13219. }
  13220. else
  13221. {
  13222. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13223. {
  13224. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13225. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13226. goto end;
  13227. }
  13228. }
  13229. }
  13230. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13231. //**********************************Write to File********************************************************/
  13232. {
  13233. FILE *infile;
  13234. FILE *outfile;
  13235. char dataLine[4096]={0};
  13236. char filename[128]={0};
  13237. int chkChar=0;
  13238. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13239. {
  13240. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13241. {
  13242. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13243. }
  13244. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13245. {
  13246. if(SetProfileReq.ConnectorId==0)
  13247. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13248. else
  13249. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13250. }
  13251. else
  13252. {
  13253. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13254. }
  13255. infile = fopen (filename, "r");
  13256. outfile = fopen (tempfile, "w");
  13257. chkChar = fgetc(infile);
  13258. rewind(infile);
  13259. if(chkChar == EOF)
  13260. {
  13261. // Profile is empty
  13262. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13263. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13264. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13265. fclose(infile);
  13266. fclose(outfile);
  13267. sprintf(rmFileCmd,"rm -f %s",filename);
  13268. system(rmFileCmd);
  13269. rename(tempfile, filename);
  13270. }
  13271. else
  13272. {
  13273. // Profile is not empty
  13274. int ChargingProfileAdded = FALSE;
  13275. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13276. {
  13277. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13278. json_object *tmpChargingProfile;
  13279. tmpChargingProfile = json_tokener_parse(dataLine);
  13280. if(!is_error(SetChargingProfile))
  13281. {
  13282. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13283. {
  13284. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13285. {
  13286. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13287. }
  13288. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13289. {
  13290. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13291. }
  13292. }
  13293. }
  13294. json_object_put(tmpChargingProfile);
  13295. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13296. {
  13297. if(ChargingProfileAdded == FALSE)
  13298. {
  13299. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13300. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13301. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13302. ChargingProfileAdded = TRUE;
  13303. }
  13304. }
  13305. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13306. {
  13307. if(ChargingProfileAdded == FALSE)
  13308. {
  13309. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13310. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13311. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13312. ChargingProfileAdded = TRUE;
  13313. }
  13314. }
  13315. else
  13316. {
  13317. fprintf(outfile,"%s\n",dataLine);
  13318. if(ChargingProfileAdded == FALSE)
  13319. {
  13320. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13321. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13322. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13323. ChargingProfileAdded = TRUE;
  13324. }
  13325. }
  13326. } // end of while loop
  13327. fclose(infile);
  13328. fclose(outfile);
  13329. sprintf(rmFileCmd,"rm -f %s",filename);
  13330. system(rmFileCmd);
  13331. rename(tempfile, filename);
  13332. }
  13333. }
  13334. sleep(1);
  13335. result = TRUE;
  13336. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13337. }
  13338. end:
  13339. json_object_put(SetChargingProfile);
  13340. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13341. {
  13342. if(SetProfileReq.ConnectorId == 0)
  13343. {
  13344. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13345. {
  13346. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13347. }
  13348. }
  13349. else
  13350. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13351. }
  13352. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13353. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13354. return result;
  13355. }
  13356. int handleTriggerMessageRequest(char *uuid, char *payload)
  13357. {
  13358. mtrace();
  13359. int result = FAIL;
  13360. int connectorIdIsNULL = FALSE;
  13361. int connectorIdInt =0;
  13362. char sstr[40]={0},sstrtemp[100]={ 0 };
  13363. char requestedMessagestr[40]={0};
  13364. char comfirmstr[20]={0};
  13365. int c = 0;
  13366. char *loc;
  13367. DEBUG_INFO("handleTriggerMessageRequest\n");
  13368. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13369. strcpy(sstrtemp, stringtrimspace(payload));
  13370. c = 0;
  13371. loc = strstr(sstrtemp, "requestedMessage");
  13372. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13373. {
  13374. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13375. c++;
  13376. }
  13377. sstr[c] = '\0';
  13378. strcpy(requestedMessagestr, sstr);
  13379. c = 0;
  13380. loc = strstr(sstrtemp, "connectorId");
  13381. if(loc == NULL)
  13382. {
  13383. connectorIdIsNULL = TRUE;
  13384. }
  13385. else
  13386. {
  13387. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13388. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13389. {
  13390. sstr[c] = loc[strlen("connectorId")+2+c];
  13391. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13392. c++;
  13393. }
  13394. sstr[c] = '\0';
  13395. connectorIdInt = atoi(sstr);
  13396. }
  13397. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13398. {
  13399. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13400. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13401. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13402. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13403. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13404. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13405. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13406. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13407. {
  13408. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13409. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13410. return TRUE;
  13411. }
  13412. else
  13413. {
  13414. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13415. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13416. }
  13417. }
  13418. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13419. {
  13420. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13421. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13422. return TRUE;
  13423. }
  13424. //==========================
  13425. // Trigger message
  13426. //==========================
  13427. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13428. {
  13429. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13430. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13431. {
  13432. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13433. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13434. }
  13435. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13436. }
  13437. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13438. {
  13439. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13440. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13441. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13442. }
  13443. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13444. {
  13445. //sendBootNotificationRequest();
  13446. server_sign = FALSE;
  13447. }
  13448. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13449. {
  13450. refreshStartTimer(&clientTime.Heartbeat);
  13451. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13452. }
  13453. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13454. {
  13455. if(connectorIdIsNULL == FALSE)
  13456. {
  13457. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13458. {
  13459. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13460. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13461. }
  13462. }
  13463. else
  13464. {
  13465. for(int idx=0;idx< gunTotalNumber;idx++)
  13466. {
  13467. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13468. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13469. }
  13470. }
  13471. }
  13472. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13473. {
  13474. if(connectorIdIsNULL == FALSE)
  13475. {
  13476. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13477. {
  13478. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13479. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13480. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13481. }
  13482. }
  13483. else
  13484. {
  13485. for(int idx=0;idx< gunTotalNumber;idx++)
  13486. {
  13487. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13488. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13489. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13490. }
  13491. }
  13492. }
  13493. return result;
  13494. }
  13495. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13496. {
  13497. mtrace();
  13498. int result = FAIL;
  13499. int connectorIdInt =0;
  13500. char comfirmstr[20]={0};
  13501. int tempIndex = 0;
  13502. json_object *UnlockConnector;
  13503. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13504. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13505. UnlockConnector = json_tokener_parse(payload);
  13506. if(!is_error(UnlockConnector))
  13507. {
  13508. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13509. {
  13510. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13511. }
  13512. }
  13513. json_object_put(UnlockConnector);
  13514. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13515. if(gunTotalNumber == 0)
  13516. {
  13517. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13518. goto end;
  13519. }
  13520. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13521. {
  13522. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13523. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13524. goto end;
  13525. }
  13526. else
  13527. {
  13528. //check Transaction active
  13529. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13530. {
  13531. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13532. {
  13533. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13534. }
  13535. else
  13536. {
  13537. tempIndex = connectorIdInt -1;
  13538. }
  13539. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13540. {
  13541. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13542. {
  13543. //stop Transaction
  13544. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13545. }
  13546. }
  13547. }
  13548. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13549. {
  13550. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13551. {
  13552. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13553. }
  13554. else
  13555. {
  13556. tempIndex = connectorIdInt -1;
  13557. }
  13558. for (int index = 0; index < CCS_QUANTITY; index++)
  13559. {
  13560. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13561. {
  13562. //stop Transaction
  13563. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13564. }
  13565. }
  13566. }
  13567. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13568. {
  13569. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13570. {
  13571. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13572. }
  13573. else
  13574. {
  13575. tempIndex = connectorIdInt -1;
  13576. }
  13577. for (int index = 0; index < GB_QUANTITY; index++)
  13578. {
  13579. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13580. {
  13581. //stop Transaction
  13582. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13583. }
  13584. }
  13585. }
  13586. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13587. {
  13588. tempIndex = connectorIdInt -1;
  13589. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13590. {
  13591. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13592. {
  13593. //stop Transaction
  13594. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13595. }
  13596. }
  13597. }
  13598. else
  13599. {
  13600. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13601. {
  13602. tempIndex = 2;
  13603. }
  13604. else
  13605. {
  13606. tempIndex = connectorIdInt-1;
  13607. }
  13608. for (int index = 0; index < AC_QUANTITY; index++)
  13609. {
  13610. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13611. {
  13612. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13613. }
  13614. }
  13615. }
  13616. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13617. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13618. result = TRUE;
  13619. return result;
  13620. }
  13621. end:
  13622. //json_object_put(obj); --- remove temporally
  13623. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13624. return result;
  13625. }
  13626. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13627. {
  13628. mtrace();
  13629. int result = FAIL;
  13630. pthread_t t;
  13631. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13632. sendUpdateFirmwareConfirmation(uuid);
  13633. if(!interLock.isUpdateFirmwareGoing)
  13634. {
  13635. interLock.isUpdateFirmwareGoing = 1;
  13636. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13637. sleep(1);
  13638. }
  13639. else
  13640. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13641. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13642. return result;
  13643. }
  13644. void *UpdateFirmwareProcess(void *data)
  13645. {
  13646. pthread_detach(pthread_self());
  13647. mtrace();
  13648. int retriesInt =0, retryIntervalInt=0;
  13649. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13650. int port=0;
  13651. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13652. int isSuccess = 0;
  13653. char ftpbuf[1024];
  13654. char temp[1024];
  13655. char * pch;
  13656. json_object *UpdateFirmware;
  13657. UpdateFirmware = json_tokener_parse(data);
  13658. if(!is_error(UpdateFirmware))
  13659. {
  13660. // Required data
  13661. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13662. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13663. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13664. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13665. // Optional data
  13666. if(json_object_object_get(UpdateFirmware, "retries"))
  13667. {
  13668. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13669. }
  13670. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13671. {
  13672. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13673. }
  13674. }
  13675. json_object_put(UpdateFirmware);
  13676. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13677. memset(path, 0, ARRAY_SIZE(path));
  13678. // Wait retrieveData
  13679. if(strlen(retrieveDatestr) > 10)
  13680. {
  13681. do
  13682. {
  13683. sleep(1);
  13684. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13685. }
  13686. // Ready to download
  13687. system("rm -f /mnt/*");
  13688. if(strncmp(locationstr,"http", 4) == 0)
  13689. {
  13690. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13691. sprintf(ftppath,"/%s", path);
  13692. DEBUG_INFO("locationstr: %s\n", locationstr);
  13693. DEBUG_INFO("protocol: %s\n",protocol);
  13694. DEBUG_INFO("host: %s\n",host);
  13695. DEBUG_INFO("path: %s\n",path);
  13696. DEBUG_INFO("ftppath: %s\n",ftppath);
  13697. int ftppathlen=strlen(ftppath);
  13698. int i=1;
  13699. char filenametemp[50];
  13700. while(i < ftppathlen)
  13701. {
  13702. int len=ftppathlen-i;
  13703. if(ftppath[len]== 47) // '/' ascll code: 47
  13704. {
  13705. DEBUG_INFO("compare '/' all right\n");
  13706. break;
  13707. }
  13708. i=i+1;
  13709. }
  13710. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13711. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13712. filenametemp[i+1] = 0;
  13713. do
  13714. {
  13715. sleep(1);
  13716. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13717. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13718. sleep(1);
  13719. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13720. if(!isSuccess)
  13721. {
  13722. sleep(1);
  13723. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13724. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13725. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13726. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13727. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13728. }
  13729. else
  13730. {
  13731. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13732. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13733. }
  13734. retriesInt--;
  13735. }while((isSuccess == 0)&&(retriesInt >= 0));
  13736. }
  13737. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13738. {
  13739. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13740. memset(temp, 0, ARRAY_SIZE(temp));
  13741. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13742. strcpy(ftpbuf, locationstr);
  13743. int ftppathlen=strlen(ftpbuf);
  13744. int i=1;
  13745. char filenametemp[50];
  13746. while(i < ftppathlen)
  13747. {
  13748. int len=ftppathlen-i;
  13749. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13750. {
  13751. DEBUG_INFO(" compare '/' all right\n");
  13752. break;
  13753. }
  13754. i=i+1;
  13755. }
  13756. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13757. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13758. filenametemp[i+1] = 0;
  13759. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13760. pch=strchr(temp,'@');
  13761. if(pch==NULL)
  13762. {
  13763. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13764. protocol, host, &port, path);
  13765. strcpy(user,"anonymous");
  13766. strcpy(password,"");
  13767. }
  13768. else
  13769. {
  13770. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13771. protocol, user, host, &port, path);
  13772. }
  13773. sscanf(host,"%[^/]%s",host1, path1);
  13774. sprintf(ftppath,"%s:/%s", host,path);
  13775. if(port == 0)
  13776. {
  13777. port = 21;
  13778. }
  13779. do
  13780. {
  13781. sleep(1);
  13782. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13783. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13784. sleep(1);
  13785. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13786. if(!isSuccess)
  13787. {
  13788. //BulldogUtil.sleepMs(interval*1000);
  13789. DEBUG_INFO("Update firmware request and download file fail.\n");
  13790. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13791. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13792. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13793. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13794. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13795. }
  13796. else
  13797. {
  13798. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13799. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13800. }
  13801. retriesInt--;
  13802. }while((!isSuccess)&&(retriesInt >= 0));
  13803. }
  13804. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13805. {
  13806. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13807. memset(temp, 0, ARRAY_SIZE(temp));
  13808. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13809. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13810. int ftppathlen=strlen(ftpbuf);
  13811. int i=1;
  13812. char filenametemp[50];
  13813. while(i < ftppathlen)
  13814. {
  13815. int len=ftppathlen-i;
  13816. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13817. {
  13818. DEBUG_INFO(" compare '/' all right\n");
  13819. break;
  13820. }
  13821. i=i+1;
  13822. }
  13823. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13824. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13825. filenametemp[i+1] = 0;
  13826. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13827. pch=strchr(temp,'@');
  13828. if(pch==NULL)
  13829. {
  13830. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13831. protocol, host, &port, path);
  13832. strcpy(user,"anonymous");
  13833. strcpy(password,"");
  13834. }
  13835. else
  13836. {
  13837. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13838. protocol, user, password, host, &port, path);
  13839. }
  13840. sscanf(host,"%[^/]%s",host1, path1);
  13841. sprintf(ftppath,"%s", path1);
  13842. //DEBUG_INFO("protocol =%s\n",protocol);
  13843. //DEBUG_INFO("user =%s\n",user);
  13844. //DEBUG_INFO("password =%s\n",password);
  13845. //DEBUG_INFO("host1 =%s\n",host1);
  13846. //DEBUG_INFO("port =%d\n",port);
  13847. //DEBUG_INFO("path1 =%s\n",path1);
  13848. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13849. //ftpFile(host, user, password, port, ftppath, fname);
  13850. //download firmware pthred
  13851. if(port == 0)
  13852. {
  13853. port = 21;
  13854. }
  13855. do
  13856. {
  13857. sleep(1);
  13858. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13859. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13860. sleep(1);
  13861. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13862. if(!isSuccess)
  13863. {
  13864. //BulldogUtil.sleepMs(interval*1000);
  13865. DEBUG_INFO("Update firmware request and download file fail.\n");
  13866. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13867. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13868. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13869. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13870. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13871. }
  13872. else
  13873. {
  13874. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13875. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13876. }
  13877. retriesInt--;
  13878. }while((!isSuccess)&&(retriesInt >= 0));
  13879. }
  13880. else
  13881. {
  13882. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13883. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13884. sleep(1);
  13885. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13886. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13887. }
  13888. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13889. {
  13890. sleep(3);
  13891. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13892. }
  13893. interLock.isUpdateFirmwareGoing = 0;
  13894. pthread_exit(NULL);
  13895. }
  13896. int handleCertificateSignedRequest(char *uuid, char *payload)
  13897. {
  13898. mtrace();
  13899. int result = PASS;
  13900. json_object *CertificateSigned;
  13901. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13902. CertificateSigned = json_tokener_parse(payload);
  13903. if(!is_error(CertificateSigned))
  13904. {
  13905. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13906. }
  13907. json_object_put(CertificateSigned);
  13908. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  13909. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13910. fclose(fp);
  13911. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13912. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13913. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  13914. {
  13915. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13916. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  13917. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  13918. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  13919. }
  13920. else
  13921. {
  13922. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  13923. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  13924. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  13925. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  13926. }
  13927. sendCertificateSignedConfirmation(uuid);
  13928. return result;
  13929. }
  13930. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13931. {
  13932. mtrace();
  13933. int result = PASS;
  13934. json_object *DeleteCertificate;
  13935. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13936. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13937. DeleteCertificate = json_tokener_parse(payload);
  13938. if(!is_error(DeleteCertificate))
  13939. {
  13940. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13941. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13942. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13943. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13944. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13945. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13946. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13947. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13948. char temp[256] = {0};
  13949. char compareData[256] = {0};
  13950. int isMatch = TRUE;
  13951. FILE *fp;
  13952. if(access(ROOTCA_CS,F_OK) != -1)
  13953. {
  13954. // Check CentralSystemRootCertificate
  13955. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  13956. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  13957. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13958. isMatch = FALSE;
  13959. if(isMatch == TRUE)
  13960. {
  13961. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  13962. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13963. isMatch = FALSE;
  13964. }
  13965. if(isMatch == TRUE)
  13966. {
  13967. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  13968. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13969. isMatch = FALSE;
  13970. }
  13971. if(isMatch == TRUE)
  13972. {
  13973. sprintf(temp, "rm -f /Storage/OCPP/%s", ROOTCA_CS);
  13974. system(temp);
  13975. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  13976. goto End;
  13977. }
  13978. }
  13979. // Check ManufacturerRootCertificate
  13980. if(access(ROOTCA_MFG,F_OK) != -1)
  13981. {
  13982. isMatch = TRUE;
  13983. parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, compareData);
  13984. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13985. isMatch = FALSE;
  13986. if(isMatch == TRUE)
  13987. {
  13988. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, compareData);
  13989. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13990. isMatch = FALSE;
  13991. }
  13992. if(isMatch == TRUE)
  13993. {
  13994. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, compareData);
  13995. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13996. isMatch = FALSE;
  13997. }
  13998. if(isMatch == TRUE)
  13999. {
  14000. sprintf(temp, "rm -f %s", ROOTCA_MFG);
  14001. system(temp);
  14002. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14003. goto End;
  14004. }
  14005. }
  14006. // Check certCP
  14007. if(access(CERTIFICATE_CP,F_OK) != -1)
  14008. {
  14009. isMatch = FALSE;
  14010. sprintf(temp ,"openssl x509 -noout -serial -in %s", CERTIFICATE_CP);
  14011. fp = popen(temp, "r");
  14012. if(fp)
  14013. {
  14014. while(fgets(temp, sizeof(temp), fp) != NULL)
  14015. {
  14016. if(strstr(temp, "serial=") != NULL)
  14017. {
  14018. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14019. sscanf(temp, "%*[^=]=%s", compareData);
  14020. break;
  14021. }
  14022. }
  14023. }
  14024. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14025. isMatch = FALSE;
  14026. if(isMatch == TRUE)
  14027. {
  14028. memset(compareData, 0, ARRAY_SIZE(compareData));
  14029. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14030. fp = popen(temp, "r");
  14031. if(fp)
  14032. {
  14033. while(fgets(temp, sizeof(temp), fp) != NULL)
  14034. {
  14035. strcat(compareData, temp);
  14036. }
  14037. }
  14038. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  14039. isMatch = FALSE;
  14040. }
  14041. if(isMatch == TRUE)
  14042. {
  14043. memset(compareData, 0, ARRAY_SIZE(compareData));
  14044. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14045. fp = popen(temp, "r");
  14046. if(fp)
  14047. {
  14048. while(fgets(temp, sizeof(temp), fp) != NULL)
  14049. {
  14050. strcat(compareData, temp);
  14051. }
  14052. }
  14053. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14054. isMatch = FALSE;
  14055. }
  14056. if(isMatch == TRUE)
  14057. {
  14058. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14059. system(temp);
  14060. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14061. goto End;
  14062. }
  14063. }
  14064. }
  14065. End:
  14066. json_object_put(DeleteCertificate);
  14067. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14068. sendDeleteCertificateConfirmation(uuid);
  14069. return result;
  14070. }
  14071. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14072. {
  14073. mtrace();
  14074. int result = PASS;
  14075. json_object *ExtendedTriggerMessage;
  14076. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14077. ExtendedTriggerMessage = json_tokener_parse(payload);
  14078. if(!is_error(ExtendedTriggerMessage))
  14079. {
  14080. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14081. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14082. {
  14083. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14084. }
  14085. else
  14086. {
  14087. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14088. }
  14089. }
  14090. json_object_put(ExtendedTriggerMessage);
  14091. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14092. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14093. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14094. {
  14095. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14096. }
  14097. else
  14098. {
  14099. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14100. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14101. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14102. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14103. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14104. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14105. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14106. {
  14107. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14108. }
  14109. else
  14110. {
  14111. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14112. }
  14113. }
  14114. sendExtendedTriggerMessageConfirmation(uuid);
  14115. //==========================
  14116. // Trigger message
  14117. //==========================
  14118. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14119. {
  14120. //sendBootNotificationRequest();
  14121. server_sign = FALSE;
  14122. }
  14123. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14124. {
  14125. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14126. }
  14127. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14128. {
  14129. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14130. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14131. {
  14132. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14133. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14134. }
  14135. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14136. }
  14137. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14138. {
  14139. refreshStartTimer(&clientTime.Heartbeat);
  14140. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14141. }
  14142. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14143. {
  14144. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14145. {
  14146. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14147. }
  14148. else
  14149. {
  14150. for(int idx=0;idx< gunTotalNumber;idx++)
  14151. {
  14152. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14153. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14154. }
  14155. }
  14156. }
  14157. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14158. {
  14159. char cmdBuf[1024]={0};
  14160. 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);
  14161. system(cmdBuf);
  14162. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14163. }
  14164. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14165. {
  14166. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14167. {
  14168. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14169. }
  14170. else
  14171. {
  14172. for(int idx=0;idx< gunTotalNumber;idx++)
  14173. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14174. }
  14175. }
  14176. return result;
  14177. }
  14178. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14179. {
  14180. mtrace();
  14181. int result = PASS;
  14182. json_object *GetInstalledCertificateIds;
  14183. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14184. GetInstalledCertificateIds = json_tokener_parse(payload);
  14185. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14186. if(!is_error(GetInstalledCertificateIds))
  14187. {
  14188. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14189. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14190. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14191. // Check CentralSystemRootCertificate
  14192. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL) && (access(ROOTCA_CS,F_OK) != -1))
  14193. {
  14194. char parseData[512] = {0};
  14195. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14196. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14197. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, parseData) == PASS)
  14198. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14199. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14200. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14201. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14202. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14203. }
  14204. else
  14205. {
  14206. DEBUG_INFO(">>> No CentralSystemRootCertificate found.\n");
  14207. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14208. }
  14209. // Check ManufacturerRootCertificate
  14210. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL) && (access(ROOTCA_MFG,F_OK) != -1))
  14211. {
  14212. char parseData[512] = {0};
  14213. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14214. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14215. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14216. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14217. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14218. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14219. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14220. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14221. }
  14222. else
  14223. {
  14224. DEBUG_INFO(">>> No ManufacturerRootCertificate found.\n");
  14225. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14226. }
  14227. }
  14228. json_object_put(GetInstalledCertificateIds);
  14229. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14230. sendGetInstalledCertificateIdsConfirmation(uuid);
  14231. return result;
  14232. }
  14233. void* GetLogProcess(void* data)
  14234. {
  14235. pthread_detach(pthread_self());
  14236. mtrace();
  14237. 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};
  14238. int port=0;
  14239. int isSuccess = FALSE;
  14240. char cmdBuf[2048];
  14241. struct tm *tmNow;
  14242. time_t CurrentTime;
  14243. struct tm tmStart;
  14244. struct tm tmStop;
  14245. CurrentTime = time(NULL);
  14246. tmNow=localtime(&CurrentTime);
  14247. uint16_t targetYear, targetMonth;
  14248. json_object *GetLog;
  14249. DEBUG_INFO("GetLogProcess...\n");
  14250. GetLog = json_tokener_parse(data);
  14251. if(!is_error(GetLog))
  14252. {
  14253. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14254. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14255. if(json_object_object_get(GetLog, "retries") != NULL)
  14256. {
  14257. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14258. }
  14259. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14260. {
  14261. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14262. }
  14263. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14264. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14265. {
  14266. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14267. }
  14268. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14269. {
  14270. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14271. }
  14272. }
  14273. json_object_put(GetLog);
  14274. // Pack log to compress file
  14275. 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) &&
  14276. (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))
  14277. {
  14278. // Pack system log
  14279. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14280. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14281. targetYear = tmStart.tm_year;
  14282. targetMonth = tmStart.tm_mon;
  14283. do
  14284. {
  14285. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14286. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14287. if(targetMonth+1>=13)
  14288. {
  14289. targetYear += 1;
  14290. targetMonth = 1;
  14291. }
  14292. else
  14293. {
  14294. targetMonth += 1;
  14295. }
  14296. }while((targetYear < (tmNow->tm_year+1900)) ||
  14297. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14298. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14299. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14300. system(cmdBuf);
  14301. // Pack charging & event log
  14302. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14303. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14304. targetYear = tmStart.tm_year;
  14305. targetMonth = tmStart.tm_mon;
  14306. do
  14307. {
  14308. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14309. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14310. if(targetMonth+1>=13)
  14311. {
  14312. targetYear += 1;
  14313. targetMonth = 1;
  14314. }
  14315. else
  14316. {
  14317. targetMonth += 1;
  14318. }
  14319. }while((targetYear < (tmNow->tm_year+1900)) ||
  14320. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14321. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14322. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14323. system(cmdBuf);
  14324. // Combine log file
  14325. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14326. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14327. }
  14328. else
  14329. {
  14330. system("exec /root/logPackTools 'log' 6");
  14331. }
  14332. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14333. system(cmdBuf);
  14334. checkUploadLog();
  14335. //****************location*******************/
  14336. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14337. {
  14338. DEBUG_INFO("location is <Empty>!\n");
  14339. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14340. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14341. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14342. goto end;
  14343. }
  14344. memset(protocol, 0, ARRAY_SIZE(protocol));
  14345. memset(user, 0, ARRAY_SIZE(user) );
  14346. memset(password, 0, ARRAY_SIZE(password));
  14347. memset(host, 0, ARRAY_SIZE(host));
  14348. memset(path, 0, ARRAY_SIZE(path));
  14349. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14350. memset(host1, 0, ARRAY_SIZE(host1));
  14351. memset(path1, 0, ARRAY_SIZE(path1));
  14352. /*location: ftp://user:password@host:port/path*/
  14353. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14354. if((access(fnamePlusPath,F_OK))!=-1)
  14355. {
  14356. DEBUG_INFO("fnamePlusPath exist.\n");
  14357. }
  14358. else
  14359. {
  14360. DEBUG_INFO("fnamePlusPath not exist!\n");
  14361. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14362. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14363. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14364. goto end;
  14365. }
  14366. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14367. {
  14368. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14369. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14370. protocol, host, &port, path);
  14371. strcpy(user,"anonymous");
  14372. strcpy(password,"");
  14373. }
  14374. else
  14375. {
  14376. //DEBUG_INFO("pch=%s\n", pch);
  14377. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14378. protocol, user, password, host, &port, path);
  14379. }
  14380. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14381. {
  14382. DEBUG_INFO("protocol is not ftp/http ! \n");
  14383. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14384. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14385. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14386. goto end;
  14387. }
  14388. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14389. {
  14390. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14391. sprintf(ftppath,"/%s", path);
  14392. do
  14393. {
  14394. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14395. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14396. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14397. sleep(3);
  14398. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14399. if(!isSuccess)
  14400. {
  14401. DEBUG_INFO("Diagnostics fail.\n");
  14402. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14403. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14404. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14405. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14406. }
  14407. else
  14408. {
  14409. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14410. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14411. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14412. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14413. }
  14414. ShmOCPP16Data->GetLog.retries--;
  14415. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14416. }
  14417. else
  14418. {
  14419. sscanf(host,"%[^/]%s",host1, path1);
  14420. if(strlen(path) > 0)
  14421. sprintf(ftppath,"/%s", path);
  14422. else
  14423. sprintf(ftppath,"/%s", path1);
  14424. int ftppathlen=strlen(ftppath);
  14425. int i=1;
  14426. char filenametemp[50];
  14427. while(i < ftppathlen)
  14428. {
  14429. int len=ftppathlen-i;
  14430. if(ftppath[len]== 47) // '/' ascll code: 47
  14431. {
  14432. DEBUG_INFO("find '/' all right\n");
  14433. break;
  14434. }
  14435. i=i+1;
  14436. }
  14437. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14438. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14439. filenametemp[i+1] = 0;
  14440. if(port == 0)
  14441. port = 21;
  14442. do
  14443. {
  14444. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14445. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14446. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14447. sleep(3);
  14448. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14449. if(!isSuccess)
  14450. {
  14451. DEBUG_INFO("Diagnostics fail.\n");
  14452. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14453. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14454. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14455. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14456. }
  14457. else
  14458. {
  14459. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14460. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14461. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14462. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14463. }
  14464. ShmOCPP16Data->GetLog.retries--;
  14465. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14466. }
  14467. end:
  14468. system("rm -f /mnt/*");
  14469. sleep(5);
  14470. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14471. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14472. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14473. interLock.isGetDiagnosticGoing = 0;
  14474. pthread_exit(NULL);
  14475. }
  14476. int handleGetLogRequest(char *uuid, char *payload)
  14477. {
  14478. mtrace();
  14479. int result = PASS;
  14480. time_t CurrentTime;
  14481. struct tm *tm;
  14482. DEBUG_INFO("handleGetLogRequest...\n");
  14483. pthread_t th_Status;
  14484. CurrentTime = time(NULL);
  14485. tm = localtime(&CurrentTime);
  14486. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14487. 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);
  14488. if(!interLock.isGetDiagnosticGoing)
  14489. {
  14490. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14491. interLock.isGetDiagnosticGoing = 1;
  14492. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14493. sleep(1);
  14494. }
  14495. else
  14496. {
  14497. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14498. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14499. }
  14500. sendGetLogConfirmation(uuid);
  14501. return result;
  14502. }
  14503. int handleInstallCertificateRequest(char *uuid, char *payload)
  14504. {
  14505. mtrace();
  14506. int result = PASS;
  14507. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14508. json_object *InstallCertificate;
  14509. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14510. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14511. InstallCertificate = json_tokener_parse(payload);
  14512. if(!is_error(InstallCertificate))
  14513. {
  14514. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14515. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14516. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14517. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14518. char temp[1024];
  14519. FILE *fp = fopen(tempCert, "w");
  14520. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14521. fclose(fp);
  14522. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14523. char strExpDate[30];
  14524. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14525. fp = popen(temp, "r");
  14526. if(fp)
  14527. {
  14528. while(fgets(temp, sizeof(temp), fp) != NULL)
  14529. {
  14530. if(strstr(temp, "notAfter=") != NULL)
  14531. {
  14532. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14533. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14534. break;
  14535. }
  14536. }
  14537. }
  14538. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14539. struct tm tmExpDate;
  14540. struct timeb tbExpDate;
  14541. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14542. tbExpDate.time = mktime(&tmExpDate);
  14543. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14544. {
  14545. DEBUG_INFO("The enddate is already expired...\n");
  14546. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14547. goto End;
  14548. }
  14549. // Verify certificate with rootCA
  14550. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14551. fp = popen(temp, "r");
  14552. if(fp)
  14553. {
  14554. while(fgets(temp, sizeof(temp), fp) != NULL)
  14555. {
  14556. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14557. {
  14558. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14559. break;
  14560. }
  14561. else
  14562. {
  14563. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14564. }
  14565. }
  14566. }
  14567. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14568. {
  14569. //=====================================================
  14570. // Verify if the certificate is valid or not. (OCSP?)
  14571. //=====================================================
  14572. /*
  14573. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14574. // Get ocsp url
  14575. char ocspUrl[512];
  14576. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14577. fp = popen(temp, "r");
  14578. if(fp)
  14579. {
  14580. while(fgets(temp, sizeof(temp), fp) != NULL)
  14581. {
  14582. if(strstr(temp, "://") != NULL)
  14583. {
  14584. strcpy(ocspUrl, temp);
  14585. break;
  14586. }
  14587. }
  14588. }
  14589. // Get certificate chain for issuer
  14590. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14591. *
  14592. // Execute OCSP
  14593. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14594. fp = popen(temp, "r");
  14595. if(fp)
  14596. {
  14597. while(fgets(temp, sizeof(temp), fp) != NULL)
  14598. {
  14599. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14600. {
  14601. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14602. break;
  14603. }
  14604. }
  14605. }
  14606. system("rm -f /Storage/OCPP/tempChain.pem");
  14607. pclose(fp);
  14608. */
  14609. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14610. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14611. {
  14612. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14613. goto End;
  14614. }
  14615. else
  14616. DEBUG_INFO("OCSP verifying...PASS.\n");
  14617. }
  14618. else
  14619. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14620. }
  14621. End:
  14622. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14623. {
  14624. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14625. {
  14626. if(access(ROOTCA_CS,F_OK) != -1)
  14627. {
  14628. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14629. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14630. rename(tempCert, ROOTCA_CS);
  14631. }
  14632. else
  14633. {
  14634. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14635. rename(tempCert, ROOTCA_CS);
  14636. }
  14637. }
  14638. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14639. {
  14640. if(access(ROOTCA_MFG,F_OK) != -1)
  14641. {
  14642. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14643. rename(ROOTCA_MFG, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14644. rename(tempCert, ROOTCA_MFG);
  14645. }
  14646. else
  14647. {
  14648. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14649. rename(tempCert, ROOTCA_MFG);
  14650. }
  14651. }
  14652. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14653. }
  14654. sendInstallCertificateConfirmation(uuid);
  14655. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14656. {
  14657. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14658. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14659. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14660. }
  14661. json_object_put(InstallCertificate);
  14662. return result;
  14663. }
  14664. void *SignedUpdateFirmwareProcess(void *data)
  14665. {
  14666. pthread_detach(pthread_self());
  14667. mtrace();
  14668. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14669. int port=0;
  14670. int isSuccess = 0;
  14671. char ftpbuf[1024];
  14672. char temp[1024];
  14673. char * pch;
  14674. char firmwareFileName[50];
  14675. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14676. json_object *SignedUpdateFirmware;
  14677. SignedUpdateFirmware = json_tokener_parse(data);
  14678. if(!is_error(SignedUpdateFirmware))
  14679. {
  14680. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14681. {
  14682. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14683. }
  14684. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14685. {
  14686. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14687. }
  14688. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14689. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14690. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14691. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14692. {
  14693. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14694. }
  14695. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14696. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14697. }
  14698. json_object_put(SignedUpdateFirmware);
  14699. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14700. memset(path, 0, ARRAY_SIZE(path));
  14701. // Wait retrieveData
  14702. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14703. {
  14704. do
  14705. {
  14706. sleep(1);
  14707. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14708. }
  14709. // Ready to download
  14710. system("rm -f /mnt/*");
  14711. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14712. {
  14713. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14714. sprintf(ftppath,"/%s", path);
  14715. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14716. DEBUG_INFO("protocol: %s\n",protocol);
  14717. DEBUG_INFO("host: %s\n",host);
  14718. DEBUG_INFO("path: %s\n",path);
  14719. DEBUG_INFO("ftppath: %s\n",ftppath);
  14720. int ftppathlen=strlen(ftppath);
  14721. int i=1;
  14722. while(i < ftppathlen)
  14723. {
  14724. int len=ftppathlen-i;
  14725. if(ftppath[len]== 47) // '/' ascll code: 47
  14726. {
  14727. DEBUG_INFO("compare '/' all right\n");
  14728. break;
  14729. }
  14730. i=i+1;
  14731. }
  14732. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14733. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14734. firmwareFileName[i+1] = 0;
  14735. do
  14736. {
  14737. sleep(1);
  14738. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14739. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14740. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14741. sleep(1);
  14742. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14743. if(!isSuccess)
  14744. {
  14745. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14746. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14747. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14748. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14749. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14750. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14751. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14752. }
  14753. else
  14754. {
  14755. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14756. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14757. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14758. }
  14759. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14760. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14761. }
  14762. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14763. {
  14764. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14765. memset(temp, 0, ARRAY_SIZE(temp));
  14766. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14767. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14768. int ftppathlen=strlen(ftpbuf);
  14769. int i=1;
  14770. while(i < ftppathlen)
  14771. {
  14772. int len=ftppathlen-i;
  14773. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14774. {
  14775. DEBUG_INFO(" compare '/' all right\n");
  14776. break;
  14777. }
  14778. i=i+1;
  14779. }
  14780. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14781. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14782. firmwareFileName[i+1] = 0;
  14783. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14784. pch=strchr(temp,'@');
  14785. if(pch==NULL)
  14786. {
  14787. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14788. protocol, host, &port, path);
  14789. strcpy(user,"anonymous");
  14790. strcpy(password,"");
  14791. }
  14792. else
  14793. {
  14794. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14795. protocol, user, host, &port, path);
  14796. }
  14797. sscanf(host,"%[^/]%s",host1, path1);
  14798. sprintf(ftppath,"%s:/%s", host,path);
  14799. if(port == 0)
  14800. {
  14801. port = 21;
  14802. }
  14803. do
  14804. {
  14805. sleep(1);
  14806. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14807. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14808. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14809. sleep(1);
  14810. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14811. if(!isSuccess)
  14812. {
  14813. sleep(1);
  14814. DEBUG_INFO("Update firmware request and download file fail.\n");
  14815. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14816. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14817. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14818. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14819. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14820. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14821. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14822. }
  14823. else
  14824. {
  14825. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14826. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14827. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14828. }
  14829. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14830. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14831. }
  14832. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14833. {
  14834. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14835. memset(temp, 0, ARRAY_SIZE(temp));
  14836. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14837. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14838. int ftppathlen=strlen(ftpbuf);
  14839. int i=1;
  14840. while(i < ftppathlen)
  14841. {
  14842. int len=ftppathlen-i;
  14843. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14844. {
  14845. DEBUG_INFO(" compare '/' all right\n");
  14846. break;
  14847. }
  14848. i=i+1;
  14849. }
  14850. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14851. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14852. firmwareFileName[i+1] = 0;
  14853. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14854. pch=strchr(temp,'@');
  14855. if(pch==NULL)
  14856. {
  14857. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14858. protocol, host, &port, path);
  14859. strcpy(user,"anonymous");
  14860. strcpy(password,"");
  14861. }
  14862. else
  14863. {
  14864. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14865. protocol, user, password, host, &port, path);
  14866. }
  14867. sscanf(host,"%[^/]%s",host1, path1);
  14868. sprintf(ftppath,"%s", path1);
  14869. //DEBUG_INFO("protocol =%s\n",protocol);
  14870. //DEBUG_INFO("user =%s\n",user);
  14871. //DEBUG_INFO("password =%s\n",password);
  14872. //DEBUG_INFO("host1 =%s\n",host1);
  14873. //DEBUG_INFO("port =%d\n",port);
  14874. //DEBUG_INFO("path1 =%s\n",path1);
  14875. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14876. //ftpFile(host, user, password, port, ftppath, fname);
  14877. //download firmware pthred
  14878. if(port == 0)
  14879. {
  14880. port = 21;
  14881. }
  14882. do
  14883. {
  14884. sleep(1);
  14885. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14886. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14887. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14888. sleep(1);
  14889. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14890. if(!isSuccess)
  14891. {
  14892. //BulldogUtil.sleepMs(interval*1000);
  14893. DEBUG_INFO("Update firmware request and download file fail.\n");
  14894. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14895. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14896. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14897. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14898. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14899. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14900. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14901. }
  14902. else
  14903. {
  14904. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14905. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14906. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14907. }
  14908. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14909. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14910. }
  14911. else
  14912. {
  14913. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14914. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14915. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14916. sleep(1);
  14917. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14918. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14919. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14920. }
  14921. // Verify firmware image signature
  14922. struct stat st;
  14923. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  14924. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  14925. fclose(fp);
  14926. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  14927. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  14928. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  14929. fclose(fp);
  14930. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  14931. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  14932. if(st.st_size == 0)
  14933. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  14934. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  14935. {
  14936. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  14937. fp = popen(temp, "r");
  14938. if(fp)
  14939. {
  14940. while(fgets(temp, sizeof(temp), fp) != NULL)
  14941. {
  14942. if(strstr(temp, "Verified OK") != NULL)
  14943. {
  14944. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14945. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  14946. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14947. }
  14948. else
  14949. {
  14950. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14951. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  14952. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14953. sleep(1);
  14954. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14955. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  14956. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14957. sleep(1);
  14958. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14959. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14960. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14961. }
  14962. break;
  14963. }
  14964. }
  14965. pclose(fp);
  14966. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  14967. }
  14968. interLock.isUpdateFirmwareGoing = 0;
  14969. pthread_exit(NULL);
  14970. }
  14971. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  14972. {
  14973. mtrace();
  14974. int result = PASS;
  14975. pthread_t t;
  14976. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  14977. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  14978. sendSignedUpdateFirmwareConfirmation(uuid);
  14979. if(!interLock.isUpdateFirmwareGoing)
  14980. {
  14981. interLock.isUpdateFirmwareGoing = 1;
  14982. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  14983. sleep(1);
  14984. }
  14985. else
  14986. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  14987. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  14988. return result;
  14989. }
  14990. int handleUnknownRequest(char *uuid, char *payload)
  14991. {
  14992. mtrace();
  14993. int result = PASS;
  14994. DEBUG_INFO("handleUnknownRequest...\n");
  14995. sendUnknownConfirmation(uuid);
  14996. return result;
  14997. }
  14998. //==========================================
  14999. // Handle server response routine
  15000. //==========================================
  15001. void handleAuthorizeResponse(char *payload, int gun_index)
  15002. {
  15003. mtrace();
  15004. char expiryDatestr[36]={0};
  15005. char parentIdTagstr[21]={0};
  15006. char statusstr[20]={0};
  15007. int expiryDateISNULL=FALSE;
  15008. int parentIdTagISNULL=FALSE;
  15009. DEBUG_INFO("handleAuthorizeResponse...\n");
  15010. json_object *Authorize;
  15011. Authorize = json_tokener_parse(payload);
  15012. if(!is_error(Authorize))
  15013. {
  15014. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15015. {
  15016. // Required data
  15017. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15018. // Optional data
  15019. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15020. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15021. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15022. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15023. }
  15024. }
  15025. json_object_put(Authorize);
  15026. if(expiryDateISNULL == FALSE)
  15027. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15028. if(parentIdTagISNULL == FALSE)
  15029. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15030. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15031. //Update idTag information to authorization cache if supproted
  15032. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15033. {
  15034. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15035. }
  15036. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15037. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15038. authorizeRetryTimes = 0;
  15039. }
  15040. void handleBootNotificationResponse(char *payload, int gun_index)
  15041. {
  15042. mtrace();
  15043. char statusStr[12]={0};
  15044. char currentTimeStr[30]={0};
  15045. int intervalInt = 0;
  15046. DEBUG_INFO("handleBootNotificationResponse...\n");
  15047. json_object *BootNotification;
  15048. BootNotification = json_tokener_parse(payload);
  15049. if(!is_error(BootNotification))
  15050. {
  15051. // Required data
  15052. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15053. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15054. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15055. }
  15056. json_object_put(BootNotification);
  15057. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15058. BootNotificationInterval = intervalInt;
  15059. //write back to ShmOCPP16Data->BootNotification
  15060. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15061. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15062. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15063. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15064. {
  15065. BootNotificationInterval = 0;
  15066. if((intervalInt == 0) || (intervalInt >= 10))
  15067. {
  15068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15069. HeartBeatWaitTime = intervalInt;
  15070. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15071. }
  15072. server_sign = TRUE;
  15073. server_pending =FALSE;
  15074. }
  15075. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15076. {
  15077. server_pending = TRUE;
  15078. }
  15079. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15080. srand(time(NULL));
  15081. refreshStartTimer(&clientTime.Heartbeat);
  15082. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15083. SetOcppConnStatus(TRUE);
  15084. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15085. }
  15086. void handleDataTransferResponse(char *payload, int gun_index)
  15087. {
  15088. json_object *DataTransfer = json_tokener_parse(payload);
  15089. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15090. if(!is_error(DataTransfer))
  15091. {
  15092. // Required data
  15093. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15094. // Optional data
  15095. if(json_object_object_get(DataTransfer, "data") != NULL)
  15096. {
  15097. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15098. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15099. if(!is_error(Data))
  15100. {
  15101. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15102. {
  15103. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15104. {
  15105. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15106. }
  15107. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15108. {
  15109. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15110. {
  15111. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status")));
  15112. }
  15113. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15114. {
  15115. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime")));
  15116. }
  15117. }
  15118. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15119. }
  15120. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15121. {
  15122. if(json_object_object_get(Data, "status") != NULL)
  15123. {
  15124. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15125. }
  15126. if(json_object_object_get(Data, "exiResponse") != NULL)
  15127. {
  15128. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15129. }
  15130. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15131. }
  15132. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15133. {
  15134. if(json_object_object_get(Data, "status") != NULL)
  15135. {
  15136. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15137. }
  15138. if(json_object_object_get(Data, "ocspResult") != NULL)
  15139. {
  15140. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15141. }
  15142. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15143. }
  15144. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15145. {
  15146. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15147. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15148. }
  15149. else
  15150. {
  15151. if(json_object_object_get(Data, "msgId") != NULL)
  15152. {
  15153. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15154. {
  15155. 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")));
  15156. }
  15157. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15158. {
  15159. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15160. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15161. }
  15162. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_GetOccupancyFee") != NULL)
  15163. {
  15164. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15165. {
  15166. sprintf((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15167. if(json_object_object_get(Data, "occupancySN") != NULL)
  15168. sprintf((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancySN, "%s", json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15169. if(json_object_object_get(Data, "startTime") != NULL)
  15170. sprintf((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_startTime, "%s", json_object_get_string(json_object_object_get(Data, "startTime")));
  15171. if(json_object_object_get(Data, "duration") != NULL)
  15172. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_duration = json_object_get_int(json_object_object_get(Data, "duration"));
  15173. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15174. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancyFee = json_object_get_double(json_object_object_get(Data, "occupancyFee"));
  15175. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].GetOccupancyFeeReq = 0;
  15176. }
  15177. else
  15178. {
  15179. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15180. {
  15181. if(ShmOCPP16Data->TcciCustomData.GetOccupancyFee[idx].GetOccupancyFeeReq)
  15182. {
  15183. strcpy((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[idx].response_status, "Rejected");
  15184. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[idx].GetOccupancyFeeReq = 0;
  15185. }
  15186. }
  15187. }
  15188. }
  15189. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15190. {
  15191. if(json_object_object_get(Data, "occupancySN") != NULL)
  15192. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15193. }
  15194. }
  15195. }
  15196. }
  15197. json_object_put(Data);
  15198. }
  15199. }
  15200. json_object_put(DataTransfer);
  15201. }
  15202. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15203. {
  15204. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15205. //struct json_object *obj;
  15206. // obj = json_tokener_parse(payload);
  15207. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15208. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15209. //No fields are defined.
  15210. }
  15211. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15212. {
  15213. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15214. //struct json_object *obj;
  15215. // obj = json_tokener_parse(payload);
  15216. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15217. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15218. //No fields are defined.
  15219. }
  15220. void handleHeartbeatResponse(char *payload, int gun_index)
  15221. {
  15222. mtrace();
  15223. DEBUG_INFO("handleHeartbeatResponse...\n");
  15224. json_object *Heartbeat;
  15225. Heartbeat = json_tokener_parse(payload);
  15226. if(!is_error(Heartbeat))
  15227. {
  15228. // Required data
  15229. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15230. }
  15231. json_object_put(Heartbeat);
  15232. if(FirstHeartBeat == 0)
  15233. {
  15234. FirstHeartBeat = 1;
  15235. DEBUG_INFO("FirstHeartBeat \n");
  15236. }
  15237. HeartBeatWithNOResponse = 0;
  15238. refreshStartTimer(&clientTime.Heartbeat);
  15239. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15240. }
  15241. void handleMeterValuesResponse(char *payload, int gun_index)
  15242. {
  15243. mtrace();
  15244. DEBUG_INFO("handleMeterValuesResponse...\n");
  15245. isQueueSendable = 1;
  15246. }
  15247. void handleStartTransactionResponse(char *payload, int gun_index)
  15248. {
  15249. mtrace();
  15250. //int transactionIdInt = 0;
  15251. FILE *outfile;
  15252. char data[100]={0};
  15253. DEBUG_INFO("handleStartTransactionResponse...\n");
  15254. json_object *StartTransaction;
  15255. StartTransaction = json_tokener_parse(payload);
  15256. if(!is_error(StartTransaction))
  15257. {
  15258. // Required data
  15259. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15260. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15261. // Optional data
  15262. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15263. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15264. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15265. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15266. }
  15267. json_object_put(StartTransaction);
  15268. OCPP_updatePeriodEnergy(gun_index);
  15269. //-----------Start : write to the Queue TransactionId file -----------------//
  15270. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15271. {}
  15272. else
  15273. {
  15274. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15275. if(log == NULL)
  15276. {
  15277. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15278. return ;
  15279. }
  15280. else
  15281. {
  15282. fclose(log);
  15283. }
  15284. }
  15285. // open file for writing
  15286. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15287. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15288. {
  15289. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15290. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15291. fputs(data, outfile);
  15292. fclose (outfile);
  15293. }
  15294. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15295. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15296. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15297. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15298. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15299. isQueueSendable = 1;
  15300. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15301. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15302. }
  15303. void handleStatusNotificationResponse(char *payload, int gun_index)
  15304. {
  15305. mtrace();
  15306. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15307. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15308. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15309. if(gun_index != 99)
  15310. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15311. }
  15312. void handleStopTransactionnResponse(char *payload, int gun_index)
  15313. {
  15314. mtrace();
  15315. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15316. json_object *StopTransaction;
  15317. StopTransaction = json_tokener_parse(payload);
  15318. if(!is_error(StopTransaction))
  15319. {
  15320. // Optional data
  15321. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15322. {
  15323. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15324. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15325. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15326. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15327. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15328. }
  15329. }
  15330. json_object_put(StopTransaction);
  15331. isQueueSendable = 1;
  15332. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15333. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15334. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15335. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15336. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15337. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15338. }
  15339. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15340. {
  15341. mtrace();
  15342. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15343. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15344. }
  15345. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15346. {
  15347. mtrace();
  15348. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15349. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15350. }
  15351. void handleSignCertificateResponse(char *payload, int gun_index)
  15352. {
  15353. mtrace();
  15354. DEBUG_INFO("handleSignCertificateResponse...\n");
  15355. json_object *SignCertificate;
  15356. SignCertificate = json_tokener_parse(payload);
  15357. if(!is_error(SignCertificate))
  15358. {
  15359. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15360. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15361. }
  15362. json_object_put(SignCertificate);
  15363. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15364. }
  15365. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15366. {
  15367. mtrace();
  15368. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15369. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15370. }
  15371. //==========================================
  15372. // Handle Error routine
  15373. //==========================================
  15374. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15375. {
  15376. mtrace();
  15377. #ifdef SystemLogMessage
  15378. DEBUG_INFO("errorCode: %s\n", errorCode);
  15379. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15380. DEBUG_INFO("errorDetails: %s\n", payload);
  15381. #endif
  15382. }
  15383. //===============================================
  15384. // Common routine
  15385. //===============================================
  15386. int initialConfigurationTable(void)
  15387. {
  15388. //clock_t start_t, end_t, total_t;
  15389. FILE *fp;
  15390. FILE *outfile;
  15391. char str[512]={0};
  15392. char sstr[256]={0};
  15393. int c = 0;
  15394. char *loc;
  15395. int confVersion = 22;
  15396. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15397. //start_t = clock();
  15398. //printf("Starting of the program, start_t = %ld\n", start_t);
  15399. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15400. // Check configuration file size is correct
  15401. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15402. {
  15403. struct stat st;
  15404. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15405. if(st.st_size < 3100)
  15406. {
  15407. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15408. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15409. }
  15410. }
  15411. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15412. {
  15413. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15414. if(outfile == NULL)
  15415. {
  15416. DEBUG_INFO("Error opening file\n");
  15417. return FALSE;
  15418. }
  15419. /*Core Profile*/
  15420. //AllowOfflineTxForUnknownId
  15421. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15425. //AuthorizationCacheEnabled
  15426. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15430. //AuthorizeRemoteTxRequests
  15431. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15435. //BlinkRepeat
  15436. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15440. //ClockAlignedDataInterval
  15441. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15445. //ConnectionTimeOut
  15446. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15448. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15450. else
  15451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15453. //GetConfigurationMaxKeys
  15454. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15456. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15458. // HeartbeatInterval
  15459. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15463. // LightIntensity
  15464. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15468. // LocalAuthorizeOffline
  15469. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15473. // LocalPreAuthorize
  15474. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15478. // MaxEnergyOnInvalidId
  15479. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15483. // MeterValuesAlignedData
  15484. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15487. 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" );
  15488. else
  15489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15491. // MeterValuesAlignedDataMaxLength
  15492. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15494. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15496. else
  15497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15499. // MeterValuesSampledData
  15500. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15503. 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" );
  15504. else
  15505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15507. // MeterValuesSampledDataMaxLength
  15508. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15510. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15512. else
  15513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15515. // MeterValueSampleInterval
  15516. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15520. // MinimumStatusDuration
  15521. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15524. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15526. // NumberOfConnectors
  15527. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15530. {
  15531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15532. }
  15533. else
  15534. {
  15535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15536. }
  15537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15538. // ResetRetries
  15539. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15543. // ConnectorPhaseRotation
  15544. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15548. // ConnectorPhaseRotationMaxLength
  15549. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15553. // StopTransactionOnEVSideDisconnect
  15554. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15558. // StopTransactionOnInvalidId
  15559. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15563. // StopTxnAlignedData
  15564. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15568. // StopTxnAlignedDataMaxLength
  15569. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15571. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15572. {
  15573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 7);
  15574. }
  15575. else
  15576. {
  15577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 9);
  15578. }
  15579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15580. // StopTxnSampledData
  15581. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15585. // StopTxnSampledDataMaxLength
  15586. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15588. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15589. {
  15590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  15591. }
  15592. else
  15593. {
  15594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  15595. }
  15596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15597. // SupportedFeatureProfiles
  15598. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15602. // SupportedFeatureProfilesMaxLength
  15603. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15607. // TransactionMessageAttempts
  15608. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15611. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15613. // TransactionMessageRetryInterval
  15614. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15617. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15619. // UnlockConnectorOnEVSideDisconnect
  15620. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15624. // WebSocketPingInterval
  15625. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15629. // QueueOffLineMeterValues
  15630. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15634. // AuthorizationKey
  15635. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15639. // SecurityProfile
  15640. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15644. // DefaultPrice
  15645. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15649. // CustomDisplayCostAndPrice
  15650. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15654. // CustomIdleFeeAfterStop
  15655. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15659. // TimeOffset
  15660. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15664. // NextTimeOffsetTransitionDateTime
  15665. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15669. // TimeOffsetNextTransition
  15670. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15674. // SystemUptimeSec
  15675. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15679. // FreeVend
  15680. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15684. // FreeVendIdtag
  15685. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15689. // OcppServer
  15690. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15692. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15694. // MaintainServer
  15695. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15697. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15699. // StatusNotificationPeriodically
  15700. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15704. // StatusNotificationInterval
  15705. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15709. // PreAuthAmount
  15710. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15714. // isEnableLocalPowerSharing
  15715. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15719. // PowerSharingServerIP
  15720. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15722. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15724. // EVCCID_PREFIX
  15725. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15729. // OffLineMaxChargingPower
  15730. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15734. // Configuration Version
  15735. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15739. // Charging profile refresh interval
  15740. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15744. // CpoName
  15745. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15749. // Ocpp Software certificated version
  15750. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15754. //* Local Auth List Management Profile*/
  15755. #if 0
  15756. //For OCTT Test Case
  15757. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15760. #endif
  15761. #if 1
  15762. //LocalAuthListEnabled
  15763. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15767. #endif
  15768. //LocalAuthListMaxLength
  15769. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15773. //SendLocalListMaxLength
  15774. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15778. //ReserveConnectorZeroSupported
  15779. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15783. //* Smart Charging Profile */
  15784. //ChargeProfileMaxStackLevel
  15785. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15789. // ChargingScheduleAllowedChargingRateUnit
  15790. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15794. // ChargingScheduleMaxPeriods
  15795. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15799. // ConnectorSwitch3to1PhaseSupported
  15800. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15804. // MaxChargingProfilesInstalled
  15805. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15809. fclose(outfile);
  15810. }
  15811. else
  15812. {
  15813. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15814. char keystr[60]={0};
  15815. char readonlystr[10]={0};
  15816. char valuestr[256]={0};
  15817. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15818. if(fp == NULL) {
  15819. DEBUG_INFO("Error opening file");
  15820. return FALSE;
  15821. }
  15822. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15823. {
  15824. //DEBUG_INFO("Get Configuration \n");
  15825. if(strlen(str) > 0)
  15826. {
  15827. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15828. //*************************key*********************************/
  15829. if(strstr(str, "key") != NULL)
  15830. {
  15831. loc = strstr(str, "key");
  15832. c = 0;
  15833. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15834. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15835. {
  15836. sstr[c] = loc[strlen("key")+3+c];
  15837. c++;
  15838. }
  15839. sstr[c] = '\0';
  15840. strcpy(keystr,sstr);
  15841. }
  15842. //*************************readonly*********************************/
  15843. if(strstr(str, "readonly") != NULL)
  15844. {
  15845. loc = strstr(str, "readonly");
  15846. c = 0;
  15847. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15848. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  15849. {
  15850. sstr[c] = loc[strlen("readonly")+2+c];
  15851. c++;
  15852. }
  15853. sstr[c] = '\0';
  15854. strcpy(readonlystr,sstr);
  15855. }
  15856. //*************************value*********************************/
  15857. if(strstr(str, "value") != NULL)
  15858. {
  15859. loc = strstr(str, "value");
  15860. c = 0;
  15861. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15862. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15863. {
  15864. sstr[c] = loc[strlen("value")+3+c];
  15865. c++;
  15866. }
  15867. sstr[c] = '\0';
  15868. strcpy(valuestr,sstr);
  15869. }
  15870. // DEBUG_INFO("keystr=%s\n",keystr);
  15871. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15872. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15873. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15874. {
  15875. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15876. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15878. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15879. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15880. }
  15881. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15882. {
  15883. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15884. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  15886. }
  15887. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  15888. {
  15889. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  15891. }
  15892. if(strcmp(keystr, "BlinkRepeat") == 0)
  15893. {
  15894. //Charger.BlinkRepeat = Integer.parseInt(value);
  15895. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  15897. }
  15898. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  15899. {
  15900. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  15902. }
  15903. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  15904. {
  15905. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  15907. }
  15908. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  15909. {
  15910. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  15912. }
  15913. if(strcmp(keystr, "HeartbeatInterval") == 0)
  15914. {
  15915. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  15917. HeartBeatWaitTime = atoi(valuestr);
  15918. }
  15919. if(strcmp(keystr, "LightIntensity") == 0)
  15920. {
  15921. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  15923. }
  15924. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  15925. {
  15926. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  15928. }
  15929. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  15930. {
  15931. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  15933. }
  15934. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  15935. {
  15936. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  15938. }
  15939. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  15940. {
  15941. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  15943. }
  15944. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  15945. {
  15946. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  15948. }
  15949. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  15950. {
  15951. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15952. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  15953. }
  15954. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  15955. {
  15956. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  15958. }
  15959. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  15960. {
  15961. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15962. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  15963. }
  15964. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  15965. {
  15966. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  15968. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  15969. }
  15970. if(strcmp(keystr, "NumberOfConnectors") == 0)
  15971. {
  15972. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  15974. }
  15975. if(strcmp(keystr, "ResetRetries") == 0)
  15976. {
  15977. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  15979. }
  15980. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  15981. {
  15982. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  15984. }
  15985. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  15986. {
  15987. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  15989. }
  15990. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  15991. {
  15992. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  15994. }
  15995. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  15996. {
  15997. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  15999. }
  16000. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16001. {
  16002. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16004. }
  16005. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16006. {
  16007. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16009. }
  16010. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16011. {
  16012. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16014. }
  16015. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16016. {
  16017. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16019. }
  16020. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16021. {
  16022. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16024. }
  16025. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16026. {
  16027. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16029. }
  16030. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16031. {
  16032. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16034. TransactionMessageAttemptsValue = atoi(valuestr);
  16035. }
  16036. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16037. {
  16038. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16040. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16041. }
  16042. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16043. {
  16044. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16046. }
  16047. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16048. {
  16049. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16051. }
  16052. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16053. {
  16054. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16056. }
  16057. if(strcmp(keystr, "AuthorizationKey") == 0)
  16058. {
  16059. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16060. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16062. }
  16063. if(strcmp(keystr, "SecurityProfile") == 0)
  16064. {
  16065. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16067. }
  16068. if(strcmp(keystr, "DefaultPrice") == 0)
  16069. {
  16070. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16072. }
  16073. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16074. {
  16075. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16077. }
  16078. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16079. {
  16080. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16082. }
  16083. if(strcmp(keystr, "TimeOffset") == 0)
  16084. {
  16085. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16087. }
  16088. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16089. {
  16090. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16092. }
  16093. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16094. {
  16095. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16097. }
  16098. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16099. {
  16100. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16101. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16102. }
  16103. if(strcmp(keystr, "FreeVend") == 0)
  16104. {
  16105. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16107. }
  16108. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16109. {
  16110. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16112. }
  16113. if(strcmp(keystr, "OcppServer") == 0)
  16114. {
  16115. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16116. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16117. }
  16118. if(strcmp(keystr, "MaintainServer") == 0)
  16119. {
  16120. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16121. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16122. }
  16123. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16124. {
  16125. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16127. }
  16128. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16129. {
  16130. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16132. }
  16133. if(strcmp(keystr, "PreAuthAmount") == 0)
  16134. {
  16135. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16137. }
  16138. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16139. {
  16140. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16142. }
  16143. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16144. {
  16145. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16146. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16147. }
  16148. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16149. {
  16150. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16152. }
  16153. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16154. {
  16155. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16157. }
  16158. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16159. {
  16160. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16162. }
  16163. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16164. {
  16165. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16167. }
  16168. if(strcmp(keystr, "CpoName") == 0)
  16169. {
  16170. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16172. }
  16173. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16174. {
  16175. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16177. }
  16178. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16179. {
  16180. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16182. }
  16183. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16184. {
  16185. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16187. }
  16188. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16189. {
  16190. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16192. }
  16193. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16194. {
  16195. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16197. }
  16198. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16199. {
  16200. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16202. }
  16203. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16204. {
  16205. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16207. }
  16208. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16209. {
  16210. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16212. }
  16213. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16214. {
  16215. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16217. }
  16218. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16219. {
  16220. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16222. }
  16223. }
  16224. }
  16225. fclose(fp);
  16226. }
  16227. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16228. {
  16229. return PASS;
  16230. }
  16231. else
  16232. {
  16233. return FAIL;
  16234. }
  16235. }
  16236. void StoreConfigurationTable(void)
  16237. {
  16238. FILE *outfile;
  16239. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16240. if(outfile == NULL)
  16241. {
  16242. DEBUG_INFO("Error opening file");
  16243. return ;
  16244. }
  16245. /*Core Profile*/
  16246. //AllowOfflineTxForUnknownId
  16247. /*
  16248. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16249. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16252. */
  16253. //DEBUG_INFO("data=%s\n",data);
  16254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16255. //AuthorizationCacheEnabled
  16256. /*
  16257. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16260. */
  16261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16262. //AuthorizeRemoteTxRequests
  16263. /*
  16264. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16267. */
  16268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16269. //BlinkRepeat
  16270. /*
  16271. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16274. */
  16275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16276. //ClockAlignedDataInterval
  16277. /*
  16278. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16281. */
  16282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16283. //ConnectionTimeOut
  16284. /*
  16285. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16288. */
  16289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16290. //GetConfigurationMaxKeys
  16291. /*
  16292. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16295. */
  16296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16297. // HeartbeatInterval
  16298. /*
  16299. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16302. */
  16303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16304. // LightIntensity
  16305. /*
  16306. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16309. */
  16310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16311. // LocalAuthorizeOffline
  16312. /*
  16313. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16316. */
  16317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16318. // LocalPreAuthorize
  16319. /*
  16320. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16323. */
  16324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16325. // MaxEnergyOnInvalidId
  16326. /*
  16327. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16330. */
  16331. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16333. // MeterValuesAlignedData
  16334. /*
  16335. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16338. */
  16339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16340. // MeterValuesAlignedDataMaxLength
  16341. /*
  16342. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16345. */
  16346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16347. // MeterValuesSampledData
  16348. /*
  16349. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16352. */
  16353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16354. // MeterValuesSampledDataMaxLength
  16355. /*
  16356. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16359. */
  16360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16361. // MeterValueSampleInterval
  16362. /*
  16363. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16366. */
  16367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16368. // MinimumStatusDuration
  16369. /*
  16370. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16373. */
  16374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16375. // NumberOfConnectors
  16376. /*
  16377. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16380. {
  16381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16382. }
  16383. else
  16384. {
  16385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16386. }
  16387. */
  16388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16389. // ResetRetries
  16390. /*
  16391. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16394. */
  16395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16396. // ConnectorPhaseRotation
  16397. /*
  16398. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16401. */
  16402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16403. // ConnectorPhaseRotationMaxLength
  16404. /*
  16405. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16408. */
  16409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16410. // StopTransactionOnEVSideDisconnect
  16411. /*
  16412. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16415. */
  16416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16417. // StopTransactionOnInvalidId
  16418. /*
  16419. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16422. */
  16423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16424. // StopTxnAlignedData
  16425. /*
  16426. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16429. */
  16430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16431. // StopTxnAlignedDataMaxLength
  16432. /*
  16433. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16436. */
  16437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16438. // StopTxnSampledData
  16439. /*
  16440. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16443. */
  16444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16445. // StopTxnSampledDataMaxLength
  16446. /*
  16447. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16450. */
  16451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16452. // SupportedFeatureProfiles
  16453. /*
  16454. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16457. */
  16458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16459. // SupportedFeatureProfilesMaxLength
  16460. /*
  16461. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16464. */
  16465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16466. // TransactionMessageAttempts
  16467. /*
  16468. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16471. */
  16472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16473. // TransactionMessageRetryInterval
  16474. /*
  16475. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16478. */
  16479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16480. // UnlockConnectorOnEVSideDisconnect
  16481. /*
  16482. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16485. */
  16486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16487. // WebSocketPingInterval
  16488. /*
  16489. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16492. */
  16493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16494. // QueueOffLineMeterValues
  16495. /*
  16496. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16499. */
  16500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16501. // AuthorizationKey
  16502. /*
  16503. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16506. */
  16507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16508. // SecurityProfile
  16509. /*
  16510. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16513. */
  16514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16515. // DefaultPrice
  16516. /*
  16517. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16520. */
  16521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16522. // CustomDisplayCostAndPrice
  16523. /*
  16524. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16527. */
  16528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16529. // CustomIdleFeeAfterStop
  16530. /*
  16531. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16534. */
  16535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16536. // TimeOffset
  16537. /*
  16538. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16541. */
  16542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16543. // NextTimeOffsetTransitionDateTime
  16544. /*
  16545. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16548. */
  16549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16550. // TimeOffsetNextTransition
  16551. /*
  16552. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16555. */
  16556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16557. // SystemUptimeSec
  16558. /*
  16559. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16562. */
  16563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16564. // FreeVend
  16565. /*
  16566. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16569. */
  16570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16571. // FreeVendIdtag
  16572. /*
  16573. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16576. */
  16577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16578. // OcppServer
  16579. /*
  16580. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16583. */
  16584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16585. // MaintainServer
  16586. /*
  16587. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16590. */
  16591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16592. // StatusNotificationPeriodically
  16593. /*
  16594. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16597. */
  16598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16599. // StatusNotificationInterval
  16600. /*
  16601. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16604. */
  16605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16606. // PreAuthAmount
  16607. /*
  16608. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16611. */
  16612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16613. // isEnableLocalPowerSharing
  16614. /*
  16615. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16618. */
  16619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16620. // PowerSharingServerIP
  16621. /*
  16622. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16625. */
  16626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16627. // EVCCID_PREFIX
  16628. /*
  16629. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16632. */
  16633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16634. // OffLineMaxChargingPower
  16635. /*
  16636. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16639. */
  16640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16641. // ConfigurationVersion
  16642. /*
  16643. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16646. */
  16647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16648. // CharingProfileRefreshInterval
  16649. /*
  16650. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16653. */
  16654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16655. // CpoName
  16656. /*
  16657. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16660. */
  16661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16662. // OcppSoftwareVersion
  16663. /*
  16664. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16667. */
  16668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16669. //* Local Auth List Management Profile*/
  16670. //LocalAuthListEnabled
  16671. /*
  16672. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16675. */
  16676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16677. //LocalAuthListMaxLength
  16678. /*
  16679. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16682. */
  16683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16684. //SendLocalListMaxLength
  16685. /*
  16686. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16689. */
  16690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16691. //ReserveConnectorZeroSupported
  16692. /*
  16693. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16696. */
  16697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16698. //* Smart Charging Profile */
  16699. //ChargeProfileMaxStackLevel
  16700. /*
  16701. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16704. */
  16705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16706. // ChargingScheduleAllowedChargingRateUnit
  16707. /*
  16708. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16711. */
  16712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16713. // ChargingScheduleMaxPeriods
  16714. /*
  16715. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16718. */
  16719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16720. // ConnectorSwitch3to1PhaseSupported
  16721. /*
  16722. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16725. */
  16726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16727. // MaxChargingProfilesInstalled
  16728. /*
  16729. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16732. */
  16733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16734. fclose(outfile);
  16735. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16736. }
  16737. void getKeyValue(char *keyReq)
  16738. {
  16739. int isEmpty = FALSE;
  16740. int isKnowKey = FALSE;
  16741. DEBUG_INFO("keyReq = %s\n", keyReq);
  16742. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16743. isEmpty = TRUE;
  16744. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16745. {
  16746. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16748. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16749. {
  16750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16751. }
  16752. else
  16753. {
  16754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16755. }
  16756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16757. isKnowKey = TRUE;
  16758. }
  16759. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16760. {
  16761. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16763. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16764. {
  16765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16766. }
  16767. else
  16768. {
  16769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16770. }
  16771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16772. isKnowKey = TRUE;
  16773. }
  16774. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16775. {
  16776. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16778. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16779. {
  16780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16781. }
  16782. else
  16783. {
  16784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16785. }
  16786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16787. isKnowKey = TRUE;
  16788. }
  16789. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16790. {
  16791. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16794. {
  16795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16796. }
  16797. else
  16798. {
  16799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16800. }
  16801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16802. isKnowKey = TRUE;
  16803. }
  16804. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16805. {
  16806. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16809. {
  16810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16811. }
  16812. else
  16813. {
  16814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16815. }
  16816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16817. isKnowKey = TRUE;
  16818. }
  16819. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16820. {
  16821. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16824. {
  16825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  16826. }
  16827. else
  16828. {
  16829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  16830. }
  16831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  16832. isKnowKey = TRUE;
  16833. }
  16834. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  16835. {
  16836. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  16837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  16838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16839. {
  16840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  16841. }
  16842. else
  16843. {
  16844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  16845. }
  16846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  16847. isKnowKey = TRUE;
  16848. }
  16849. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  16850. {
  16851. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  16852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  16853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16854. {
  16855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  16856. }
  16857. else
  16858. {
  16859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  16860. }
  16861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  16862. isKnowKey = TRUE;
  16863. }
  16864. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  16865. {
  16866. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  16867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  16868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16869. {
  16870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  16871. }
  16872. else
  16873. {
  16874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  16875. }
  16876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  16877. isKnowKey = TRUE;
  16878. }
  16879. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  16880. {
  16881. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  16882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  16883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16884. {
  16885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  16886. }
  16887. else
  16888. {
  16889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  16890. }
  16891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  16892. isKnowKey = TRUE;
  16893. }
  16894. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  16895. {
  16896. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  16897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  16898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16899. {
  16900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  16901. }
  16902. else
  16903. {
  16904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  16905. }
  16906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  16907. isKnowKey = TRUE;
  16908. }
  16909. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  16910. {
  16911. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  16912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  16913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16914. {
  16915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  16916. }
  16917. else
  16918. {
  16919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  16920. }
  16921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  16922. isKnowKey = TRUE;
  16923. }
  16924. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  16925. {
  16926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  16927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  16928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16929. {
  16930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  16931. }
  16932. else
  16933. {
  16934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  16935. }
  16936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  16937. isKnowKey = TRUE;
  16938. }
  16939. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  16940. {
  16941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  16942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  16943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16944. {
  16945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16946. }
  16947. else
  16948. {
  16949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16950. }
  16951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  16952. isKnowKey = TRUE;
  16953. }
  16954. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  16955. {
  16956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  16957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  16958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16959. {
  16960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  16961. }
  16962. else
  16963. {
  16964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  16965. }
  16966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  16967. isKnowKey = TRUE;
  16968. }
  16969. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  16970. {
  16971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  16972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  16973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16974. {
  16975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16976. }
  16977. else
  16978. {
  16979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16980. }
  16981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  16982. isKnowKey = TRUE;
  16983. }
  16984. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  16985. {
  16986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  16987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  16988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16989. {
  16990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  16991. }
  16992. else
  16993. {
  16994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  16995. }
  16996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  16997. isKnowKey = TRUE;
  16998. }
  16999. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17000. {
  17001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17004. {
  17005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17006. }
  17007. else
  17008. {
  17009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17010. }
  17011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17012. isKnowKey = TRUE;
  17013. }
  17014. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17015. {
  17016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17019. {
  17020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17021. }
  17022. else
  17023. {
  17024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17025. }
  17026. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17028. isKnowKey = TRUE;
  17029. }
  17030. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17031. {
  17032. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17035. {
  17036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17037. }
  17038. else
  17039. {
  17040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17041. }
  17042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17043. isKnowKey = TRUE;
  17044. }
  17045. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17046. {
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17050. {
  17051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17052. }
  17053. else
  17054. {
  17055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17056. }
  17057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17058. isKnowKey = TRUE;
  17059. }
  17060. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17061. {
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17065. {
  17066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17067. }
  17068. else
  17069. {
  17070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17071. }
  17072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17073. isKnowKey = TRUE;
  17074. }
  17075. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17076. {
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17080. {
  17081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17082. }
  17083. else
  17084. {
  17085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17086. }
  17087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17088. isKnowKey = TRUE;
  17089. }
  17090. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17091. {
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17095. {
  17096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17097. }
  17098. else
  17099. {
  17100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17101. }
  17102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17103. isKnowKey = TRUE;
  17104. }
  17105. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17106. {
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17110. {
  17111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17112. }
  17113. else
  17114. {
  17115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17116. }
  17117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17118. isKnowKey = TRUE;
  17119. }
  17120. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17121. {
  17122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17125. {
  17126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17127. }
  17128. else
  17129. {
  17130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17131. }
  17132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17133. isKnowKey = TRUE;
  17134. }
  17135. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17136. {
  17137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17140. {
  17141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17142. }
  17143. else
  17144. {
  17145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17146. }
  17147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17148. isKnowKey = TRUE;
  17149. }
  17150. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17151. {
  17152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17155. {
  17156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17157. }
  17158. else
  17159. {
  17160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17161. }
  17162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17163. isKnowKey = TRUE;
  17164. }
  17165. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17166. {
  17167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17170. {
  17171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17172. }
  17173. else
  17174. {
  17175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17176. }
  17177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17178. isKnowKey = TRUE;
  17179. }
  17180. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17181. {
  17182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17185. {
  17186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17187. }
  17188. else
  17189. {
  17190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17191. }
  17192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17193. isKnowKey = TRUE;
  17194. }
  17195. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17196. {
  17197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17200. {
  17201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17202. }
  17203. else
  17204. {
  17205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17206. }
  17207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17208. isKnowKey = TRUE;
  17209. }
  17210. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17211. {
  17212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17215. {
  17216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17217. }
  17218. else
  17219. {
  17220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17221. }
  17222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17223. isKnowKey = TRUE;
  17224. }
  17225. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17226. {
  17227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17230. {
  17231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17232. }
  17233. else
  17234. {
  17235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17236. }
  17237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17238. isKnowKey = TRUE;
  17239. }
  17240. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17241. {
  17242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17245. {
  17246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17247. }
  17248. else
  17249. {
  17250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17251. }
  17252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17253. isKnowKey = TRUE;
  17254. }
  17255. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17256. {
  17257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17260. {
  17261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17262. }
  17263. else
  17264. {
  17265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17266. }
  17267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17268. isKnowKey = TRUE;
  17269. }
  17270. /*
  17271. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17272. {
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17276. {
  17277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17278. }
  17279. else
  17280. {
  17281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17282. }
  17283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17284. isKnowKey = TRUE;
  17285. }*/
  17286. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17287. {
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17291. {
  17292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17293. }
  17294. else
  17295. {
  17296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17297. }
  17298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17299. isKnowKey = TRUE;
  17300. }
  17301. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17302. {
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17306. {
  17307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17308. }
  17309. else
  17310. {
  17311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17312. }
  17313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17314. isKnowKey = TRUE;
  17315. }
  17316. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17317. {
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17321. {
  17322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17323. }
  17324. else
  17325. {
  17326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17327. }
  17328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17329. isKnowKey = TRUE;
  17330. }
  17331. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17332. {
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17336. {
  17337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17338. }
  17339. else
  17340. {
  17341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17342. }
  17343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17344. isKnowKey = TRUE;
  17345. }
  17346. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17347. {
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17351. {
  17352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17353. }
  17354. else
  17355. {
  17356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17357. }
  17358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17359. isKnowKey = TRUE;
  17360. }
  17361. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17362. {
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17366. {
  17367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17368. }
  17369. else
  17370. {
  17371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17372. }
  17373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17374. isKnowKey = TRUE;
  17375. }
  17376. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17377. {
  17378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17381. {
  17382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17383. }
  17384. else
  17385. {
  17386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17387. }
  17388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17389. isKnowKey = TRUE;
  17390. }
  17391. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17392. {
  17393. struct sysinfo s_info;
  17394. int error = sysinfo(&s_info);
  17395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17398. {
  17399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17400. }
  17401. else
  17402. {
  17403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17404. }
  17405. if(error != 0)
  17406. {
  17407. DEBUG_WARN("System uptime get error: %d\n", error);
  17408. }
  17409. else
  17410. {
  17411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17412. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17413. }
  17414. isKnowKey = TRUE;
  17415. }
  17416. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17417. {
  17418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17421. {
  17422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17423. }
  17424. else
  17425. {
  17426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17427. }
  17428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17429. isKnowKey = TRUE;
  17430. }
  17431. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17432. {
  17433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17436. {
  17437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17438. }
  17439. else
  17440. {
  17441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17442. }
  17443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17444. isKnowKey = TRUE;
  17445. }
  17446. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17447. {
  17448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17451. {
  17452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17453. }
  17454. else
  17455. {
  17456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17457. }
  17458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17459. isKnowKey = TRUE;
  17460. }
  17461. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17462. {
  17463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17466. {
  17467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17468. }
  17469. else
  17470. {
  17471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17472. }
  17473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17474. isKnowKey = TRUE;
  17475. }
  17476. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17477. {
  17478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17481. {
  17482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17483. }
  17484. else
  17485. {
  17486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17487. }
  17488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17489. isKnowKey = TRUE;
  17490. }
  17491. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17492. {
  17493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17496. {
  17497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17498. }
  17499. else
  17500. {
  17501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17502. }
  17503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17504. isKnowKey = TRUE;
  17505. }
  17506. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17507. {
  17508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17511. {
  17512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17513. }
  17514. else
  17515. {
  17516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17517. }
  17518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17519. isKnowKey = TRUE;
  17520. }
  17521. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17522. {
  17523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17526. {
  17527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17528. }
  17529. else
  17530. {
  17531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17532. }
  17533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17534. isKnowKey = TRUE;
  17535. }
  17536. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17537. {
  17538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17541. {
  17542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17543. }
  17544. else
  17545. {
  17546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17547. }
  17548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17549. isKnowKey = TRUE;
  17550. }
  17551. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17552. {
  17553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17556. {
  17557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17558. }
  17559. else
  17560. {
  17561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17562. }
  17563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17564. isKnowKey = TRUE;
  17565. }
  17566. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17567. {
  17568. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17571. {
  17572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17573. }
  17574. else
  17575. {
  17576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17577. }
  17578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17579. isKnowKey = TRUE;
  17580. }
  17581. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17582. {
  17583. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17586. {
  17587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17588. }
  17589. else
  17590. {
  17591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17592. }
  17593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17594. isKnowKey = TRUE;
  17595. }
  17596. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17597. {
  17598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17601. {
  17602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17603. }
  17604. else
  17605. {
  17606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17607. }
  17608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17609. isKnowKey = TRUE;
  17610. }
  17611. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17612. {
  17613. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17616. {
  17617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17618. }
  17619. else
  17620. {
  17621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17622. }
  17623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17624. isKnowKey = TRUE;
  17625. }
  17626. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17627. {
  17628. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17631. {
  17632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17633. }
  17634. else
  17635. {
  17636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17637. }
  17638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17639. isKnowKey = TRUE;
  17640. }
  17641. #if 1
  17642. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17643. {
  17644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17646. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17647. {
  17648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17649. }
  17650. else
  17651. {
  17652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17653. }
  17654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17655. isKnowKey = TRUE;
  17656. }
  17657. #endif
  17658. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17659. {
  17660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17662. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17663. {
  17664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17665. }
  17666. else
  17667. {
  17668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17669. }
  17670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17671. isKnowKey = TRUE;
  17672. }
  17673. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17674. {
  17675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17677. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17678. {
  17679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17680. }
  17681. else
  17682. {
  17683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17684. }
  17685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17686. isKnowKey = TRUE;
  17687. }
  17688. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17689. {
  17690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17692. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17693. {
  17694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17695. }
  17696. else
  17697. {
  17698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17699. }
  17700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17701. isKnowKey = TRUE;
  17702. }
  17703. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17704. {
  17705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17707. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17708. {
  17709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17710. }
  17711. else
  17712. {
  17713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17714. }
  17715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17716. isKnowKey = TRUE;
  17717. }
  17718. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17719. {
  17720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17722. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17723. {
  17724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17725. }
  17726. else
  17727. {
  17728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17729. }
  17730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17731. isKnowKey = TRUE;
  17732. }
  17733. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17734. {
  17735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17737. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17738. {
  17739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17740. }
  17741. else
  17742. {
  17743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17744. }
  17745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17746. isKnowKey = TRUE;
  17747. }
  17748. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17749. {
  17750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17752. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17753. {
  17754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17755. }
  17756. else
  17757. {
  17758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17759. }
  17760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17761. isKnowKey = TRUE;
  17762. }
  17763. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17764. {
  17765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17767. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17768. {
  17769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17770. }
  17771. else
  17772. {
  17773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17774. }
  17775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17776. isKnowKey = TRUE;
  17777. }
  17778. //=========================================================
  17779. if(!isEmpty && !isKnowKey)
  17780. {
  17781. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17782. strcpy(unknownkey[UnknownKeynum], keyReq);
  17783. UnknownKeynum = UnknownKeynum + 1;
  17784. }
  17785. }
  17786. void processUnkownKey(void)
  17787. {
  17788. DEBUG_INFO("processUnkownKey...\n");
  17789. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17790. for(int index=0; index < UnknownKeynum; index++)
  17791. {
  17792. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17793. {
  17794. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17795. }
  17796. }
  17797. }
  17798. int setKeyValue(char *key, char *value)
  17799. {
  17800. int isSuccess = NotSupported;
  17801. int check_ascii=0;
  17802. char str[501]={0};
  17803. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17804. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17805. {
  17806. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17808. {
  17809. strcpy(str, (const char*)value);
  17810. for(int i = 0; str[i]; i++){
  17811. str[i] = tolower(str[i]);
  17812. }
  17813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17814. isSuccess = ConfigurationStatus_Accepted;
  17815. }
  17816. else
  17817. {
  17818. isSuccess = ConfigurationStatus_Rejected;
  17819. }
  17820. }
  17821. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  17822. {
  17823. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  17824. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17825. {
  17826. strcpy(str, (const char*)value);
  17827. for(int i = 0; str[i]; i++){
  17828. str[i] = tolower(str[i]);
  17829. }
  17830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17831. isSuccess = ConfigurationStatus_Accepted;
  17832. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  17833. }
  17834. else
  17835. {
  17836. isSuccess = ConfigurationStatus_Rejected;
  17837. }
  17838. }
  17839. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  17840. {
  17841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17842. {
  17843. strcpy(str, (const char*)value);
  17844. for(int i = 0; str[i]; i++)
  17845. {
  17846. str[i] = tolower(str[i]);
  17847. }
  17848. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  17849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17850. isSuccess = ConfigurationStatus_Accepted;
  17851. }
  17852. else
  17853. {
  17854. isSuccess = ConfigurationStatus_Rejected;
  17855. }
  17856. }
  17857. if(strcmp(key, "BlinkRepeat") == 0)
  17858. {
  17859. //Charger.BlinkRepeat = Integer.parseInt(value);
  17860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17861. {
  17862. check_ascii = value[0];
  17863. if( (check_ascii < 48) || (check_ascii > 57) )
  17864. {
  17865. isSuccess = ConfigurationStatus_Rejected;
  17866. }
  17867. else
  17868. {
  17869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  17870. isSuccess = ConfigurationStatus_Accepted;
  17871. }
  17872. }
  17873. else
  17874. {
  17875. isSuccess = ConfigurationStatus_Rejected;
  17876. }
  17877. }
  17878. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  17879. {
  17880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17881. {
  17882. check_ascii = value[0];
  17883. if( (check_ascii < 48) || (check_ascii > 57) )
  17884. {
  17885. isSuccess = ConfigurationStatus_Rejected;
  17886. }
  17887. else
  17888. {
  17889. if((atoi(value) == 0) || (atoi(value) >= 5))
  17890. {
  17891. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  17892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  17893. isSuccess = ConfigurationStatus_Accepted;
  17894. }
  17895. else
  17896. isSuccess = ConfigurationStatus_Rejected;
  17897. }
  17898. }
  17899. else
  17900. {
  17901. isSuccess = ConfigurationStatus_Rejected;
  17902. }
  17903. }
  17904. if(strcmp(key, "ConnectionTimeOut") == 0 )
  17905. {
  17906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17907. {
  17908. check_ascii = value[0];
  17909. if( (check_ascii < 48) || (check_ascii > 57) )
  17910. {
  17911. isSuccess = ConfigurationStatus_Rejected;
  17912. }
  17913. else
  17914. {
  17915. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  17916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  17917. isSuccess = ConfigurationStatus_Accepted;
  17918. }
  17919. }
  17920. else
  17921. {
  17922. isSuccess = ConfigurationStatus_Rejected;
  17923. }
  17924. }
  17925. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  17926. {
  17927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17928. {
  17929. check_ascii = value[0];
  17930. if( (check_ascii < 48) || (check_ascii > 57) )
  17931. {
  17932. isSuccess = ConfigurationStatus_Rejected;
  17933. }
  17934. else
  17935. {
  17936. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  17937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  17938. isSuccess = ConfigurationStatus_Accepted;
  17939. }
  17940. }
  17941. else
  17942. {
  17943. isSuccess = ConfigurationStatus_Rejected;
  17944. }
  17945. }
  17946. if(strcmp(key, "HeartbeatInterval") == 0)
  17947. {
  17948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17949. {
  17950. check_ascii = value[0];
  17951. if( (check_ascii < 48) || (check_ascii > 57) )
  17952. {
  17953. isSuccess = ConfigurationStatus_Rejected;
  17954. }
  17955. else
  17956. {
  17957. if((atoi(value) == 0) || (atoi(value) >= 10))
  17958. {
  17959. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  17960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  17961. HeartBeatWaitTime = atoi(value);
  17962. isSuccess = ConfigurationStatus_Accepted;
  17963. }
  17964. else
  17965. {
  17966. isSuccess = ConfigurationStatus_Rejected;
  17967. }
  17968. }
  17969. }
  17970. else
  17971. {
  17972. isSuccess = ConfigurationStatus_Rejected;
  17973. }
  17974. }
  17975. if(strcmp(key, "LightIntensity") == 0)
  17976. {
  17977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17978. {
  17979. check_ascii = value[0];
  17980. if( (check_ascii < 48) || (check_ascii > 57) )
  17981. {
  17982. isSuccess = ConfigurationStatus_Rejected;
  17983. }
  17984. else
  17985. {
  17986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  17987. isSuccess = ConfigurationStatus_Accepted;
  17988. }
  17989. }
  17990. else
  17991. {
  17992. isSuccess = ConfigurationStatus_Rejected;
  17993. }
  17994. }
  17995. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  17996. {
  17997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17998. {
  17999. strcpy(str, (const char*)value);
  18000. for(int i = 0; str[i]; i++)
  18001. {
  18002. str[i] = tolower(str[i]);
  18003. }
  18004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18005. isSuccess = ConfigurationStatus_Accepted;
  18006. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18007. }
  18008. else
  18009. {
  18010. isSuccess = ConfigurationStatus_Rejected;
  18011. }
  18012. }
  18013. if(strcmp(key, "LocalPreAuthorize") == 0)
  18014. {
  18015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18016. {
  18017. strcpy(str, (const char*)value);
  18018. for(int i = 0; str[i]; i++)
  18019. {
  18020. str[i] = tolower(str[i]);
  18021. }
  18022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18023. isSuccess = ConfigurationStatus_Accepted;
  18024. }
  18025. else
  18026. {
  18027. isSuccess = ConfigurationStatus_Rejected;
  18028. }
  18029. }
  18030. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18031. {
  18032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18033. {
  18034. check_ascii = value[0];
  18035. if( (check_ascii < 48) || (check_ascii > 57) )
  18036. {
  18037. isSuccess = ConfigurationStatus_Rejected;
  18038. }
  18039. else
  18040. {
  18041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18042. isSuccess = ConfigurationStatus_Accepted;
  18043. }
  18044. }
  18045. else
  18046. {
  18047. isSuccess = ConfigurationStatus_Rejected;
  18048. }
  18049. }
  18050. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18051. {
  18052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18053. {
  18054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18055. isSuccess = ConfigurationStatus_Accepted;
  18056. }
  18057. else
  18058. {
  18059. isSuccess = ConfigurationStatus_Rejected;
  18060. }
  18061. }
  18062. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18063. {
  18064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18065. {
  18066. check_ascii = value[0];
  18067. if( (check_ascii < 48) || (check_ascii > 57) )
  18068. {
  18069. isSuccess = ConfigurationStatus_Rejected;
  18070. }
  18071. else
  18072. {
  18073. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18075. isSuccess = ConfigurationStatus_Accepted;
  18076. }
  18077. }
  18078. else
  18079. {
  18080. isSuccess = ConfigurationStatus_Rejected;
  18081. }
  18082. }
  18083. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18084. {
  18085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18086. {
  18087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18088. isSuccess = ConfigurationStatus_Accepted;
  18089. }
  18090. else
  18091. {
  18092. isSuccess = ConfigurationStatus_Rejected;
  18093. }
  18094. }
  18095. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18096. {
  18097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18098. {
  18099. check_ascii = value[0];
  18100. if( (check_ascii < 48) || (check_ascii > 57) )
  18101. {
  18102. isSuccess = ConfigurationStatus_Rejected;
  18103. }
  18104. else
  18105. {
  18106. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18108. isSuccess = ConfigurationStatus_Accepted;
  18109. }
  18110. }
  18111. else
  18112. {
  18113. isSuccess = ConfigurationStatus_Rejected;
  18114. }
  18115. }
  18116. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18117. {
  18118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18119. {
  18120. check_ascii = value[0];
  18121. if( (check_ascii < 48) || (check_ascii > 57) )
  18122. {
  18123. isSuccess = ConfigurationStatus_Rejected;
  18124. }
  18125. else
  18126. {
  18127. if((atoi(value) == 0) || (atoi(value) >= 3))
  18128. {
  18129. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18131. isSuccess = ConfigurationStatus_Accepted;
  18132. }
  18133. else
  18134. {
  18135. isSuccess = ConfigurationStatus_Rejected;
  18136. }
  18137. }
  18138. }
  18139. else
  18140. {
  18141. isSuccess = ConfigurationStatus_Rejected;
  18142. }
  18143. }
  18144. if(strcmp(key, "MinimumStatusDuration") == 0)
  18145. {
  18146. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18147. {
  18148. check_ascii = value[0];
  18149. if( (check_ascii < 48) || (check_ascii > 57) )
  18150. {
  18151. isSuccess = ConfigurationStatus_Rejected;
  18152. }
  18153. else
  18154. {
  18155. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18156. {
  18157. isSuccess = ConfigurationStatus_Rejected;
  18158. }
  18159. else
  18160. {
  18161. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18163. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18164. isSuccess = ConfigurationStatus_Accepted;
  18165. }
  18166. }
  18167. }
  18168. else
  18169. {
  18170. isSuccess = ConfigurationStatus_Rejected;
  18171. }
  18172. }
  18173. if(strcmp(key, "NumberOfConnectors") == 0)
  18174. {
  18175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18176. {
  18177. check_ascii = value[0];
  18178. if( (check_ascii < 48) || (check_ascii > 57) )
  18179. {
  18180. isSuccess = ConfigurationStatus_Rejected;
  18181. }
  18182. else
  18183. {
  18184. //Charger.ResetRetries = Integer.parseInt(value);
  18185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18186. isSuccess = ConfigurationStatus_Accepted;
  18187. }
  18188. }
  18189. else
  18190. {
  18191. isSuccess = ConfigurationStatus_Rejected;
  18192. }
  18193. }
  18194. if(strcmp(key, "ResetRetries") == 0)
  18195. {
  18196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18197. {
  18198. check_ascii = value[0];
  18199. if( (check_ascii < 48) || (check_ascii > 57) )
  18200. {
  18201. isSuccess = ConfigurationStatus_Rejected;
  18202. }
  18203. else
  18204. {
  18205. //Charger.ResetRetries = Integer.parseInt(value);
  18206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18207. isSuccess = ConfigurationStatus_Accepted;
  18208. }
  18209. }
  18210. else
  18211. {
  18212. isSuccess = ConfigurationStatus_Rejected;
  18213. }
  18214. }
  18215. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18216. {
  18217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18218. {
  18219. strcpy(str, (const char*)value);
  18220. for(int i = 0; str[i]; i++)
  18221. {
  18222. str[i] = tolower(str[i]);
  18223. }
  18224. if(strcmp(str, "notapplicable")== 0)
  18225. {
  18226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18227. isSuccess = ConfigurationStatus_Accepted;
  18228. }
  18229. else if(strcmp(str, "unknown")== 0)
  18230. {
  18231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18232. isSuccess = ConfigurationStatus_Accepted;
  18233. }
  18234. else if(strcmp(str, "rst")== 0)
  18235. {
  18236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18237. isSuccess = ConfigurationStatus_Accepted;
  18238. }
  18239. else if(strcmp(str, "rts")== 0)
  18240. {
  18241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18242. isSuccess = ConfigurationStatus_Accepted;
  18243. }
  18244. else if(strcmp(str, "srt")== 0)
  18245. {
  18246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18247. isSuccess = ConfigurationStatus_Accepted;
  18248. }
  18249. else if(strcmp(str, "str")== 0)
  18250. {
  18251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18252. isSuccess = ConfigurationStatus_Accepted;
  18253. }
  18254. else if(strcmp(str, "trs")== 0)
  18255. {
  18256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18257. isSuccess = ConfigurationStatus_Accepted;
  18258. }
  18259. else if(strcmp(str, "tsr")== 0)
  18260. {
  18261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18262. isSuccess = ConfigurationStatus_Accepted;
  18263. }
  18264. else
  18265. {
  18266. isSuccess = ConfigurationStatus_Rejected;
  18267. }
  18268. }
  18269. else
  18270. {
  18271. isSuccess = ConfigurationStatus_Rejected;
  18272. }
  18273. }
  18274. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18275. {
  18276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18277. {
  18278. check_ascii = value[0];
  18279. if( (check_ascii < 48) || (check_ascii > 57) )
  18280. {
  18281. isSuccess = ConfigurationStatus_Rejected;
  18282. }
  18283. else
  18284. {
  18285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18286. isSuccess = ConfigurationStatus_Accepted;
  18287. }
  18288. }
  18289. else
  18290. {
  18291. isSuccess = ConfigurationStatus_Rejected;
  18292. }
  18293. }
  18294. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18295. {
  18296. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18297. {
  18298. strcpy(str, (const char*)value);
  18299. for(int i = 0; str[i]; i++)
  18300. {
  18301. str[i] = tolower(str[i]);
  18302. }
  18303. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18305. isSuccess = ConfigurationStatus_Accepted;
  18306. }
  18307. else
  18308. {
  18309. isSuccess = ConfigurationStatus_Rejected;
  18310. }
  18311. }
  18312. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18313. {
  18314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18315. {
  18316. strcpy(str, (const char*)value);
  18317. for(int i = 0; str[i]; i++)
  18318. {
  18319. str[i] = tolower(str[i]);
  18320. }
  18321. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18323. isSuccess = ConfigurationStatus_Accepted;
  18324. }
  18325. else
  18326. {
  18327. isSuccess = ConfigurationStatus_Rejected;
  18328. }
  18329. }
  18330. if(strcmp(key, "StopTxnAlignedData") == 0)
  18331. {
  18332. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18333. {
  18334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18335. isSuccess = ConfigurationStatus_Accepted;
  18336. }
  18337. else
  18338. {
  18339. isSuccess = ConfigurationStatus_Rejected;
  18340. }
  18341. }
  18342. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18343. {
  18344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18345. {
  18346. check_ascii = value[0];
  18347. if( (check_ascii < 48) || (check_ascii > 57) )
  18348. {
  18349. isSuccess = ConfigurationStatus_Rejected;
  18350. }
  18351. else
  18352. {
  18353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18354. isSuccess = ConfigurationStatus_Accepted;
  18355. }
  18356. }
  18357. else
  18358. {
  18359. isSuccess = ConfigurationStatus_Rejected;
  18360. }
  18361. }
  18362. if(strcmp(key, "StopTxnSampledData") == 0)
  18363. {
  18364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18365. {
  18366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18367. isSuccess = ConfigurationStatus_Accepted;
  18368. }
  18369. else
  18370. {
  18371. isSuccess = ConfigurationStatus_Rejected;
  18372. }
  18373. }
  18374. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18375. {
  18376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18377. {
  18378. check_ascii = value[0];
  18379. if( (check_ascii < 48) || (check_ascii > 57) )
  18380. {
  18381. isSuccess = ConfigurationStatus_Rejected;
  18382. }
  18383. else
  18384. {
  18385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18386. isSuccess = ConfigurationStatus_Accepted;
  18387. }
  18388. }
  18389. else
  18390. {
  18391. isSuccess = ConfigurationStatus_Rejected;
  18392. }
  18393. }
  18394. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18395. {
  18396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18397. {
  18398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18399. isSuccess = ConfigurationStatus_Accepted;
  18400. }
  18401. else
  18402. {
  18403. isSuccess = ConfigurationStatus_Rejected;
  18404. }
  18405. }
  18406. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18407. {
  18408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18409. {
  18410. check_ascii = value[0];
  18411. if( (check_ascii < 48) || (check_ascii > 57) )
  18412. {
  18413. isSuccess = ConfigurationStatus_Rejected;
  18414. }
  18415. else
  18416. {
  18417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18418. isSuccess = ConfigurationStatus_Accepted;
  18419. }
  18420. }
  18421. else
  18422. {
  18423. isSuccess = ConfigurationStatus_Rejected;
  18424. }
  18425. }
  18426. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18427. {
  18428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18429. {
  18430. check_ascii = value[0];
  18431. if( (check_ascii < 48) || (check_ascii > 57) )
  18432. {
  18433. isSuccess = ConfigurationStatus_Rejected;
  18434. }
  18435. else
  18436. {
  18437. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18439. TransactionMessageAttemptsValue = atoi(value);
  18440. isSuccess = ConfigurationStatus_Accepted;
  18441. }
  18442. }
  18443. else
  18444. {
  18445. isSuccess = ConfigurationStatus_Rejected;
  18446. }
  18447. }
  18448. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18449. {
  18450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18451. {
  18452. check_ascii = value[0];
  18453. if( (check_ascii < 48) || (check_ascii > 57) )
  18454. {
  18455. isSuccess = ConfigurationStatus_Rejected;
  18456. }
  18457. else
  18458. {
  18459. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18461. TransactionMessageRetryIntervalValue = atoi(value);
  18462. isSuccess = ConfigurationStatus_Accepted;
  18463. }
  18464. }
  18465. else
  18466. {
  18467. isSuccess = ConfigurationStatus_Rejected;
  18468. }
  18469. }
  18470. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18471. {
  18472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18473. {
  18474. strcpy(str, (const char*)value);
  18475. for(int i = 0; str[i]; i++)
  18476. {
  18477. str[i] = tolower(str[i]);
  18478. }
  18479. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18481. isSuccess = ConfigurationStatus_Accepted;
  18482. }
  18483. else
  18484. {
  18485. isSuccess = ConfigurationStatus_Rejected;
  18486. }
  18487. }
  18488. if(strcmp(key, "WebSocketPingInterval") == 0)
  18489. {
  18490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18491. {
  18492. check_ascii = value[0];
  18493. if( (check_ascii < 48) || (check_ascii > 57) )
  18494. {
  18495. isSuccess = ConfigurationStatus_Rejected;
  18496. }
  18497. else
  18498. {
  18499. if((atoi(value) == 0) || (atoi(value) >= 10))
  18500. {
  18501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18502. isSuccess = ConfigurationStatus_Accepted;
  18503. }
  18504. else
  18505. isSuccess = ConfigurationStatus_Rejected;
  18506. }
  18507. }
  18508. else
  18509. {
  18510. isSuccess = ConfigurationStatus_Rejected;
  18511. }
  18512. }
  18513. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18514. {
  18515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18516. {
  18517. strcpy(str, (const char*)value);
  18518. for(int i = 0; str[i]; i++)
  18519. {
  18520. str[i] = tolower(str[i]);
  18521. }
  18522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18523. isSuccess = ConfigurationStatus_Accepted;
  18524. }
  18525. else
  18526. {
  18527. isSuccess = ConfigurationStatus_Rejected;
  18528. }
  18529. }
  18530. if(strcmp(key, "AuthorizationKey") == 0)
  18531. {
  18532. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18533. {
  18534. strcpy(str, (const char*)value);
  18535. int strlength = strlen(str);
  18536. char capture[3];
  18537. char stackItem = 0;
  18538. char password[21] = {0};
  18539. printf("String length: %d\n", strlength);
  18540. for(int idx=0; idx<(strlength/2); idx++)
  18541. {
  18542. capture[0] = str[(idx*2)];
  18543. capture[1] = str[(idx*2)+1];
  18544. capture[2] = 0;
  18545. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18546. sprintf(password,"%s%c", password, stackItem);
  18547. }
  18548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  18549. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18550. isSuccess = ConfigurationStatus_Accepted;
  18551. }
  18552. else
  18553. {
  18554. isSuccess = ConfigurationStatus_Rejected;
  18555. }
  18556. }
  18557. if(strcmp(key, "SecurityProfile") == 0)
  18558. {
  18559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18560. {
  18561. check_ascii = value[0];
  18562. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18563. {
  18564. isSuccess = ConfigurationStatus_Rejected;
  18565. }
  18566. else if(check_ascii == 0x33)
  18567. {
  18568. isSuccess = NotSupported;
  18569. }
  18570. else
  18571. {
  18572. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18573. {
  18574. if(((check_ascii - 0x30) == 1) ||
  18575. ((check_ascii - 0x30) == 2) ||
  18576. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18577. {
  18578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18579. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18580. isSuccess = ConfigurationStatus_Accepted;
  18581. }
  18582. else
  18583. isSuccess = ConfigurationStatus_Rejected;
  18584. }
  18585. else
  18586. isSuccess = ConfigurationStatus_Rejected;
  18587. }
  18588. }
  18589. else
  18590. {
  18591. isSuccess = ConfigurationStatus_Rejected;
  18592. }
  18593. }
  18594. if(strcmp(key, "DefaultPrice") == 0)
  18595. {
  18596. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18597. {
  18598. strcpy(str, (const char*)value);
  18599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18600. isSuccess = ConfigurationStatus_Accepted;
  18601. }
  18602. else
  18603. {
  18604. isSuccess = ConfigurationStatus_Rejected;
  18605. }
  18606. }
  18607. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18608. {
  18609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18610. {
  18611. strcpy(str, (const char*)value);
  18612. for(int i = 0; str[i]; i++)
  18613. {
  18614. str[i] = tolower(str[i]);
  18615. }
  18616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18617. isSuccess = ConfigurationStatus_Accepted;
  18618. }
  18619. else
  18620. {
  18621. isSuccess = ConfigurationStatus_Rejected;
  18622. }
  18623. }
  18624. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18625. {
  18626. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18627. {
  18628. strcpy(str, (const char*)value);
  18629. for(int i = 0; str[i]; i++)
  18630. {
  18631. str[i] = tolower(str[i]);
  18632. }
  18633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18634. isSuccess = ConfigurationStatus_Accepted;
  18635. }
  18636. else
  18637. {
  18638. isSuccess = ConfigurationStatus_Rejected;
  18639. }
  18640. }
  18641. if(strcmp(key, "TimeOffset") == 0)
  18642. {
  18643. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18644. {
  18645. strcpy(str, (const char*)value);
  18646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18647. isSuccess = ConfigurationStatus_Accepted;
  18648. }
  18649. else
  18650. {
  18651. isSuccess = ConfigurationStatus_Rejected;
  18652. }
  18653. }
  18654. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18655. {
  18656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18657. {
  18658. strcpy(str, (const char*)value);
  18659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18660. isSuccess = ConfigurationStatus_Accepted;
  18661. }
  18662. else
  18663. {
  18664. isSuccess = ConfigurationStatus_Rejected;
  18665. }
  18666. }
  18667. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18668. {
  18669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18670. {
  18671. strcpy(str, (const char*)value);
  18672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18673. isSuccess = ConfigurationStatus_Accepted;
  18674. }
  18675. else
  18676. {
  18677. isSuccess = ConfigurationStatus_Rejected;
  18678. }
  18679. }
  18680. if(strcmp(key, "SystemUptimeSec") == 0)
  18681. {
  18682. isSuccess = NotSupported;
  18683. }
  18684. if(strcmp(key, "FreeVend") == 0)
  18685. {
  18686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18687. {
  18688. strcpy(str, (const char*)value);
  18689. for(int i = 0; str[i]; i++)
  18690. {
  18691. str[i] = tolower(str[i]);
  18692. }
  18693. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18695. isSuccess = ConfigurationStatus_Accepted;
  18696. }
  18697. else
  18698. {
  18699. isSuccess = ConfigurationStatus_Rejected;
  18700. }
  18701. }
  18702. if(strcmp(key, "FreeVendIdtag") == 0)
  18703. {
  18704. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18705. {
  18706. strcpy(str, (const char*)value);
  18707. if(strlen(str) <= 20)
  18708. {
  18709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18710. isSuccess = ConfigurationStatus_Accepted;
  18711. }
  18712. else
  18713. {
  18714. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18715. isSuccess = ConfigurationStatus_Rejected;
  18716. }
  18717. }
  18718. else
  18719. {
  18720. isSuccess = ConfigurationStatus_Rejected;
  18721. }
  18722. }
  18723. if(strcmp(key, "OcppServer") == 0)
  18724. {
  18725. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18726. {
  18727. strcpy(str, (const char*)value);
  18728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18729. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18730. isSuccess = ConfigurationStatus_Accepted;
  18731. }
  18732. else
  18733. {
  18734. isSuccess = ConfigurationStatus_Rejected;
  18735. }
  18736. }
  18737. if(strcmp(key, "MaintainServer") == 0)
  18738. {
  18739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18740. {
  18741. strcpy(str, (const char*)value);
  18742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18743. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18744. isSuccess = ConfigurationStatus_Accepted;
  18745. }
  18746. else
  18747. {
  18748. isSuccess = ConfigurationStatus_Rejected;
  18749. }
  18750. }
  18751. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18752. {
  18753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18754. {
  18755. strcpy(str, (const char*)value);
  18756. for(int i = 0; str[i]; i++)
  18757. {
  18758. str[i] = tolower(str[i]);
  18759. }
  18760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18761. isSuccess = ConfigurationStatus_Accepted;
  18762. }
  18763. else
  18764. {
  18765. isSuccess = ConfigurationStatus_Rejected;
  18766. }
  18767. }
  18768. if(strcmp(key, "StatusNotificationInterval") == 0)
  18769. {
  18770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18771. {
  18772. check_ascii = value[0];
  18773. if( (check_ascii < 48) || (check_ascii > 57) )
  18774. {
  18775. isSuccess = ConfigurationStatus_Rejected;
  18776. }
  18777. else
  18778. {
  18779. if((atoi(value) == 0) || (atoi(value) >= 10))
  18780. {
  18781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18782. isSuccess = ConfigurationStatus_Accepted;
  18783. }
  18784. else
  18785. isSuccess = ConfigurationStatus_Rejected;
  18786. }
  18787. }
  18788. else
  18789. {
  18790. isSuccess = ConfigurationStatus_Rejected;
  18791. }
  18792. }
  18793. if(strcmp(key, "PreAuthAmount") == 0)
  18794. {
  18795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18796. {
  18797. check_ascii = value[0];
  18798. if( (check_ascii < 48) || (check_ascii > 57) )
  18799. {
  18800. isSuccess = ConfigurationStatus_Rejected;
  18801. }
  18802. else
  18803. {
  18804. if(atof(value) >= 0)
  18805. {
  18806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18807. isSuccess = ConfigurationStatus_Accepted;
  18808. }
  18809. else
  18810. isSuccess = ConfigurationStatus_Rejected;
  18811. }
  18812. }
  18813. else
  18814. {
  18815. isSuccess = ConfigurationStatus_Rejected;
  18816. }
  18817. }
  18818. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  18819. {
  18820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  18821. {
  18822. check_ascii = value[0];
  18823. if( (check_ascii < 48) || (check_ascii > 57) )
  18824. {
  18825. isSuccess = ConfigurationStatus_Rejected;
  18826. }
  18827. else
  18828. {
  18829. if(atoi(value) >= 0)
  18830. {
  18831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  18832. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  18833. isSuccess = ConfigurationStatus_Accepted;
  18834. }
  18835. else
  18836. isSuccess = ConfigurationStatus_Rejected;
  18837. }
  18838. }
  18839. else
  18840. {
  18841. isSuccess = ConfigurationStatus_Rejected;
  18842. }
  18843. }
  18844. if(strcmp(key, "PowerSharingServerIP") == 0)
  18845. {
  18846. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  18847. {
  18848. strcpy(str, (const char*)value);
  18849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  18850. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  18851. isSuccess = ConfigurationStatus_Accepted;
  18852. }
  18853. else
  18854. {
  18855. isSuccess = ConfigurationStatus_Rejected;
  18856. }
  18857. }
  18858. if(strcmp(key, "EVCCID_PREFIX") == 0)
  18859. {
  18860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  18861. {
  18862. strcpy(str, (const char*)value);
  18863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  18864. isSuccess = ConfigurationStatus_Accepted;
  18865. }
  18866. else
  18867. {
  18868. isSuccess = ConfigurationStatus_Rejected;
  18869. }
  18870. }
  18871. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  18872. {
  18873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  18874. {
  18875. if(atoi(value) > modelnameInfo.ratedPower)
  18876. {
  18877. isSuccess = ConfigurationStatus_Rejected;
  18878. }
  18879. else{
  18880. strcpy(str, (const char*)value);
  18881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  18882. isSuccess = ConfigurationStatus_Accepted;
  18883. }
  18884. }
  18885. else
  18886. {
  18887. isSuccess = ConfigurationStatus_Rejected;
  18888. }
  18889. }
  18890. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  18891. {
  18892. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  18893. {
  18894. if((atoi(value) != 0) && (atoi(value) < 5))
  18895. {
  18896. isSuccess = ConfigurationStatus_Rejected;
  18897. }
  18898. else{
  18899. strcpy(str, (const char*)value);
  18900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  18901. isSuccess = ConfigurationStatus_Accepted;
  18902. }
  18903. }
  18904. else
  18905. {
  18906. isSuccess = ConfigurationStatus_Rejected;
  18907. }
  18908. }
  18909. if(strcmp(key, "CpoName") == 0)
  18910. {
  18911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  18912. {
  18913. strcpy(str, (const char*)value);
  18914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  18915. isSuccess = ConfigurationStatus_Accepted;
  18916. }
  18917. else
  18918. {
  18919. isSuccess = ConfigurationStatus_Rejected;
  18920. }
  18921. }
  18922. #if 0
  18923. //For OCPP Test Case
  18924. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  18925. {
  18926. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  18927. {
  18928. strcpy(str, (const char*)value);
  18929. for(int i = 0; str[i]; i++)
  18930. {
  18931. str[i] = tolower(str[i]);
  18932. }
  18933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18934. isSuccess = ConfigurationStatus_Accepted;
  18935. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  18936. }
  18937. else
  18938. {
  18939. isSuccess = ConfigurationStatus_Rejected;
  18940. }
  18941. }
  18942. #endif
  18943. #if 1
  18944. if(strcmp(key, "LocalAuthListEnabled") == 0)
  18945. {
  18946. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  18947. {
  18948. strcpy(str, (const char*)value);
  18949. for(int i = 0; str[i]; i++)
  18950. {
  18951. str[i] = tolower(str[i]);
  18952. }
  18953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18954. isSuccess = ConfigurationStatus_Accepted;
  18955. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  18956. }
  18957. else
  18958. {
  18959. isSuccess = ConfigurationStatus_Rejected;
  18960. }
  18961. }
  18962. #endif
  18963. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  18964. {
  18965. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  18966. {
  18967. check_ascii = value[0];
  18968. if( (check_ascii < 48) || (check_ascii > 57) )
  18969. {
  18970. isSuccess = ConfigurationStatus_Rejected;
  18971. }
  18972. else
  18973. {
  18974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  18975. isSuccess = ConfigurationStatus_Accepted;
  18976. }
  18977. }
  18978. else
  18979. {
  18980. isSuccess = ConfigurationStatus_Rejected;
  18981. }
  18982. }
  18983. if(strcmp(key, "SendLocalListMaxLength") == 0)
  18984. {
  18985. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  18986. {
  18987. check_ascii = value[0];
  18988. if( (check_ascii < 48) || (check_ascii > 57) )
  18989. {
  18990. isSuccess = ConfigurationStatus_Rejected;
  18991. }
  18992. else
  18993. {
  18994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  18995. isSuccess = ConfigurationStatus_Accepted;
  18996. }
  18997. }
  18998. else
  18999. {
  19000. isSuccess = ConfigurationStatus_Rejected;
  19001. }
  19002. }
  19003. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19004. {
  19005. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19006. {
  19007. strcpy(str, (const char*)value);
  19008. for(int i = 0; str[i]; i++)
  19009. {
  19010. str[i] = tolower(str[i]);
  19011. }
  19012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19013. isSuccess = ConfigurationStatus_Accepted;
  19014. }
  19015. else
  19016. {
  19017. isSuccess = ConfigurationStatus_Rejected;
  19018. }
  19019. }
  19020. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19021. {
  19022. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19023. {
  19024. check_ascii = value[0];
  19025. if( (check_ascii < 48) || (check_ascii > 57) )
  19026. {
  19027. isSuccess = ConfigurationStatus_Rejected;
  19028. }
  19029. else
  19030. {
  19031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19032. isSuccess = ConfigurationStatus_Accepted;
  19033. }
  19034. }
  19035. else
  19036. {
  19037. isSuccess = ConfigurationStatus_Rejected;
  19038. }
  19039. }
  19040. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19041. {
  19042. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19043. {
  19044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19045. isSuccess = ConfigurationStatus_Accepted;
  19046. }
  19047. else
  19048. {
  19049. isSuccess = ConfigurationStatus_Rejected;
  19050. }
  19051. }
  19052. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19053. {
  19054. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19055. {
  19056. check_ascii = value[0];
  19057. if( (check_ascii < 48) || (check_ascii > 57) )
  19058. {
  19059. isSuccess = ConfigurationStatus_Rejected;
  19060. }
  19061. else
  19062. {
  19063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19064. isSuccess = ConfigurationStatus_Accepted;
  19065. }
  19066. }
  19067. else
  19068. {
  19069. isSuccess = ConfigurationStatus_Rejected;
  19070. }
  19071. }
  19072. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19073. {
  19074. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19075. {
  19076. strcpy(str, (const char*)value);
  19077. for(int i = 0; str[i]; i++)
  19078. {
  19079. str[i] = tolower(str[i]);
  19080. }
  19081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19082. isSuccess = ConfigurationStatus_Accepted;
  19083. }
  19084. else
  19085. {
  19086. isSuccess = ConfigurationStatus_Rejected;
  19087. }
  19088. }
  19089. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19090. {
  19091. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19092. {
  19093. check_ascii = value[0];
  19094. if( (check_ascii < 48) || (check_ascii > 57) )
  19095. {
  19096. isSuccess = ConfigurationStatus_Rejected;
  19097. }
  19098. else
  19099. {
  19100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19101. isSuccess = ConfigurationStatus_Accepted;
  19102. }
  19103. }
  19104. else
  19105. {
  19106. isSuccess = ConfigurationStatus_Rejected;
  19107. }
  19108. }
  19109. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19110. return isSuccess;
  19111. }
  19112. int TransactionMessageAttemptsGet(void)
  19113. {
  19114. return TransactionMessageAttemptsValue;
  19115. }
  19116. int FirstHeartBeatResponse(void)
  19117. {
  19118. return FirstHeartBeat;
  19119. }
  19120. int TransactionMessageRetryIntervalGet(void)
  19121. {
  19122. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19123. }
  19124. int ReadHttpStatus(int sock)
  19125. {
  19126. //char c;
  19127. char buff[1024]="",*ptr=buff+1;
  19128. int bytes_received, status;
  19129. DEBUG_INFO("Begin Response ..\n");
  19130. while((bytes_received = recv(sock, ptr, 1, 0))){
  19131. if(bytes_received==-1){
  19132. perror("ReadHttpStatus");
  19133. exit(1);
  19134. }
  19135. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19136. ptr++;
  19137. }
  19138. *ptr=0;
  19139. ptr=buff+1;
  19140. sscanf(ptr,"%*s %d ", &status);
  19141. DEBUG_INFO("%s\n",ptr);
  19142. DEBUG_INFO("status=%d\n",status);
  19143. DEBUG_INFO("End Response ..\n");
  19144. return (bytes_received>0)?status:0;
  19145. }
  19146. //the only filed that it parsed is 'Content-Length'
  19147. int ParseHeader(int sock)
  19148. {
  19149. //char c;
  19150. char buff[1024]="",*ptr=buff+4;
  19151. int bytes_received;
  19152. DEBUG_INFO("Begin HEADER ..\n");
  19153. while((bytes_received = recv(sock, ptr, 1, 0))){
  19154. if(bytes_received==-1){
  19155. perror("Parse Header");
  19156. exit(1);
  19157. }
  19158. if(
  19159. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19160. (ptr[-1]=='\r') && (*ptr=='\n' )
  19161. ) break;
  19162. ptr++;
  19163. }
  19164. *ptr=0;
  19165. ptr=buff+4;
  19166. //printf("%s",ptr);
  19167. if(bytes_received){
  19168. ptr=strstr(ptr,"Content-Length:");
  19169. if(ptr){
  19170. sscanf(ptr,"%*s %d",&bytes_received);
  19171. }else
  19172. bytes_received=-1; //unknown size
  19173. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19174. }
  19175. DEBUG_INFO("End HEADER ..\n");
  19176. return bytes_received ;
  19177. }
  19178. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19179. {
  19180. int result = TRUE;
  19181. char rmFileCmd[100]={0};
  19182. char FilePath[100]={0};
  19183. char ftpbuf[200];
  19184. int systemresult;
  19185. sprintf(FilePath,"/mnt/%s",filename);
  19186. system("ping 8.8.8.8 &");
  19187. if((access(FilePath,F_OK))!=-1)
  19188. {
  19189. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19190. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19191. system(rmFileCmd);
  19192. }
  19193. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19194. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19195. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19196. systemresult = system(ftpbuf);
  19197. if(systemresult != 0)
  19198. {
  19199. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19200. result = FALSE;
  19201. }
  19202. system("pkill ping");
  19203. return result;
  19204. }
  19205. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19206. {
  19207. int result = TRUE;
  19208. char rmFileCmd[100]={0};
  19209. char FilePath[100]={0};
  19210. char ftpbuf[200];
  19211. int systemresult;
  19212. sprintf(FilePath,"/mnt/%s",filename);
  19213. system("ping 8.8.8.8 &");
  19214. if((access(FilePath,F_OK))!=-1)
  19215. {
  19216. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19217. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19218. system(rmFileCmd);
  19219. }
  19220. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19221. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19222. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19223. systemresult = system(ftpbuf);
  19224. if(systemresult != 0)
  19225. {
  19226. DEBUG_WARN("scp error!\n");
  19227. result = FALSE;
  19228. }
  19229. system("pkill ping");
  19230. return result;
  19231. }
  19232. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19233. {
  19234. int result = TRUE;
  19235. char rmFileCmd[100]={0};
  19236. char FilePath[100]={0};
  19237. char ftpbuf[200];
  19238. int systemresult;
  19239. sprintf(FilePath,"/mnt/%s",filename);
  19240. system("ping 8.8.8.8 &");
  19241. if((access(FilePath,F_OK))!=-1)
  19242. {
  19243. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19244. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19245. system(rmFileCmd);
  19246. }
  19247. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19248. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  19249. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19250. systemresult = system(ftpbuf);
  19251. if(systemresult != 0)
  19252. {
  19253. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  19254. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19255. systemresult = system(ftpbuf);
  19256. if(systemresult != 0)
  19257. {
  19258. DEBUG_WARN("FTP download fail!\n");
  19259. result = FALSE;
  19260. }
  19261. }
  19262. system("pkill ping");
  19263. return result;
  19264. }
  19265. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19266. {
  19267. char rmFileCmd[100]={0};
  19268. char FilePath[100]={0};
  19269. char buf[512];
  19270. int systemresult = 0;
  19271. //DEBUG_INFO("filename=%s\n",filename);
  19272. //DEBUG_INFO("url=%s\n",url);
  19273. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19274. if((access(FilePath,F_OK))!=-1)
  19275. {
  19276. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19277. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19278. system(rmFileCmd);
  19279. }
  19280. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19281. if(fp == NULL)
  19282. {
  19283. DEBUG_INFO("log is NULL\n");
  19284. return FALSE;
  19285. }
  19286. else
  19287. {
  19288. fprintf(fp, "%s\n", url);
  19289. fprintf(fp, "%s\n", filename);
  19290. fclose(fp);
  19291. }
  19292. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19293. if(phpFP == NULL)
  19294. {
  19295. DEBUG_INFO("PHP upload fail.\n");
  19296. return FALSE;
  19297. }
  19298. else
  19299. {
  19300. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19301. {
  19302. if(strstr(buf, "result") != NULL)
  19303. {
  19304. sscanf(buf, "result: %d", &systemresult);
  19305. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19306. }
  19307. }
  19308. pclose(phpFP);
  19309. }
  19310. if(systemresult != 1)
  19311. {
  19312. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19313. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19314. if(phpFP == NULL)
  19315. {
  19316. DEBUG_WARN("PHP PUT upload fail.\n");
  19317. return FALSE;
  19318. }
  19319. else
  19320. {
  19321. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19322. {
  19323. if(strstr(buf, "result") != NULL)
  19324. {
  19325. sscanf(buf, "result: %d", &systemresult);
  19326. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19327. }
  19328. }
  19329. pclose(phpFP);
  19330. }
  19331. }
  19332. if(systemresult != 1)
  19333. {
  19334. DEBUG_WARN("PHP PUT upload fail.\n");
  19335. return FALSE;
  19336. }
  19337. return TRUE;
  19338. }
  19339. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19340. {
  19341. int result = FALSE;
  19342. char ftpbuf[200];
  19343. int systemresult;
  19344. /*
  19345. // Domaind name transfer to IP address
  19346. struct hostent* server;
  19347. char *IPbuffer;
  19348. server = gethostbyname(location);
  19349. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19350. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19351. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19352. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19353. systemresult = system(ftpbuf);
  19354. if(systemresult != 0)
  19355. {
  19356. DEBUG_INFO("ftpput error!\n");
  19357. }
  19358. else
  19359. {
  19360. result = TRUE;
  19361. DEBUG_INFO("ftpput OK!\n");
  19362. }
  19363. return result;
  19364. }
  19365. int GetOcppServerURL()
  19366. {
  19367. int result = FALSE;
  19368. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19369. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19370. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19371. struct yuarel url;
  19372. char urlStr[512];
  19373. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19374. {
  19375. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19376. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19377. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19378. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19379. if(yuarel_parse(&url, urlStr) != -1)
  19380. {
  19381. sprintf(OcppProtocol, "%s", url.scheme);
  19382. sprintf(OcppHost, "%s", url.host);
  19383. if(url.path == NULL)
  19384. OcppTempPath[0] = '\0';
  19385. else
  19386. {
  19387. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19388. {
  19389. sprintf(OcppTempPath, "%s/", url.path);
  19390. }
  19391. else
  19392. {
  19393. sprintf(OcppTempPath, "%s", url.path);
  19394. }
  19395. }
  19396. if(url.port == 0)
  19397. {
  19398. if(strcmp(OcppProtocol, "wss") == 0)
  19399. OcppPort = 443;
  19400. else
  19401. OcppPort = 80;
  19402. }
  19403. else
  19404. OcppPort = url.port;
  19405. result = TRUE;
  19406. }
  19407. }
  19408. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19409. {
  19410. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19411. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19412. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19413. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19414. if(yuarel_parse(&url, urlStr) != -1)
  19415. {
  19416. sprintf(OcppProtocol, "%s", url.scheme);
  19417. sprintf(OcppHost, "%s", url.host);
  19418. if(url.path == NULL)
  19419. OcppTempPath[0] = '\0';
  19420. else
  19421. sprintf(OcppTempPath, "%s", url.path);
  19422. if(url.port == 0)
  19423. {
  19424. if(strcmp(OcppProtocol, "wss") == 0)
  19425. OcppPort = 443;
  19426. else
  19427. OcppPort = 80;
  19428. }
  19429. else
  19430. OcppPort = url.port;
  19431. result = TRUE;
  19432. }
  19433. }
  19434. else
  19435. {
  19436. strcpy(OcppHost,"");
  19437. }
  19438. return result;
  19439. }
  19440. int GetOcppPath()
  19441. {
  19442. int result = FALSE;
  19443. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19444. {
  19445. if(OcppTempPath == NULL)
  19446. {
  19447. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19448. }
  19449. else
  19450. {
  19451. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19452. }
  19453. result = TRUE;
  19454. goto End;
  19455. }
  19456. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19457. {
  19458. if(OcppTempPath == NULL)
  19459. {
  19460. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19461. }
  19462. else
  19463. {
  19464. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19465. }
  19466. result = TRUE;
  19467. goto End;
  19468. }
  19469. else
  19470. {
  19471. strcpy(OcppPath,"");
  19472. }
  19473. End:
  19474. return result;
  19475. }
  19476. int GetOcppPort()
  19477. {
  19478. return OcppPort;
  19479. }
  19480. int GetOcppConnStatus(void)
  19481. {
  19482. return ShmOCPP16Data->OcppConnStatus;
  19483. }
  19484. void SetOcppConnStatus(uint8_t status)
  19485. {
  19486. ShmOCPP16Data->OcppConnStatus = status;
  19487. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19488. }
  19489. int GetHeartBeatWithNOResponse(void)
  19490. {
  19491. return HeartBeatWithNOResponse;
  19492. }
  19493. void SetHeartBeatWithNOResponse(void)
  19494. {
  19495. HeartBeatWithNOResponse = 0;
  19496. }
  19497. void GetStartTransactionIdTag(int gun_index)
  19498. {
  19499. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19500. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19501. }
  19502. int GetStartTransactionId(int gun_index)
  19503. {
  19504. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19505. }
  19506. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19507. {
  19508. char ch;
  19509. FILE *fptr1;
  19510. int temptransactionId;
  19511. char str[100]={0};
  19512. temptransactionId = 0;
  19513. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19514. {
  19515. DEBUG_INFO("IdTag is empty.\n");
  19516. return temptransactionId;
  19517. }
  19518. /*------ Read the file ----------------*/
  19519. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19520. if (!fptr1)
  19521. {
  19522. DEBUG_INFO("QueueTransactionId file open error.\n");
  19523. //printf(" File not found or unable to open the input file!!\n");
  19524. return temptransactionId;
  19525. }
  19526. ch=fgetc(fptr1);
  19527. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19528. rewind(fptr1);
  19529. if(ch!=EOF)
  19530. {
  19531. // printf("%c",ch);
  19532. while (fgets(str, 100, fptr1) != NULL)
  19533. {
  19534. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19535. if(str[0]=='\0')
  19536. {
  19537. break;
  19538. }
  19539. char *revbuf[8] = {0}; // Variable store string split
  19540. int num = 0;// Quantity after string split
  19541. DEBUG_INFO("Transaction queue data= %s\n", str);
  19542. splitstring(str,",",revbuf,&num); // String split
  19543. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19544. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19545. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19546. DEBUG_INFO("------------------------------\n");
  19547. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19548. {
  19549. if(isStopTransaction)
  19550. {
  19551. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19552. {
  19553. temptransactionId = atoi(revbuf[2]);
  19554. //break;
  19555. }
  19556. }
  19557. else
  19558. {
  19559. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19560. {
  19561. temptransactionId = atoi(revbuf[2]);
  19562. //break;
  19563. }
  19564. }
  19565. }
  19566. }
  19567. }
  19568. else
  19569. DEBUG_INFO("EOF\n");
  19570. fclose(fptr1);
  19571. /*------- End of reading ---------------*/
  19572. return temptransactionId;
  19573. }
  19574. void SetTransactionIdZero(int transactionId)
  19575. {
  19576. char ch;
  19577. FILE *fptr1, *fptr2;
  19578. int temptransactionId = 0;
  19579. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19580. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19581. if (!fptr1)
  19582. {
  19583. //printf(" File not found or unable to open the input file!!\n");
  19584. return ;
  19585. }
  19586. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19587. if (!fptr2)
  19588. {
  19589. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19590. fclose(fptr1);
  19591. return ;
  19592. }
  19593. ch=fgetc(fptr1);
  19594. rewind(fptr1);
  19595. if(ch!=EOF)
  19596. {
  19597. // copy all contents to the temporary file except the specific line
  19598. while (fgets(str, 100, fptr1) != NULL)
  19599. {
  19600. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19601. if(str[0]=='\0')
  19602. {
  19603. break;
  19604. }
  19605. char *revbuf[8] = {0};
  19606. int num = 0;
  19607. strcpy(strtemp, str);
  19608. splitstring(str,",",revbuf,&num);
  19609. if(revbuf[2][0] != '\0')
  19610. {
  19611. temptransactionId = atoi(revbuf[2]);
  19612. if(transactionId != temptransactionId)
  19613. {
  19614. fprintf(fptr2, "%s\n", strtemp);
  19615. }
  19616. }
  19617. }
  19618. }
  19619. fclose(fptr1);
  19620. fclose(fptr2);
  19621. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19622. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19623. /*------ Read the file ----------------*/
  19624. }
  19625. int InternetDisconnect(void)
  19626. {
  19627. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19628. }
  19629. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19630. void storeTempStopTransaction(int gun_index)
  19631. {
  19632. char guid[37]={0};
  19633. int tempIndex = 0;
  19634. char TempStopTransaction[256];
  19635. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19636. DEBUG_INFO("storeTempStopTransaction...\n");
  19637. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19638. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19639. //=========================== Stop Transaction Time ===============================================
  19640. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  19641. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19642. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19643. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19644. {
  19645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19646. {
  19647. tempIndex = ((gun_index==2) ? 1: 0);
  19648. }
  19649. else
  19650. {
  19651. tempIndex = gun_index;
  19652. }
  19653. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19654. {
  19655. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19656. {
  19657. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19658. }
  19659. }// END OF CHAdeMO_QUANTITY
  19660. }
  19661. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19662. {
  19663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19664. {
  19665. tempIndex = ((gun_index==2) ? 1: 0);
  19666. }
  19667. else
  19668. {
  19669. tempIndex = gun_index;
  19670. }
  19671. for (int index = 0; index < CCS_QUANTITY; index++)
  19672. {
  19673. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19674. {
  19675. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19676. }
  19677. }// END OF CCS_QUANTITY
  19678. }
  19679. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19680. {
  19681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19682. {
  19683. tempIndex = ((gun_index==2) ? 1: 0);
  19684. }
  19685. else
  19686. {
  19687. tempIndex = gun_index;
  19688. }
  19689. for (int index = 0; index < GB_QUANTITY; index++)
  19690. {
  19691. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19692. {
  19693. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19694. }
  19695. }// END OF GB_QUANTITY
  19696. }
  19697. else if(gunType[gun_index] == GUN_TYPE_DO)
  19698. {
  19699. tempIndex = gun_index;
  19700. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19701. {
  19702. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19703. {
  19704. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19705. }
  19706. }
  19707. }
  19708. else
  19709. {
  19710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19711. {
  19712. tempIndex = 2;
  19713. }
  19714. else
  19715. {
  19716. tempIndex = gun_index;
  19717. }
  19718. for (int index = 0; index < AC_QUANTITY; index++)
  19719. {
  19720. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19721. {
  19722. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19723. }
  19724. }// END OF AC_QUANTITY
  19725. }
  19726. //======================================== Message create ==============================================
  19727. json_object *StopTransaction = json_object_new_object();
  19728. json_object *transactionDatas = json_object_new_array();
  19729. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19730. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19731. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19732. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19733. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19734. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19735. meterValueBufferQuery(gun_index, transactionDatas);
  19736. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19737. random_uuid(guid);
  19738. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19739. ,MESSAGE_TYPE_CALL
  19740. ,guid
  19741. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19742. json_object_put(StopTransaction);
  19743. // Check File "TempStopTransaction" Exist
  19744. if((access(TempStopTransaction,F_OK))!=-1)
  19745. {
  19746. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19747. fclose(fopen(TempStopTransaction, "w"));
  19748. }
  19749. else
  19750. {
  19751. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19752. FILE *log = fopen(TempStopTransaction, "w+");
  19753. if(log == NULL)
  19754. {
  19755. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19756. return ;
  19757. }
  19758. else
  19759. {
  19760. fclose(log);
  19761. }
  19762. }
  19763. //Add TempStopTransaction | Update TempStopTransaction
  19764. // open file for writing
  19765. FILE *outfile;
  19766. outfile = fopen (TempStopTransaction, "a");
  19767. //DEBUG_INFO("data = %s\n", queuedata);
  19768. fputs(queuedata, outfile);
  19769. fputs("\n", outfile);
  19770. fclose (outfile);
  19771. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19772. OCPP_updatePeriodEnergy(gun_index);
  19773. }
  19774. void checkTempStopTransaction(int gun_index)
  19775. {
  19776. FILE *fptr1;
  19777. char ch;
  19778. char str[QUEUE_MESSAGE_LENGTH]={0};
  19779. char guid[37]={0};
  19780. char tempdata[65]={0};
  19781. char connectorStr[2]={0};
  19782. char TempStopTransaction[256];
  19783. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19784. fptr1 = fopen(TempStopTransaction, "r");
  19785. //TempStopTransaction格式: 槍號,StopTransaction封包
  19786. if (!fptr1)
  19787. {
  19788. //printf(" File not found or unable to open the input file!!\n");
  19789. return ;
  19790. }
  19791. ch=fgetc(fptr1);
  19792. //printf(" Now the content of the file %s is : \n",fname);
  19793. rewind(fptr1);
  19794. if(ch!=EOF)
  19795. {
  19796. // copy all contents to the temporary file except the specific line
  19797. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19798. {
  19799. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19800. if(str[0]=='\0')
  19801. {
  19802. break;
  19803. }
  19804. //TempStopTransaction格式: 槍號,StopTransaction封包
  19805. strncpy(connectorStr, str, 1);
  19806. if(atoi(connectorStr) != (gun_index+1))
  19807. {
  19808. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19809. fclose(fptr1);
  19810. return ;
  19811. }
  19812. //random_uuid(guid);
  19813. strncpy(guid, str+6, 36); //copy guid
  19814. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19815. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19816. {
  19817. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19818. }
  19819. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19820. OCPP_insert_transaction_msg(NO, str);
  19821. memset(str,0,ARRAY_SIZE(str));
  19822. }
  19823. }
  19824. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19825. fclose(fptr1);
  19826. remove(TempStopTransaction); // remove the original file
  19827. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19828. }
  19829. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19830. {
  19831. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19832. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19833. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19834. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19835. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19836. }
  19837. void FillTransactionId(int ConnectorId, int TransactionId)
  19838. {
  19839. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19840. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  19841. }
  19842. int GetWebSocketPingInterval(void)
  19843. {
  19844. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19845. }
  19846. int GetServerSign(void)
  19847. {
  19848. return server_sign;
  19849. }
  19850. uint8_t GetOcppSecurityProfile()
  19851. {
  19852. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19853. }
  19854. void MergeCertificates()
  19855. {
  19856. char cmdBuf[2048]={0};
  19857. if(access(ROOTCA_CS,F_OK) != -1)
  19858. {
  19859. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  19860. }
  19861. else
  19862. {
  19863. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  19864. }
  19865. system(cmdBuf);
  19866. }
  19867. void GetOcppChargerBoxId(uint8_t *data)
  19868. {
  19869. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19870. }
  19871. void GetOcppSecurityPassword(uint8_t *data)
  19872. {
  19873. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19874. }
  19875. void SetOcppVersion(uint8_t *version)
  19876. {
  19877. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19878. DEBUG_INFO("ocpp version: %s\n", version);
  19879. if(strstr((char*)version, "ocpp1.6") != NULL)
  19880. {
  19881. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19882. }
  19883. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19884. {
  19885. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19886. system("pkill OcppBackend");
  19887. }
  19888. }
  19889. void SetServerSign(int value)
  19890. {
  19891. server_sign = value;
  19892. }
  19893. int GetBootNotificationInterval(void)
  19894. {
  19895. return BootNotificationInterval;
  19896. }
  19897. int GetInternetConn(void)
  19898. {
  19899. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19900. }
  19901. int GetBackendConnectionTimeout(void)
  19902. {
  19903. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19904. }
  19905. int isConnectorInitMode(int gun_index)
  19906. {
  19907. int tempIndex = 0;
  19908. int result = TRUE;
  19909. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19910. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19911. {
  19912. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19913. {
  19914. tempIndex = ((gun_index==2) ? 1: 0);
  19915. }
  19916. else
  19917. {
  19918. tempIndex = gun_index;
  19919. }
  19920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19921. {
  19922. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19923. {
  19924. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19925. } //end of the same index
  19926. }//end of for CHAdeMO_QUANTITY
  19927. }
  19928. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19929. {
  19930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19931. {
  19932. tempIndex = ((gun_index==2) ? 1: 0);
  19933. }
  19934. else
  19935. {
  19936. tempIndex = gun_index;
  19937. }
  19938. for (int index = 0; index < CCS_QUANTITY; index++)
  19939. {
  19940. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19941. {
  19942. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19943. } //end of the same index
  19944. } // end of for CCS_QUANTITY
  19945. }
  19946. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19947. {
  19948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19949. {
  19950. tempIndex = ((gun_index==2) ? 1: 0);
  19951. }
  19952. else
  19953. {
  19954. tempIndex = gun_index;
  19955. }
  19956. for (int index = 0; index < GB_QUANTITY; index++)
  19957. {
  19958. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19959. {
  19960. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19961. } //end of the same index
  19962. } // end of for GB_QUANTITY
  19963. }
  19964. else if(gunType[gun_index] == GUN_TYPE_DO)
  19965. {
  19966. tempIndex = gun_index;
  19967. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19968. {
  19969. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19970. {
  19971. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19972. } //end of the same index
  19973. }
  19974. }
  19975. else
  19976. {
  19977. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19978. {
  19979. tempIndex = 2;
  19980. }
  19981. else
  19982. {
  19983. tempIndex = gun_index;
  19984. }
  19985. for (int index = 0; index < AC_QUANTITY; index++)
  19986. {
  19987. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19988. {
  19989. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19990. }//end of the same index
  19991. }//end of for AC_QUANTITY
  19992. }
  19993. return result;
  19994. }
  19995. void refreshProcDogTimer()
  19996. {
  19997. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19998. }
  19999. void InitialSystemValue(void)
  20000. {
  20001. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20002. locallistVersion=0;
  20003. BootNotificationInterval = 0;
  20004. authorizeRetryTimes = 0;
  20005. GunStatusInterval = 10;
  20006. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20007. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20008. //Hear Beat
  20009. HeartBeatWithNOResponse = 0;
  20010. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20011. FirstHeartBeat = 0;
  20012. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20013. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20014. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20015. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20016. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20017. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20018. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20019. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20020. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20021. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20022. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20023. //Status && ConnectorPlugIn Setting
  20024. Connector0PreviousSystemStatus = 99;
  20025. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20026. {
  20027. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20028. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20029. }
  20030. for (int index = 0; index < CCS_QUANTITY; index++)
  20031. {
  20032. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20033. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20034. }
  20035. for (int index = 0; index < GB_QUANTITY; index++)
  20036. {
  20037. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20038. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20039. }
  20040. for (int index = 0; index < AC_QUANTITY; index++)
  20041. {
  20042. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20043. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20044. }
  20045. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20046. {
  20047. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20048. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20049. }
  20050. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20051. {
  20052. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20053. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20054. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20055. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20056. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20057. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20058. }
  20059. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20060. refreshStartTimer(&clientTime.Heartbeat);
  20061. sleep(1);
  20062. }
  20063. void LWS_Send(char *str)
  20064. {
  20065. //=====================================================
  20066. // Check InternetConn 0: disconnected, 1: connected
  20067. //====================================================
  20068. if(GetOcppConnStatus() == 0)
  20069. {
  20070. DEBUG_INFO("offline now !!!\n");
  20071. return;
  20072. }
  20073. // Only disable isWebsocketSendable operation initiated by charger
  20074. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20075. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20076. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20077. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20078. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20079. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20080. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20081. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20082. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20083. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20084. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20085. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20086. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20087. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20088. {
  20089. isWebsocketSendable = 0;
  20090. }
  20091. pthread_mutex_lock(&lock_send);
  20092. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20093. sprintf((char *)SendBuffer, "%s", str);
  20094. SendBufLen = strlen(str);
  20095. pthread_mutex_unlock(&lock_send);
  20096. lws_callback_on_writable(wsi_client);
  20097. //lws_service(context, 0);
  20098. //sleep(1);
  20099. }
  20100. void LWS_SendNow(char *str)
  20101. {
  20102. //=====================================================
  20103. // Check InternetConn 0: disconnected, 1: connected
  20104. //====================================================
  20105. if(GetOcppConnStatus() == 0)
  20106. {
  20107. DEBUG_INFO("offline now !!!\n");
  20108. return;
  20109. }
  20110. // Only disable isWebsocketSendable operation initiated by charger
  20111. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20112. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20113. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20114. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20115. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20116. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20117. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20118. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20119. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20120. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20121. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20122. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20123. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20124. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20125. {
  20126. isWebsocketSendable = 0;
  20127. }
  20128. pthread_mutex_lock(&lock_send);
  20129. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20130. sprintf((char *)SendBuffer, "%s", str);
  20131. SendBufLen = strlen(str);
  20132. pthread_mutex_unlock(&lock_send);
  20133. lws_callback_on_writable(wsi_client);
  20134. lws_service(context, 0);
  20135. //sleep(1);
  20136. }