MessageHandler.c 994 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178
  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)-100) 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 occupancyFeeAct(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_OccupancyFeeAct");
  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.OccupancyFeeAct[gun_index].occupancySN));
  1386. json_object_object_add(dataBuf, "action", json_object_new_int(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].action));
  1387. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1388. json_object_put(dataBuf);
  1389. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1390. }
  1391. //==========================================
  1392. // Check time passed since today
  1393. //==========================================
  1394. long long DiffTimebWithNow(struct timeb ST)
  1395. {
  1396. //return milli-second
  1397. struct timeb ET;
  1398. long long StartTime,StopTime;
  1399. ftime(&ET);
  1400. StartTime=(long long)ST.time;
  1401. StopTime=(long long)ET.time;
  1402. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1403. }
  1404. int getTimePassSinceToday(uint8_t gun_index)
  1405. {
  1406. int result = -1;
  1407. static time_t lastTime[4];
  1408. time_t t;
  1409. struct tm *tmStartToday;
  1410. struct timeb tbStartToday;
  1411. t=time(NULL);
  1412. if(difftime(t, lastTime[gun_index])>0)
  1413. {
  1414. tmStartToday=localtime(&t);
  1415. tmStartToday->tm_hour = 0;
  1416. tmStartToday->tm_min = 0;
  1417. tmStartToday->tm_sec = 0;
  1418. tbStartToday.time = mktime(tmStartToday);
  1419. tbStartToday.millitm = 0;
  1420. result = DiffTimebWithNow(tbStartToday)/1000;
  1421. lastTime[gun_index] = t;
  1422. }
  1423. return result;
  1424. }
  1425. void getNowDatetime(uint8_t *data)
  1426. {
  1427. time_t t = time(NULL);
  1428. struct tm tm = *localtime(&t);
  1429. 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);
  1430. }
  1431. int syncDateTimeRTC(uint8_t *data)
  1432. {
  1433. struct ParsingResult
  1434. {
  1435. int result;
  1436. int scanedElement;
  1437. int year;
  1438. int month;
  1439. int mday;
  1440. int hour;
  1441. int min;
  1442. int sec;
  1443. int tz_hour;
  1444. int tz_min;
  1445. float minSec;
  1446. }result;
  1447. struct tm tmOrg;
  1448. struct tm *tmTarget;
  1449. struct timeb tbTarget;
  1450. char buf[128];
  1451. memset(&result, 0x00, sizeof(struct ParsingResult));
  1452. result.result = PASS;
  1453. if(strstr((char*)data, ".") != NULL)
  1454. {
  1455. // Original data with mini second
  1456. if(strstr((char*)data, "Z") != NULL)
  1457. {
  1458. // Original data with Z
  1459. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1460. &result.year,
  1461. &result.month,
  1462. &result.mday,
  1463. &result.hour,
  1464. &result.min,
  1465. &result.sec,
  1466. &result.minSec);
  1467. }
  1468. else
  1469. {
  1470. // Original data without Z
  1471. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1472. &result.year,
  1473. &result.month,
  1474. &result.mday,
  1475. &result.hour,
  1476. &result.min,
  1477. &result.sec,
  1478. &result.minSec,
  1479. &result.tz_hour,
  1480. &result.tz_min);
  1481. }
  1482. }
  1483. else
  1484. {
  1485. // Original data without mini second
  1486. if(strstr((char*)data, "Z") != NULL)
  1487. {
  1488. // Original data with Z
  1489. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1490. &result.year,
  1491. &result.month,
  1492. &result.mday,
  1493. &result.hour,
  1494. &result.min,
  1495. &result.sec);
  1496. }
  1497. else
  1498. {
  1499. // Original data without Z
  1500. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1501. &result.year,
  1502. &result.month,
  1503. &result.mday,
  1504. &result.hour,
  1505. &result.min,
  1506. &result.sec,
  1507. &result.tz_hour,
  1508. &result.tz_min);
  1509. }
  1510. }
  1511. tmOrg.tm_year = result.year - 1900;
  1512. tmOrg.tm_mon = result.month - 1;
  1513. tmOrg.tm_mday = result.mday;
  1514. tmOrg.tm_hour = result.hour;
  1515. tmOrg.tm_min = result.min;
  1516. tmOrg.tm_sec = result.sec;
  1517. tmOrg.tm_gmtoff = 0;
  1518. tbTarget.time = mktime(&tmOrg);
  1519. tbTarget.timezone = 0;
  1520. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1521. tmTarget = gmtime(&tbTarget.time);
  1522. 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);
  1523. //DEBUG_INFO(" org date time: %s\n", data);
  1524. //DEBUG_INFO("parse date time: %s\n", buf);
  1525. system(buf);
  1526. system("/sbin/hwclock -w --systohc");
  1527. if(result.scanedElement < 6)
  1528. result.result = FAIL;
  1529. return result.result;
  1530. }
  1531. //==========================================
  1532. // Parse certificate content
  1533. //==========================================
  1534. int parseCertInfo(char *certPath, int parseType, char *data)
  1535. {
  1536. int result = FAIL;
  1537. int count = 0;
  1538. int showupLine = 0;
  1539. memset(data, 0, ARRAY_SIZE(data));
  1540. if(access(certPath,F_OK) != -1)
  1541. {
  1542. char temp[512] = {0};
  1543. char capturedData[256] = {0};
  1544. char hashType[10] = "SHA256";
  1545. FILE *fp;
  1546. // Need to get hash type first
  1547. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1548. fp = popen(temp, "r");
  1549. if(fp)
  1550. {
  1551. while(fgets(temp, sizeof(temp), fp) != NULL)
  1552. {
  1553. if(strstr(temp, "Signature Algorithm:") != NULL)
  1554. {
  1555. result = PASS;
  1556. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1557. sprintf((char*)hashType, "SHA256");
  1558. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1559. sprintf((char*)hashType, "SHA384");
  1560. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1561. sprintf((char*)hashType, "SHA512");
  1562. else
  1563. {
  1564. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1565. result = FAIL;
  1566. }
  1567. break;
  1568. }
  1569. }
  1570. }
  1571. switch(parseType)
  1572. {
  1573. case CERT_PARSE_HashAlgorithm:
  1574. sprintf((char*)data, hashType);
  1575. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1576. break;
  1577. case CERT_PARSE_SerialNumber:
  1578. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1579. fp = popen(temp, "r");
  1580. if(fp)
  1581. {
  1582. while(fgets(temp, sizeof(temp), fp) != NULL)
  1583. {
  1584. if(strstr(temp, "serial=") != NULL)
  1585. {
  1586. sscanf(temp, "%*[^=]=%s", capturedData);
  1587. result = PASS;
  1588. break;
  1589. }
  1590. }
  1591. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1592. sprintf((char*)data, capturedData);
  1593. }
  1594. break;
  1595. case CERT_PARSE_IssuerNameHash:
  1596. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1597. fp = popen(temp, "r");
  1598. if(fp)
  1599. {
  1600. while(fgets(temp, sizeof(temp), fp) != NULL)
  1601. {
  1602. if(strstr(temp, "SEQUENCE") != NULL)
  1603. {
  1604. count++;
  1605. if(count==4)
  1606. {
  1607. sscanf(temp, "%[^:]", capturedData);
  1608. showupLine = atoi(capturedData);
  1609. break;
  1610. }
  1611. }
  1612. }
  1613. }
  1614. if(showupLine > 0)
  1615. {
  1616. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerNameHash", certPath, showupLine);
  1617. system(temp);
  1618. }
  1619. else
  1620. {
  1621. break;
  1622. }
  1623. if(access("/Storage/OCPP/IssuerNameHash",F_OK) != -1)
  1624. {
  1625. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerNameHash", (char*)hashType);
  1626. fp = popen(temp, "r");
  1627. if(fp)
  1628. {
  1629. while(fgets(temp, sizeof(temp), fp) != NULL)
  1630. {
  1631. if(strstr(temp, "(stdin)=") != NULL)
  1632. {
  1633. sscanf(temp, "%*[^=]=%s", capturedData);
  1634. result = PASS;
  1635. break;
  1636. }
  1637. }
  1638. stringtrimspace(capturedData);
  1639. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1640. sprintf((char*)data, capturedData);
  1641. }
  1642. }
  1643. break;
  1644. case CERT_PARSE_IssuerKeyHash:
  1645. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1646. fp = popen(temp, "r");
  1647. if(fp)
  1648. {
  1649. while(fgets(temp, sizeof(temp), fp) != NULL)
  1650. {
  1651. if(strstr(temp, "BIT STRING") != NULL)
  1652. {
  1653. sscanf(temp, "%[^:]", capturedData);
  1654. showupLine = atoi(capturedData);
  1655. break;
  1656. }
  1657. }
  1658. }
  1659. if(showupLine > 0)
  1660. {
  1661. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerKeyHash", certPath, showupLine);
  1662. system(temp);
  1663. }
  1664. else
  1665. {
  1666. break;
  1667. }
  1668. if(access("/Storage/OCPP/IssuerKeyHash",F_OK) != -1)
  1669. {
  1670. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerKeyHash", (char*)hashType);
  1671. fp = popen(temp, "r");
  1672. if(fp)
  1673. {
  1674. while(fgets(temp, sizeof(temp), fp) != NULL)
  1675. {
  1676. if(strstr(temp, "(stdin)=") != NULL)
  1677. {
  1678. sscanf(temp, "%*[^=]=%s", capturedData);
  1679. result = PASS;
  1680. break;
  1681. }
  1682. }
  1683. stringtrimspace(capturedData);
  1684. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1685. sprintf((char*)data, capturedData);
  1686. }
  1687. }
  1688. break;
  1689. case CERT_PARSE_OcspUrl:
  1690. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1691. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1692. fp = popen(temp, "r");
  1693. if(fp)
  1694. {
  1695. while(fgets(temp, sizeof(temp), fp) != NULL)
  1696. {
  1697. if(strstr(temp, "OCSP - URI:") != NULL)
  1698. {
  1699. //strcpy((char*)data, temp);
  1700. sscanf(temp, "%*[^:]:%s", capturedData);
  1701. sprintf((char*)data, capturedData);
  1702. DEBUG_INFO("OCSP_URI: %s\n", data);
  1703. result = PASS;
  1704. break;
  1705. }
  1706. }
  1707. }
  1708. break;
  1709. default:
  1710. DEBUG_INFO("Parse type is invalid.\n");
  1711. break;
  1712. }
  1713. pclose(fp);
  1714. }
  1715. return result;
  1716. }
  1717. //==========================================
  1718. // GetCompositeSchedule logic related function
  1719. //==========================================
  1720. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1721. {
  1722. //return milli-second
  1723. unsigned int StartTime,StopTime;
  1724. StartTime=(unsigned int)ST.time;
  1725. StopTime=(unsigned int)ET.time;
  1726. return (StopTime-StartTime);
  1727. }
  1728. int DiffTimebWithNowSec(struct timeb ST)
  1729. {
  1730. //return milli-second
  1731. struct timeb ET;
  1732. unsigned int StartTime,StopTime;
  1733. ftime(&ET);
  1734. StartTime=(unsigned int)ST.time;
  1735. StopTime=(unsigned int)ET.time;
  1736. return (StopTime-StartTime);
  1737. }
  1738. int getStartStop(uint8_t *start, uint8_t *stop)
  1739. {
  1740. struct ParsingResult
  1741. {
  1742. int result;
  1743. int scanedElement;
  1744. int year;
  1745. int month;
  1746. int mday;
  1747. int hour;
  1748. int min;
  1749. int sec;
  1750. int tz_hour;
  1751. int tz_min;
  1752. float minSec;
  1753. };
  1754. struct ParsingResult parseStart;
  1755. struct ParsingResult parseStop;
  1756. int result = -1;
  1757. struct tm tmStart;
  1758. struct timeb tbStart;
  1759. struct tm tmStop;
  1760. struct timeb tbStop;
  1761. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1762. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1763. // Scan start & stop date time
  1764. if(strstr((char*)start, ".") != NULL)
  1765. {
  1766. // Original data with mini second
  1767. if(strstr((char*)start, "Z") != NULL)
  1768. {
  1769. // Original data with Z
  1770. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1771. &parseStart.year,
  1772. &parseStart.month,
  1773. &parseStart.mday,
  1774. &parseStart.hour,
  1775. &parseStart.min,
  1776. &parseStart.sec,
  1777. &parseStart.minSec);
  1778. }
  1779. else
  1780. {
  1781. // Original data without Z
  1782. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1783. &parseStart.year,
  1784. &parseStart.month,
  1785. &parseStart.mday,
  1786. &parseStart.hour,
  1787. &parseStart.min,
  1788. &parseStart.sec,
  1789. &parseStart.minSec,
  1790. &parseStart.tz_hour,
  1791. &parseStart.tz_min);
  1792. }
  1793. }
  1794. else
  1795. {
  1796. // Original data without mini second
  1797. if(strstr((char*)start, "Z") != NULL)
  1798. {
  1799. // Original data with Z
  1800. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1801. &parseStart.year,
  1802. &parseStart.month,
  1803. &parseStart.mday,
  1804. &parseStart.hour,
  1805. &parseStart.min,
  1806. &parseStart.sec);
  1807. }
  1808. else
  1809. {
  1810. // Original data without Z
  1811. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1812. &parseStart.year,
  1813. &parseStart.month,
  1814. &parseStart.mday,
  1815. &parseStart.hour,
  1816. &parseStart.min,
  1817. &parseStart.sec,
  1818. &parseStart.tz_hour,
  1819. &parseStart.tz_min);
  1820. }
  1821. }
  1822. if(strstr((char*)stop, ".") != NULL)
  1823. {
  1824. // Original data with mini second
  1825. if(strstr((char*)stop, "Z") != NULL)
  1826. {
  1827. // Original data with Z
  1828. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1829. &parseStop.year,
  1830. &parseStop.month,
  1831. &parseStop.mday,
  1832. &parseStop.hour,
  1833. &parseStop.min,
  1834. &parseStop.sec,
  1835. &parseStop.minSec);
  1836. }
  1837. else
  1838. {
  1839. // Original data without Z
  1840. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1841. &parseStop.year,
  1842. &parseStop.month,
  1843. &parseStop.mday,
  1844. &parseStop.hour,
  1845. &parseStop.min,
  1846. &parseStop.sec,
  1847. &parseStop.minSec,
  1848. &parseStop.tz_hour,
  1849. &parseStop.tz_min);
  1850. }
  1851. }
  1852. else
  1853. {
  1854. // Original data without mini second
  1855. if(strstr((char*)stop, "Z") != NULL)
  1856. {
  1857. // Original data with Z
  1858. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1859. &parseStop.year,
  1860. &parseStop.month,
  1861. &parseStop.mday,
  1862. &parseStop.hour,
  1863. &parseStop.min,
  1864. &parseStop.sec);
  1865. }
  1866. else
  1867. {
  1868. // Original data without Z
  1869. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1870. &parseStop.year,
  1871. &parseStop.month,
  1872. &parseStop.mday,
  1873. &parseStop.hour,
  1874. &parseStop.min,
  1875. &parseStop.sec,
  1876. &parseStop.tz_hour,
  1877. &parseStop.tz_min);
  1878. }
  1879. }
  1880. // Calculate date time difference
  1881. if((parseStart.scanedElement >=6) &&
  1882. (parseStop.scanedElement >=6))
  1883. {
  1884. //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);
  1885. //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);
  1886. tmStart.tm_year = parseStart.year - 1900;
  1887. tmStart.tm_mon = parseStart.month - 1;
  1888. tmStart.tm_mday = parseStart.mday;
  1889. tmStart.tm_hour = parseStart.hour;
  1890. tmStart.tm_min = parseStart.min;
  1891. tmStart.tm_sec = parseStart.sec;
  1892. tmStart.tm_gmtoff = 0;
  1893. tbStart.time = mktime(&tmStart);
  1894. tbStart.timezone = 0;
  1895. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1896. tmStop.tm_year = parseStop.year - 1900;
  1897. tmStop.tm_mon = parseStop.month - 1;
  1898. tmStop.tm_mday = parseStop.mday;
  1899. tmStop.tm_hour = parseStop.hour;
  1900. tmStop.tm_min = parseStop.min;
  1901. tmStop.tm_sec = parseStop.sec;
  1902. tmStop.tm_gmtoff = 0;
  1903. tbStop.time = mktime(&tmStop);
  1904. tbStop.timezone = 0;
  1905. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1906. result = DiffTimebSec(tbStart, tbStop);
  1907. //DEBUG_INFO("getStartStop(): %d\n", result);
  1908. }
  1909. else
  1910. {
  1911. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1912. }
  1913. return result;
  1914. }
  1915. int isOvertNow(uint8_t *start)
  1916. {
  1917. int result = NO;
  1918. struct ParsingResult
  1919. {
  1920. int result;
  1921. int scanedElement;
  1922. int year;
  1923. int month;
  1924. int mday;
  1925. int hour;
  1926. int min;
  1927. int sec;
  1928. int tz_hour;
  1929. int tz_min;
  1930. float minSec;
  1931. }parsingResult;
  1932. struct tm tmStart;
  1933. struct timeb tbStart;
  1934. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1935. if(strstr((char*)start, ".") != NULL)
  1936. {
  1937. // Original data with mini second
  1938. if(strstr((char*)start, "Z") != NULL)
  1939. {
  1940. // Original data with Z
  1941. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1942. &parsingResult.year,
  1943. &parsingResult.month,
  1944. &parsingResult.mday,
  1945. &parsingResult.hour,
  1946. &parsingResult.min,
  1947. &parsingResult.sec,
  1948. &parsingResult.minSec);
  1949. }
  1950. else
  1951. {
  1952. // Original data without Z
  1953. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1954. &parsingResult.year,
  1955. &parsingResult.month,
  1956. &parsingResult.mday,
  1957. &parsingResult.hour,
  1958. &parsingResult.min,
  1959. &parsingResult.sec,
  1960. &parsingResult.minSec,
  1961. &parsingResult.tz_hour,
  1962. &parsingResult.tz_min);
  1963. }
  1964. }
  1965. else
  1966. {
  1967. // Original data without mini second
  1968. if(strstr((char*)start, "Z") != NULL)
  1969. {
  1970. // Original data with Z
  1971. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1972. &parsingResult.year,
  1973. &parsingResult.month,
  1974. &parsingResult.mday,
  1975. &parsingResult.hour,
  1976. &parsingResult.min,
  1977. &parsingResult.sec);
  1978. }
  1979. else
  1980. {
  1981. // Original data without Z
  1982. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1983. &parsingResult.year,
  1984. &parsingResult.month,
  1985. &parsingResult.mday,
  1986. &parsingResult.hour,
  1987. &parsingResult.min,
  1988. &parsingResult.sec,
  1989. &parsingResult.tz_hour,
  1990. &parsingResult.tz_min);
  1991. }
  1992. }
  1993. if(parsingResult.scanedElement >= 6)
  1994. {
  1995. tmStart.tm_year = parsingResult.year - 1900;
  1996. tmStart.tm_mon = parsingResult.month - 1;
  1997. tmStart.tm_mday = parsingResult.mday;
  1998. tmStart.tm_hour = parsingResult.hour;
  1999. tmStart.tm_min = parsingResult.min;
  2000. tmStart.tm_sec = parsingResult.sec;
  2001. tmStart.tm_gmtoff = 0;
  2002. tbStart.time = mktime(&tmStart);
  2003. tbStart.timezone = 0;
  2004. tbStart.millitm = 0;
  2005. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  2006. if(DiffTimebWithNowSec(tbStart) <= 0)
  2007. result = NO;
  2008. else
  2009. result = YES;
  2010. }
  2011. else
  2012. {
  2013. DEBUG_WARN("Start date parsing error.\n");
  2014. }
  2015. return result;
  2016. }
  2017. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2018. {
  2019. struct ParsingResult
  2020. {
  2021. int result;
  2022. int scanedElement;
  2023. int year;
  2024. int month;
  2025. int mday;
  2026. int hour;
  2027. int min;
  2028. int sec;
  2029. int tz_hour;
  2030. int tz_min;
  2031. float minSec;
  2032. };
  2033. struct ParsingResult parseStart;
  2034. struct ParsingResult parseStop;
  2035. int result = -1;
  2036. struct tm tmStart;
  2037. struct timeb tbStart;
  2038. struct tm tmStop;
  2039. struct timeb tbStop;
  2040. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  2041. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  2042. // Scan start & stop date time
  2043. if(strstr((char*)start, ".") != NULL)
  2044. {
  2045. // Original data with mini second
  2046. if(strstr((char*)start, "Z") != NULL)
  2047. {
  2048. // Original data with Z
  2049. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  2050. &parseStart.year,
  2051. &parseStart.month,
  2052. &parseStart.mday,
  2053. &parseStart.hour,
  2054. &parseStart.min,
  2055. &parseStart.sec,
  2056. &parseStart.minSec);
  2057. }
  2058. else
  2059. {
  2060. // Original data without Z
  2061. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2062. &parseStart.year,
  2063. &parseStart.month,
  2064. &parseStart.mday,
  2065. &parseStart.hour,
  2066. &parseStart.min,
  2067. &parseStart.sec,
  2068. &parseStart.minSec,
  2069. &parseStart.tz_hour,
  2070. &parseStart.tz_min);
  2071. }
  2072. }
  2073. else
  2074. {
  2075. // Original data without mini second
  2076. if(strstr((char*)start, "Z") != NULL)
  2077. {
  2078. // Original data with Z
  2079. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  2080. &parseStart.year,
  2081. &parseStart.month,
  2082. &parseStart.mday,
  2083. &parseStart.hour,
  2084. &parseStart.min,
  2085. &parseStart.sec);
  2086. }
  2087. else
  2088. {
  2089. // Original data without Z
  2090. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  2091. &parseStart.year,
  2092. &parseStart.month,
  2093. &parseStart.mday,
  2094. &parseStart.hour,
  2095. &parseStart.min,
  2096. &parseStart.sec,
  2097. &parseStart.tz_hour,
  2098. &parseStart.tz_min);
  2099. }
  2100. }
  2101. if(strstr((char*)stop, ".") != NULL)
  2102. {
  2103. // Original data with mini second
  2104. if(strstr((char*)stop, "Z") != NULL)
  2105. {
  2106. // Original data with Z
  2107. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  2108. &parseStop.year,
  2109. &parseStop.month,
  2110. &parseStop.mday,
  2111. &parseStop.hour,
  2112. &parseStop.min,
  2113. &parseStop.sec,
  2114. &parseStop.minSec);
  2115. }
  2116. else
  2117. {
  2118. // Original data without Z
  2119. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2120. &parseStop.year,
  2121. &parseStop.month,
  2122. &parseStop.mday,
  2123. &parseStop.hour,
  2124. &parseStop.min,
  2125. &parseStop.sec,
  2126. &parseStop.minSec,
  2127. &parseStop.tz_hour,
  2128. &parseStop.tz_min);
  2129. }
  2130. }
  2131. else
  2132. {
  2133. // Original data without mini second
  2134. if(strstr((char*)stop, "Z") != NULL)
  2135. {
  2136. // Original data with Z
  2137. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  2138. &parseStop.year,
  2139. &parseStop.month,
  2140. &parseStop.mday,
  2141. &parseStop.hour,
  2142. &parseStop.min,
  2143. &parseStop.sec);
  2144. }
  2145. else
  2146. {
  2147. // Original data without Z
  2148. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  2149. &parseStop.year,
  2150. &parseStop.month,
  2151. &parseStop.mday,
  2152. &parseStop.hour,
  2153. &parseStop.min,
  2154. &parseStop.sec,
  2155. &parseStop.tz_hour,
  2156. &parseStop.tz_min);
  2157. }
  2158. }
  2159. // Calculate date time difference
  2160. if((parseStart.scanedElement >=6) &&
  2161. (parseStop.scanedElement >=6))
  2162. {
  2163. //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);
  2164. //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);
  2165. tmStart.tm_year = parseStart.year - 1900;
  2166. tmStart.tm_mon = parseStart.month - 1;
  2167. tmStart.tm_mday = parseStart.mday;
  2168. tmStart.tm_hour = parseStart.hour;
  2169. tmStart.tm_min = parseStart.min;
  2170. tmStart.tm_sec = parseStart.sec;
  2171. tmStart.tm_gmtoff = 0;
  2172. tbStart.time = mktime(&tmStart);
  2173. tbStart.timezone = 0;
  2174. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  2175. tmStop.tm_year = parseStop.year - 1900;
  2176. tmStop.tm_mon = parseStop.month - 1;
  2177. tmStop.tm_mday = parseStop.mday;
  2178. tmStop.tm_hour = parseStop.hour;
  2179. tmStop.tm_min = parseStop.min;
  2180. tmStop.tm_sec = parseStop.sec;
  2181. tmStop.tm_gmtoff = 0;
  2182. tbStop.time = mktime(&tmStop);
  2183. tbStop.timezone = 0;
  2184. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  2185. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2186. //DEBUG_INFO("getStartStop(): %d\n", result);
  2187. }
  2188. else
  2189. {
  2190. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2191. }
  2192. return result;
  2193. }
  2194. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2195. {
  2196. FILE *fp;
  2197. char profileFileName[128];
  2198. char *line = NULL;
  2199. size_t len = 0;
  2200. time_t CurrentTime;
  2201. struct tm *tmComposite;
  2202. struct StructChargingProfile maxProfile;
  2203. struct StructChargingProfile compositeProfile;
  2204. uint8_t limitMax=0;
  2205. int compositePeriodIdx = 0;
  2206. //uint8_t isDurationNull = FALSE;
  2207. CurrentTime = time(NULL);
  2208. tmComposite=localtime(&CurrentTime);
  2209. 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);
  2210. if(isUnitA)
  2211. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2212. else
  2213. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2214. compositeProfile.ChargingSchedule.Duration = durationReq;
  2215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2216. {
  2217. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2218. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2219. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2220. }
  2221. compositeProfile.ChargingProfileId = 0;
  2222. compositeProfile.StackLevel = 99 ;
  2223. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2224. maxProfile.ChargingProfileId = -1;
  2225. maxProfile.ChargingSchedule.Duration = -1;
  2226. system("rm -f /tmp/*.json");
  2227. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2228. // Search max profile
  2229. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2230. if((access(profileFileName, F_OK))!=-1)
  2231. {
  2232. fp = fopen(profileFileName, "r");
  2233. while(getline(&line, &len, fp) != -1)
  2234. {
  2235. json_object *obj = NULL;
  2236. obj = json_tokener_parse(line);
  2237. if(is_error(obj))
  2238. {
  2239. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2240. }
  2241. else
  2242. {
  2243. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2244. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2245. )
  2246. {
  2247. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2248. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2249. )
  2250. {
  2251. struct tm tmFrom, tmTo;
  2252. struct timeb tbFrom, tbTo;
  2253. 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) &&
  2254. (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))
  2255. {
  2256. tmFrom.tm_year -= 1900;
  2257. tmFrom.tm_mon -= 1;
  2258. tbFrom.time = mktime(&tmFrom);
  2259. tmTo.tm_year -= 1900;
  2260. tmTo.tm_mon -= 1;
  2261. tbTo.time = mktime(&tmTo);
  2262. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2263. {
  2264. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2265. {
  2266. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2267. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2268. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2269. }
  2270. if(maxProfile.ChargingProfileId == -1)
  2271. DEBUG_INFO("MaxProfile found.\n");
  2272. else
  2273. DEBUG_INFO("MaxProfile updated.\n");
  2274. // Required item
  2275. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2276. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2277. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2278. if(isUnitA)
  2279. {
  2280. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2281. 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++)
  2282. {
  2283. 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"));
  2284. 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?
  2285. 3:
  2286. 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")));
  2287. 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")));
  2288. }
  2289. }
  2290. else
  2291. {
  2292. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2293. 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++)
  2294. {
  2295. 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"));
  2296. 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?
  2297. 3:
  2298. 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")));
  2299. 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));
  2300. }
  2301. }
  2302. // Optional item
  2303. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2304. {
  2305. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2306. }
  2307. else
  2308. {
  2309. sprintf((char*)maxProfile.ValidFrom, " ");
  2310. }
  2311. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2312. {
  2313. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2314. }
  2315. else
  2316. {
  2317. sprintf((char*)maxProfile.ValidTo, " ");
  2318. }
  2319. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2320. {
  2321. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2322. }
  2323. else
  2324. {
  2325. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2326. }
  2327. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2328. {
  2329. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2330. }
  2331. else
  2332. {
  2333. maxProfile.TransactionId = -1;
  2334. }
  2335. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2336. {
  2337. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2338. }
  2339. else
  2340. {
  2341. maxProfile.ChargingSchedule.Duration = 86400;
  2342. //isDurationNull = TRUE;
  2343. }
  2344. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2345. {
  2346. 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")));
  2347. }
  2348. else
  2349. {
  2350. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2351. }
  2352. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2353. {
  2354. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2355. }
  2356. else
  2357. {
  2358. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2359. }
  2360. }
  2361. }
  2362. }
  2363. else
  2364. {
  2365. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2366. {
  2367. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2368. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2369. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2370. }
  2371. if(maxProfile.ChargingProfileId == -1)
  2372. DEBUG_INFO("MaxProfile found.\n");
  2373. else
  2374. DEBUG_INFO("MaxProfile updated.\n");
  2375. // Required item
  2376. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2377. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2378. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2379. if(isUnitA)
  2380. {
  2381. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2382. 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++)
  2383. {
  2384. 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"));
  2385. 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?
  2386. 3:
  2387. 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")));
  2388. 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")));
  2389. }
  2390. }
  2391. else
  2392. {
  2393. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2394. 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++)
  2395. {
  2396. 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"));
  2397. 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?
  2398. 3:
  2399. 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")));
  2400. 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));
  2401. }
  2402. }
  2403. // Optional item
  2404. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2405. {
  2406. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2407. }
  2408. else
  2409. {
  2410. sprintf((char*)maxProfile.ValidFrom, " ");
  2411. }
  2412. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2413. {
  2414. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2415. }
  2416. else
  2417. {
  2418. sprintf((char*)maxProfile.ValidTo, " ");
  2419. }
  2420. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2421. {
  2422. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2423. }
  2424. else
  2425. {
  2426. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2427. }
  2428. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2429. {
  2430. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2431. }
  2432. else
  2433. {
  2434. maxProfile.TransactionId = -1;
  2435. }
  2436. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2437. {
  2438. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2439. }
  2440. else
  2441. {
  2442. maxProfile.ChargingSchedule.Duration = 86400;
  2443. //isDurationNull = TRUE;
  2444. }
  2445. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2446. {
  2447. 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")));
  2448. }
  2449. else
  2450. {
  2451. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2452. }
  2453. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2454. {
  2455. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2456. }
  2457. else
  2458. {
  2459. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2460. }
  2461. }
  2462. }
  2463. }
  2464. json_object_put(obj);
  2465. }
  2466. fclose(fp);
  2467. /*
  2468. if(maxProfile.ChargingProfileId !=-1)
  2469. {
  2470. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2471. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2472. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2473. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2474. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2475. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2476. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2477. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2478. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2479. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2480. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2481. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2482. {
  2483. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2484. {
  2485. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2486. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2487. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2488. }
  2489. }
  2490. }
  2491. else
  2492. DEBUG_INFO("MaxProfile not found.\n");
  2493. DEBUG_INFO("------------------------------------\n");*/
  2494. }
  2495. if(maxProfile.ChargingProfileId != -1)
  2496. {
  2497. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2498. {
  2499. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2500. {
  2501. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2502. 0:
  2503. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2504. }
  2505. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2506. {
  2507. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2508. {
  2509. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2510. 0:
  2511. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2512. if(idxPeriod > 0)
  2513. {
  2514. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2515. {
  2516. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2523. {
  2524. if(maxProfile.ChargingSchedule.Duration != -1)
  2525. {
  2526. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2527. }
  2528. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2529. {
  2530. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2531. {
  2532. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2533. if(idxPeriod > 0)
  2534. {
  2535. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2536. {
  2537. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2538. }
  2539. }
  2540. }
  2541. }
  2542. }
  2543. else
  2544. {
  2545. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2546. {
  2547. if(maxProfile.ChargingSchedule.Duration != -1)
  2548. {
  2549. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2550. 0:
  2551. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2552. }
  2553. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2554. {
  2555. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2556. {
  2557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2558. 0:
  2559. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2560. if(idxPeriod > 0)
  2561. {
  2562. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2563. {
  2564. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2565. }
  2566. }
  2567. }
  2568. }
  2569. }
  2570. else
  2571. {
  2572. if(maxProfile.ChargingSchedule.Duration != -1)
  2573. {
  2574. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2575. 0:
  2576. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2577. }
  2578. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2579. {
  2580. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2581. {
  2582. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2583. 0:
  2584. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2585. if(idxPeriod > 0)
  2586. {
  2587. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2588. {
  2589. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2590. }
  2591. }
  2592. }
  2593. }
  2594. }
  2595. }
  2596. /*
  2597. DEBUG_INFO("MaxProfile after align.\n");
  2598. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2599. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2600. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2601. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2602. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2603. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2604. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2605. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2606. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2607. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2608. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2609. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2610. {
  2611. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2612. {
  2613. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2614. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2615. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2616. }
  2617. }
  2618. DEBUG_INFO("------------------------------------\n");*/
  2619. }
  2620. // Find each profile period quantity
  2621. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2622. {
  2623. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2624. limitMax = idx+1;
  2625. }
  2626. if(maxProfile.ChargingProfileId != -1)
  2627. {
  2628. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2629. {
  2630. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2632. (maxProfile.ChargingSchedule.Duration > 0))
  2633. {
  2634. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2635. {
  2636. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2637. compositePeriodIdx++;
  2638. }
  2639. else
  2640. {
  2641. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2642. }
  2643. }
  2644. }
  2645. }
  2646. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2647. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2648. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2649. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2650. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2651. {
  2652. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2653. {
  2654. compositeProfile.ChargingProfileId = 1;
  2655. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2656. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2657. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2658. }
  2659. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2660. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2661. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2662. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2663. }
  2664. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2665. if(line)
  2666. free(line);
  2667. }
  2668. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2669. {
  2670. FILE *fp;
  2671. char profileFileName[128];
  2672. char *line = NULL;
  2673. size_t len = 0;
  2674. time_t CurrentTime;
  2675. struct tm *tmComposite;
  2676. struct StructChargingProfile maxProfile;
  2677. struct StructChargingProfile defaultTxProfile;
  2678. struct StructChargingProfile txProfile;
  2679. struct StructChargingProfile compositeProfile;
  2680. struct StructChargingSchedulePeriod tmpPeriod;
  2681. uint8_t limitMax=0;
  2682. uint8_t limitDef=0;
  2683. uint8_t limitTx=0;
  2684. int compositePeriodIdx = 0;
  2685. CurrentTime = time(NULL);
  2686. tmComposite=localtime(&CurrentTime);
  2687. 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);
  2688. if(isUnitA)
  2689. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2690. else
  2691. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2692. compositeProfile.ChargingSchedule.Duration = durationReq;
  2693. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2694. {
  2695. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2696. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2697. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2698. }
  2699. compositeProfile.ChargingProfileId = 0;
  2700. compositeProfile.StackLevel = 99 ;
  2701. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2702. maxProfile.ChargingProfileId = -1;
  2703. defaultTxProfile.ChargingProfileId = -1;
  2704. txProfile.ChargingProfileId = -1;
  2705. maxProfile.ChargingSchedule.Duration = -1;
  2706. defaultTxProfile.ChargingSchedule.Duration = -1;
  2707. txProfile.ChargingSchedule.Duration = -1;
  2708. system("rm -f /tmp/*.json");
  2709. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2710. /*
  2711. * Search valid charging profile
  2712. */
  2713. //DEBUG_INFO("====================================\n");
  2714. // Search tx profile
  2715. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2716. if((access(profileFileName, F_OK))!=-1)
  2717. {
  2718. fp = fopen(profileFileName, "r");
  2719. while(getline(&line, &len, fp) != -1)
  2720. {
  2721. json_object *obj = NULL;
  2722. obj = json_tokener_parse(line);
  2723. if(is_error(obj))
  2724. {
  2725. DEBUG_ERROR("Parse txProfile from file error.\n");
  2726. }
  2727. else
  2728. {
  2729. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2730. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2731. )
  2732. {
  2733. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2734. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2735. )
  2736. {
  2737. struct tm tmFrom, tmTo;
  2738. struct timeb tbFrom, tbTo;
  2739. 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) &&
  2740. (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))
  2741. {
  2742. tmFrom.tm_year -= 1900;
  2743. tmFrom.tm_mon -= 1;
  2744. tbFrom.time = mktime(&tmFrom);
  2745. tmTo.tm_year -= 1900;
  2746. tmTo.tm_mon -= 1;
  2747. tbTo.time = mktime(&tmTo);
  2748. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2749. {
  2750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2751. {
  2752. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2755. }
  2756. if(txProfile.ChargingProfileId == -1)
  2757. DEBUG_INFO("TxProfile found.\n");
  2758. else
  2759. DEBUG_INFO("TxProfile updated.\n");
  2760. // Required item
  2761. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2762. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2763. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2764. if(isUnitA)
  2765. {
  2766. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2767. 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++)
  2768. {
  2769. 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"));
  2770. 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?
  2771. 3:
  2772. 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")));
  2773. 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")));
  2774. }
  2775. }
  2776. else
  2777. {
  2778. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2779. 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++)
  2780. {
  2781. 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"));
  2782. 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?
  2783. 3:
  2784. 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")));
  2785. 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));
  2786. }
  2787. }
  2788. // Optional item
  2789. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2790. {
  2791. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2792. }
  2793. else
  2794. {
  2795. sprintf((char*)txProfile.ValidFrom, " ");
  2796. }
  2797. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2798. {
  2799. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2800. }
  2801. else
  2802. {
  2803. sprintf((char*)txProfile.ValidTo, " ");
  2804. }
  2805. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2806. {
  2807. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2808. }
  2809. else
  2810. {
  2811. sprintf((char*)txProfile.RecurrencyKind, " ");
  2812. }
  2813. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2814. {
  2815. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2816. }
  2817. else
  2818. {
  2819. txProfile.TransactionId = -1;
  2820. }
  2821. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2822. {
  2823. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2824. }
  2825. else
  2826. {
  2827. txProfile.ChargingSchedule.Duration = 86400;
  2828. }
  2829. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2830. {
  2831. 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")));
  2832. }
  2833. else
  2834. {
  2835. 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));
  2836. }
  2837. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2838. {
  2839. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2840. }
  2841. else
  2842. {
  2843. txProfile.ChargingSchedule.MinChargingRate = -1;
  2844. }
  2845. }
  2846. }
  2847. }
  2848. else
  2849. {
  2850. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2851. {
  2852. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2853. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2854. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2855. }
  2856. if(txProfile.ChargingProfileId == -1)
  2857. DEBUG_INFO("TxProfile found.\n");
  2858. else
  2859. DEBUG_INFO("TxProfile updated.\n");
  2860. // Required item
  2861. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2862. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2863. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2864. if(isUnitA)
  2865. {
  2866. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2867. 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++)
  2868. {
  2869. 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"));
  2870. 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?
  2871. 3:
  2872. 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")));
  2873. 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")));
  2874. }
  2875. }
  2876. else
  2877. {
  2878. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2879. 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++)
  2880. {
  2881. 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"));
  2882. 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?
  2883. 3:
  2884. 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")));
  2885. 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));
  2886. }
  2887. }
  2888. // Optional item
  2889. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2890. {
  2891. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2892. }
  2893. else
  2894. {
  2895. sprintf((char*)txProfile.ValidFrom, " ");
  2896. }
  2897. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2898. {
  2899. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2900. }
  2901. else
  2902. {
  2903. sprintf((char*)txProfile.ValidTo, " ");
  2904. }
  2905. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2906. {
  2907. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2908. }
  2909. else
  2910. {
  2911. sprintf((char*)txProfile.RecurrencyKind, " ");
  2912. }
  2913. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2914. {
  2915. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2916. }
  2917. else
  2918. {
  2919. txProfile.TransactionId = -1;
  2920. }
  2921. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2922. {
  2923. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2924. }
  2925. else
  2926. {
  2927. txProfile.ChargingSchedule.Duration = 86400;
  2928. }
  2929. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2930. {
  2931. 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")));
  2932. }
  2933. else
  2934. {
  2935. 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));
  2936. }
  2937. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2938. {
  2939. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2940. }
  2941. else
  2942. {
  2943. txProfile.ChargingSchedule.MinChargingRate = -1;
  2944. }
  2945. }
  2946. }
  2947. }
  2948. json_object_put(obj);
  2949. }
  2950. fclose(fp);
  2951. /*
  2952. if(txProfile.ChargingProfileId != -1)
  2953. {
  2954. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2955. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2956. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2957. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2958. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2959. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2960. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2961. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2962. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2963. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2964. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2965. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2966. {
  2967. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2968. {
  2969. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2970. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2971. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2972. }
  2973. }
  2974. }
  2975. else
  2976. DEBUG_INFO("TxProfile not found.\n");*/
  2977. }
  2978. // Search default tx profile
  2979. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2980. if((access(profileFileName, F_OK))==-1)
  2981. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2982. if((access(profileFileName, F_OK))!=-1)
  2983. {
  2984. fp = fopen(profileFileName, "r");
  2985. while(getline(&line, &len, fp) != -1)
  2986. {
  2987. json_object *obj = NULL;
  2988. obj = json_tokener_parse(line);
  2989. if(is_error(obj))
  2990. {
  2991. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2992. }
  2993. else
  2994. {
  2995. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2996. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2997. )
  2998. {
  2999. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3000. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3001. )
  3002. {
  3003. struct tm tmFrom, tmTo;
  3004. struct timeb tbFrom, tbTo;
  3005. 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) &&
  3006. (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))
  3007. {
  3008. tmFrom.tm_year -= 1900;
  3009. tmFrom.tm_mon -= 1;
  3010. tbFrom.time = mktime(&tmFrom);
  3011. tmTo.tm_year -= 1900;
  3012. tmTo.tm_mon -= 1;
  3013. tbTo.time = mktime(&tmTo);
  3014. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3015. {
  3016. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3017. {
  3018. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3019. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3020. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3021. }
  3022. if(defaultTxProfile.ChargingProfileId == -1)
  3023. DEBUG_INFO("TxDefaultProfile found.\n");
  3024. else
  3025. DEBUG_INFO("TxDefaultProfile updated.\n");
  3026. // Required item
  3027. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3028. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3029. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3030. if(isUnitA)
  3031. {
  3032. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3033. 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++)
  3034. {
  3035. 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"));
  3036. 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?
  3037. 3:
  3038. 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")));
  3039. 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")));
  3040. }
  3041. }
  3042. else
  3043. {
  3044. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3045. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3046. {
  3047. 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"));
  3048. 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?
  3049. 3:
  3050. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3051. 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));
  3052. }
  3053. }
  3054. // Optional item
  3055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3056. {
  3057. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3058. }
  3059. else
  3060. {
  3061. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3062. }
  3063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3064. {
  3065. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3066. }
  3067. else
  3068. {
  3069. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3070. }
  3071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3072. {
  3073. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3074. }
  3075. else
  3076. {
  3077. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3078. }
  3079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3080. {
  3081. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3082. }
  3083. else
  3084. {
  3085. defaultTxProfile.TransactionId = -1;
  3086. }
  3087. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3088. {
  3089. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3090. }
  3091. else
  3092. {
  3093. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3094. }
  3095. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3096. {
  3097. 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")));
  3098. }
  3099. else
  3100. {
  3101. 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));
  3102. }
  3103. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3104. {
  3105. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3106. }
  3107. else
  3108. {
  3109. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3110. }
  3111. }
  3112. }
  3113. }
  3114. else
  3115. {
  3116. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3117. {
  3118. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3119. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3120. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3121. }
  3122. if(defaultTxProfile.ChargingProfileId == -1)
  3123. DEBUG_INFO("TxDefaultProfile found.\n");
  3124. else
  3125. DEBUG_INFO("TxDefaultProfile updated.\n");
  3126. // Required item
  3127. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3128. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3129. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3130. if(isUnitA)
  3131. {
  3132. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3133. 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++)
  3134. {
  3135. 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"));
  3136. 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?
  3137. 3:
  3138. 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")));
  3139. 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")));
  3140. }
  3141. }
  3142. else
  3143. {
  3144. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3145. 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++)
  3146. {
  3147. 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"));
  3148. 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?
  3149. 3:
  3150. 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")));
  3151. 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));
  3152. }
  3153. }
  3154. // Optional item
  3155. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3156. {
  3157. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3158. }
  3159. else
  3160. {
  3161. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3162. }
  3163. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3164. {
  3165. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3166. }
  3167. else
  3168. {
  3169. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3170. }
  3171. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3172. {
  3173. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3174. }
  3175. else
  3176. {
  3177. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3178. }
  3179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3180. {
  3181. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3182. }
  3183. else
  3184. {
  3185. defaultTxProfile.TransactionId = -1;
  3186. }
  3187. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3188. {
  3189. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3190. }
  3191. else
  3192. {
  3193. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3194. }
  3195. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3196. {
  3197. 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")));
  3198. }
  3199. else
  3200. {
  3201. 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));
  3202. }
  3203. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3204. {
  3205. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3206. }
  3207. else
  3208. {
  3209. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3210. }
  3211. }
  3212. }
  3213. }
  3214. json_object_put(obj);
  3215. }
  3216. fclose(fp);
  3217. /*
  3218. if(defaultTxProfile.ChargingProfileId != -1)
  3219. {
  3220. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3221. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3222. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3223. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3224. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3225. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3226. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3227. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  3228. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3229. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3230. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3231. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3232. {
  3233. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3234. {
  3235. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3236. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3237. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3238. }
  3239. }
  3240. }
  3241. else
  3242. DEBUG_INFO("TxDefaultProfile not found.\n");
  3243. DEBUG_INFO("------------------------------------\n");*/
  3244. }
  3245. // Search max profile
  3246. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3247. if((access(profileFileName, F_OK))!=-1)
  3248. {
  3249. fp = fopen(profileFileName, "r");
  3250. while(getline(&line, &len, fp) != -1)
  3251. {
  3252. json_object *obj = NULL;
  3253. obj = json_tokener_parse(line);
  3254. if(is_error(obj))
  3255. {
  3256. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3257. }
  3258. else
  3259. {
  3260. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3261. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3262. )
  3263. {
  3264. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3265. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3266. )
  3267. {
  3268. struct tm tmFrom, tmTo;
  3269. struct timeb tbFrom, tbTo;
  3270. 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) &&
  3271. (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))
  3272. {
  3273. tmFrom.tm_year -= 1900;
  3274. tmFrom.tm_mon -= 1;
  3275. tbFrom.time = mktime(&tmFrom);
  3276. tmTo.tm_year -= 1900;
  3277. tmTo.tm_mon -= 1;
  3278. tbTo.time = mktime(&tmTo);
  3279. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3280. {
  3281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3282. {
  3283. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3285. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3286. }
  3287. if(maxProfile.ChargingProfileId == -1)
  3288. DEBUG_INFO("MaxProfile found.\n");
  3289. else
  3290. DEBUG_INFO("MaxProfile updated.\n");
  3291. // Required item
  3292. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3293. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3294. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3295. if(isUnitA)
  3296. {
  3297. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3298. 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++)
  3299. {
  3300. 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"));
  3301. 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?
  3302. 3:
  3303. 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")));
  3304. 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")));
  3305. }
  3306. }
  3307. else
  3308. {
  3309. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3310. 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++)
  3311. {
  3312. 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"));
  3313. 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?
  3314. 3:
  3315. 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")));
  3316. 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));
  3317. }
  3318. }
  3319. // Optional item
  3320. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3321. {
  3322. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3323. }
  3324. else
  3325. {
  3326. sprintf((char*)maxProfile.ValidFrom, " ");
  3327. }
  3328. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3329. {
  3330. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3331. }
  3332. else
  3333. {
  3334. sprintf((char*)maxProfile.ValidTo, " ");
  3335. }
  3336. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3337. {
  3338. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3339. }
  3340. else
  3341. {
  3342. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3343. }
  3344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3345. {
  3346. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3347. }
  3348. else
  3349. {
  3350. maxProfile.TransactionId = -1;
  3351. }
  3352. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3353. {
  3354. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3355. }
  3356. else
  3357. {
  3358. maxProfile.ChargingSchedule.Duration = 86400;
  3359. }
  3360. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3361. {
  3362. 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")));
  3363. }
  3364. else
  3365. {
  3366. 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));
  3367. }
  3368. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3369. {
  3370. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3371. }
  3372. else
  3373. {
  3374. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3375. }
  3376. }
  3377. }
  3378. }
  3379. else
  3380. {
  3381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3382. {
  3383. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3384. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3385. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3386. }
  3387. if(maxProfile.ChargingProfileId == -1)
  3388. DEBUG_INFO("MaxProfile found.\n");
  3389. else
  3390. DEBUG_INFO("MaxProfile updated.\n");
  3391. // Required item
  3392. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3393. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3394. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3395. if(isUnitA)
  3396. {
  3397. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3398. 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++)
  3399. {
  3400. 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"));
  3401. 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?
  3402. 3:
  3403. 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")));
  3404. 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")));
  3405. }
  3406. }
  3407. else
  3408. {
  3409. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3410. 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++)
  3411. {
  3412. 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"));
  3413. 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?
  3414. 3:
  3415. 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")));
  3416. 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));
  3417. }
  3418. }
  3419. // Optional item
  3420. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3421. {
  3422. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3423. }
  3424. else
  3425. {
  3426. sprintf((char*)maxProfile.ValidFrom, " ");
  3427. }
  3428. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3429. {
  3430. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3431. }
  3432. else
  3433. {
  3434. sprintf((char*)maxProfile.ValidTo, " ");
  3435. }
  3436. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3437. {
  3438. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3439. }
  3440. else
  3441. {
  3442. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3443. }
  3444. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3445. {
  3446. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3447. }
  3448. else
  3449. {
  3450. maxProfile.TransactionId = -1;
  3451. }
  3452. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3453. {
  3454. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3455. }
  3456. else
  3457. {
  3458. maxProfile.ChargingSchedule.Duration = 86400;
  3459. }
  3460. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3461. {
  3462. 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")));
  3463. }
  3464. else
  3465. {
  3466. 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));
  3467. }
  3468. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3469. {
  3470. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3471. }
  3472. else
  3473. {
  3474. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3475. }
  3476. }
  3477. }
  3478. }
  3479. json_object_put(obj);
  3480. }
  3481. fclose(fp);
  3482. /*
  3483. if(maxProfile.ChargingProfileId !=-1)
  3484. {
  3485. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3486. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3487. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3488. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3489. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3490. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3491. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3492. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3493. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3494. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3495. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3496. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3497. {
  3498. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3499. {
  3500. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3501. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3502. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3503. }
  3504. }
  3505. }
  3506. else
  3507. DEBUG_INFO("MaxProfile not found.\n");
  3508. DEBUG_INFO("------------------------------------\n");*/
  3509. }
  3510. /*
  3511. * Align found profile start schedule & periods
  3512. */
  3513. //DEBUG_INFO("====================================\n");
  3514. /*
  3515. // For local test usage, force modify found profile start schedule info
  3516. 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);
  3517. 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);
  3518. 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);
  3519. */
  3520. if(txProfile.ChargingProfileId != -1)
  3521. {
  3522. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3523. {
  3524. if(txProfile.ChargingSchedule.Duration != -1)
  3525. {
  3526. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3527. 0:
  3528. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3529. }
  3530. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3531. {
  3532. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3533. {
  3534. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3535. 0:
  3536. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3537. if(idxPeriod > 0)
  3538. {
  3539. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3540. {
  3541. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3542. }
  3543. }
  3544. }
  3545. }
  3546. }
  3547. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3548. {
  3549. if(txProfile.ChargingSchedule.Duration != -1)
  3550. {
  3551. 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?
  3552. 0:
  3553. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3554. }
  3555. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3556. {
  3557. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3558. {
  3559. 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?
  3560. 0:
  3561. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3562. if(idxPeriod > 0)
  3563. {
  3564. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3565. {
  3566. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3567. }
  3568. }
  3569. }
  3570. }
  3571. }
  3572. else
  3573. {
  3574. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3575. {
  3576. if(txProfile.ChargingSchedule.Duration != -1)
  3577. {
  3578. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3579. 0:
  3580. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3581. }
  3582. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3583. {
  3584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3585. {
  3586. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3587. 0:
  3588. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3589. if(idxPeriod > 0)
  3590. {
  3591. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3592. {
  3593. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3594. }
  3595. }
  3596. }
  3597. }
  3598. }
  3599. else
  3600. {
  3601. if(txProfile.ChargingSchedule.Duration != -1)
  3602. {
  3603. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3604. 0:
  3605. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3606. }
  3607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3608. {
  3609. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3610. {
  3611. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3612. 0:
  3613. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3614. if(idxPeriod > 0)
  3615. {
  3616. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3617. {
  3618. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3619. }
  3620. }
  3621. }
  3622. }
  3623. }
  3624. }
  3625. /*
  3626. DEBUG_INFO("txProfile after align.\n");
  3627. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3628. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3629. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3630. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3631. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3632. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3633. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3634. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3635. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3636. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3637. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3638. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3639. {
  3640. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3641. {
  3642. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3643. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3644. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3645. }
  3646. }*/
  3647. }
  3648. if(defaultTxProfile.ChargingProfileId != -1)
  3649. {
  3650. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3651. {
  3652. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3653. {
  3654. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3655. 0:
  3656. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3657. }
  3658. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3659. {
  3660. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3661. {
  3662. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3663. 0:
  3664. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3665. if(idxPeriod > 0)
  3666. {
  3667. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3668. {
  3669. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3670. }
  3671. }
  3672. }
  3673. }
  3674. }
  3675. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3676. {
  3677. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3678. {
  3679. 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?
  3680. 0:
  3681. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3682. }
  3683. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3684. {
  3685. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3686. {
  3687. 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?
  3688. 0:
  3689. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3690. if(idxPeriod > 0)
  3691. {
  3692. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3693. {
  3694. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3695. }
  3696. }
  3697. }
  3698. }
  3699. }
  3700. else
  3701. {
  3702. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3703. {
  3704. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3705. {
  3706. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3707. 0:
  3708. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3709. }
  3710. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3711. {
  3712. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3713. {
  3714. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3715. 0:
  3716. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3717. if(idxPeriod > 0)
  3718. {
  3719. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3720. {
  3721. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3722. }
  3723. }
  3724. }
  3725. }
  3726. }
  3727. else
  3728. {
  3729. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3730. {
  3731. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3732. 0:
  3733. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3734. }
  3735. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3736. {
  3737. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3738. {
  3739. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3740. 0:
  3741. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3742. if(idxPeriod > 0)
  3743. {
  3744. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3745. {
  3746. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3747. }
  3748. }
  3749. }
  3750. }
  3751. }
  3752. }
  3753. /*
  3754. DEBUG_INFO("defaultTxProfile after align.\n");
  3755. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3756. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3757. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3758. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3759. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3760. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3761. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3762. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3763. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3764. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3765. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3767. {
  3768. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3769. {
  3770. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3771. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3772. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3773. }
  3774. }
  3775. DEBUG_INFO("------------------------------------\n");*/
  3776. }
  3777. if(maxProfile.ChargingProfileId != -1)
  3778. {
  3779. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3780. {
  3781. if(maxProfile.ChargingSchedule.Duration != -1)
  3782. {
  3783. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3784. 0:
  3785. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3786. }
  3787. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3788. {
  3789. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3790. {
  3791. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3792. 0:
  3793. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3794. if(idxPeriod > 0)
  3795. {
  3796. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3797. {
  3798. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3799. }
  3800. }
  3801. }
  3802. }
  3803. }
  3804. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3805. {
  3806. if(maxProfile.ChargingSchedule.Duration != -1)
  3807. {
  3808. 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?
  3809. 0:
  3810. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3811. }
  3812. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3813. {
  3814. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3815. {
  3816. 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?
  3817. 0:
  3818. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3819. if(idxPeriod > 0)
  3820. {
  3821. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3822. {
  3823. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3824. }
  3825. }
  3826. }
  3827. }
  3828. }
  3829. else
  3830. {
  3831. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3832. {
  3833. if(maxProfile.ChargingSchedule.Duration != -1)
  3834. {
  3835. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3836. 0:
  3837. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3838. }
  3839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3840. {
  3841. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3842. {
  3843. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3844. 0:
  3845. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3846. if(idxPeriod > 0)
  3847. {
  3848. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3849. {
  3850. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3851. }
  3852. }
  3853. }
  3854. }
  3855. }
  3856. else
  3857. {
  3858. if(maxProfile.ChargingSchedule.Duration != -1)
  3859. {
  3860. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3861. 0:
  3862. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3863. }
  3864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3865. {
  3866. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3867. {
  3868. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3869. 0:
  3870. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3871. if(idxPeriod > 0)
  3872. {
  3873. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3874. {
  3875. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3876. }
  3877. }
  3878. }
  3879. }
  3880. }
  3881. }
  3882. /*
  3883. DEBUG_INFO("MaxProfile after align.\n");
  3884. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3885. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3886. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3887. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3888. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3889. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3890. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3891. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3892. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3893. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3894. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3895. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3896. {
  3897. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3898. {
  3899. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3900. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3901. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3902. }
  3903. }
  3904. DEBUG_INFO("------------------------------------\n");*/
  3905. }
  3906. /*
  3907. * Merge to composite schedule
  3908. */
  3909. //DEBUG_INFO("====================================\n");
  3910. // Find each profile period quantity
  3911. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3912. {
  3913. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3914. limitMax = idx+1;
  3915. }
  3916. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3917. {
  3918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3919. limitDef = idx+1;
  3920. }
  3921. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3922. {
  3923. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3924. limitTx = idx+1;
  3925. }
  3926. // TxProfile found, composite schedule based on it
  3927. if(txProfile.ChargingProfileId != -1)
  3928. {
  3929. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3930. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3931. {
  3932. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3933. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3934. (txProfile.ChargingSchedule.Duration > 0))
  3935. {
  3936. if(maxProfile.ChargingProfileId != -1)
  3937. {
  3938. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3939. {
  3940. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3941. {
  3942. if((maxProfile.ChargingSchedule.Duration > 0))
  3943. {
  3944. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3945. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3946. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3947. }
  3948. else
  3949. {
  3950. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3951. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3952. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3953. }
  3954. }
  3955. if(idxMaxPeriod == (limitMax-1))
  3956. {
  3957. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3958. {
  3959. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3960. {
  3961. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3962. compositePeriodIdx++;
  3963. }
  3964. else
  3965. {
  3966. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3967. }
  3968. }
  3969. }
  3970. }
  3971. }
  3972. else
  3973. {
  3974. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3975. {
  3976. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3977. compositePeriodIdx++;
  3978. }
  3979. else
  3980. {
  3981. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3982. }
  3983. }
  3984. }
  3985. if(idxTxPeriod == (limitTx-1))
  3986. {
  3987. if(defaultTxProfile.ChargingProfileId != -1)
  3988. {
  3989. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3990. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3991. {
  3992. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3993. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3994. (defaultTxProfile.ChargingSchedule.Duration>0))
  3995. {
  3996. if(maxProfile.ChargingProfileId != -1)
  3997. {
  3998. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3999. {
  4000. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4001. {
  4002. if((maxProfile.ChargingSchedule.Duration > 0))
  4003. {
  4004. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4005. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4006. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  4007. }
  4008. else
  4009. {
  4010. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4011. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4012. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4013. }
  4014. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4015. {
  4016. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4017. {
  4018. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4019. compositePeriodIdx++;
  4020. }
  4021. else
  4022. {
  4023. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4024. }
  4025. }
  4026. // Delete duplicate period
  4027. if(compositePeriodIdx > 1)
  4028. {
  4029. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4030. {
  4031. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4032. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4033. compositePeriodIdx -= 1;
  4034. }
  4035. }
  4036. }
  4037. else
  4038. {
  4039. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4040. {
  4041. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4042. compositePeriodIdx++;
  4043. }
  4044. else
  4045. {
  4046. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4047. }
  4048. break;
  4049. }
  4050. }
  4051. }
  4052. else
  4053. {
  4054. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4055. {
  4056. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4057. compositePeriodIdx++;
  4058. }
  4059. else
  4060. {
  4061. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4062. }
  4063. }
  4064. }
  4065. }
  4066. }
  4067. }
  4068. }
  4069. }
  4070. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4071. else if(defaultTxProfile.ChargingProfileId != -1)
  4072. {
  4073. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  4074. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4075. {
  4076. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  4077. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  4078. (defaultTxProfile.ChargingSchedule.Duration > 0))
  4079. {
  4080. if(maxProfile.ChargingProfileId != -1)
  4081. {
  4082. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4083. {
  4084. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4085. {
  4086. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4087. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4088. if((maxProfile.ChargingSchedule.Duration > 0))
  4089. {
  4090. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  4091. }
  4092. else
  4093. {
  4094. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4095. }
  4096. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4097. {
  4098. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4099. {
  4100. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4101. compositePeriodIdx++;
  4102. }
  4103. else
  4104. {
  4105. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4106. }
  4107. }
  4108. // Delete duplicate period
  4109. if(compositePeriodIdx > 1)
  4110. {
  4111. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4112. {
  4113. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4114. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4115. compositePeriodIdx -= 1;
  4116. }
  4117. }
  4118. }
  4119. else
  4120. {
  4121. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4122. {
  4123. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4124. compositePeriodIdx++;
  4125. }
  4126. else
  4127. {
  4128. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4129. }
  4130. break;
  4131. }
  4132. }
  4133. }
  4134. else
  4135. {
  4136. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4137. {
  4138. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4139. compositePeriodIdx++;
  4140. }
  4141. else
  4142. {
  4143. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4144. }
  4145. }
  4146. }
  4147. }
  4148. }
  4149. // Fill other period by MaxProfile
  4150. if(maxProfile.ChargingProfileId != -1)
  4151. {
  4152. if(compositePeriodIdx==0)
  4153. {
  4154. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4155. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  4156. {
  4157. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4158. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4159. (maxProfile.ChargingSchedule.Duration > 0))
  4160. {
  4161. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4162. {
  4163. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4164. compositePeriodIdx++;
  4165. }
  4166. else
  4167. {
  4168. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4169. }
  4170. }
  4171. }
  4172. }
  4173. else
  4174. {
  4175. int lastCompositePeriodIdx = compositePeriodIdx;
  4176. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4177. {
  4178. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4179. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4180. (maxProfile.ChargingSchedule.Duration > 0))
  4181. {
  4182. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  4183. {
  4184. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  4185. {
  4186. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4187. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4188. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  4189. }
  4190. else
  4191. {
  4192. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4193. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4194. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  4195. }
  4196. }
  4197. if(tmpPeriod.Limit != -1)
  4198. {
  4199. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  4200. {
  4201. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  4202. {
  4203. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4204. compositePeriodIdx++;
  4205. }
  4206. else
  4207. {
  4208. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4209. }
  4210. }
  4211. // Delete duplicate period
  4212. if(compositePeriodIdx > 1)
  4213. {
  4214. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4215. {
  4216. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4217. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4218. compositePeriodIdx -= 1;
  4219. }
  4220. }
  4221. }
  4222. }
  4223. }
  4224. }
  4225. }
  4226. if(compositeProfile.ChargingSchedule.Duration < durationReq)
  4227. {
  4228. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4229. {
  4230. if((idxPeriod > 0) && (compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == 0 || compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1))
  4231. {
  4232. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = compositeProfile.ChargingSchedule.Duration;
  4233. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  4234. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].NumberPhases;
  4235. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  4236. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4237. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4238. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4239. DEBUG_INFO("------------------------------------------------\n");
  4240. break;
  4241. }
  4242. }
  4243. }
  4244. compositeProfile.ChargingSchedule.Duration = durationReq;
  4245. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4246. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4247. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4248. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4249. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4250. {
  4251. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4252. {
  4253. compositeProfile.ChargingProfileId = 1;
  4254. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4255. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4256. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4257. }
  4258. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4259. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4260. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4261. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4262. }
  4263. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4264. if(line)
  4265. free(line);
  4266. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4267. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4268. }
  4269. //==========================================
  4270. // Init all share memory
  4271. //==========================================
  4272. int InitShareMemory()
  4273. {
  4274. int result = PASS;
  4275. int MeterSMId;
  4276. //creat ShmSysConfigAndInfo
  4277. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4278. {
  4279. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4280. result = FAIL;
  4281. }
  4282. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4283. {
  4284. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4285. result = FAIL;
  4286. }
  4287. else
  4288. {}
  4289. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4290. {
  4291. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4292. result = FAIL;
  4293. }
  4294. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4295. {
  4296. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4297. result = FAIL;
  4298. }
  4299. else
  4300. {}
  4301. //creat ShmPsuData
  4302. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4303. {
  4304. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4305. result = FAIL;
  4306. }
  4307. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4308. {
  4309. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4310. result = FAIL;
  4311. }
  4312. else
  4313. {}
  4314. //creat ShmOCPP16Data
  4315. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4316. {
  4317. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4318. result = FAIL;
  4319. }
  4320. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4321. {
  4322. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4323. result = FAIL;
  4324. }
  4325. else
  4326. {}
  4327. /****************************** For Initial Settings************************************************/
  4328. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4329. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4330. // allocate Configuration memory address
  4331. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4332. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4333. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4334. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4335. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4336. //offline MeterValue Interval
  4337. TempMeterValueInterval = 0;
  4338. return result;
  4339. }
  4340. int ProcessShareMemory()
  4341. {
  4342. int result = PASS;
  4343. if(InitShareMemory() == FAIL)
  4344. {
  4345. DEBUG_ERROR("InitShareMemory NG\n");
  4346. if(ShmStatusCodeData!=NULL)
  4347. {
  4348. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4349. }
  4350. result = FAIL;
  4351. }
  4352. // Model name parsing
  4353. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4354. {
  4355. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4356. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4357. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4358. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4359. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  4360. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  4361. ) // 'D' means DC
  4362. {
  4363. // DO series
  4364. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4365. {
  4366. gunTotalNumber += 1;
  4367. gunType[gun_index] = GUN_TYPE_DO;
  4368. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4369. {
  4370. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4371. {
  4372. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4373. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4374. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4375. }
  4376. }
  4377. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4378. {
  4379. case Gun_Type_Chademo:
  4380. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4381. break;
  4382. case Gun_Type_CCS_2:
  4383. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4384. break;
  4385. case Gun_Type_GB:
  4386. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4387. break;
  4388. case Gun_Type_AC:
  4389. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4390. break;
  4391. default:
  4392. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4393. break;
  4394. }
  4395. }
  4396. }
  4397. else
  4398. {
  4399. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4400. {
  4401. gunTotalNumber += 1;
  4402. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4403. {
  4404. case Gun_Type_Chademo:
  4405. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4406. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4407. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4408. {
  4409. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4410. {
  4411. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4412. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4413. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4414. }
  4415. }
  4416. break;
  4417. case Gun_Type_CCS_2:
  4418. gunType[gun_index] = GUN_TYPE_CCS;
  4419. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4420. for (int index = 0; index < CCS_QUANTITY; index++)
  4421. {
  4422. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4423. {
  4424. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4425. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4426. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4427. }
  4428. }
  4429. break;
  4430. case Gun_Type_GB:
  4431. gunType[gun_index] = GUN_TYPE_GBT;
  4432. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4433. for (int index = 0; index < GB_QUANTITY; index++)
  4434. {
  4435. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4436. {
  4437. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4438. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4439. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4440. }
  4441. }
  4442. break;
  4443. case Gun_Type_AC:
  4444. gunType[gun_index] = GUN_TYPE_AC;
  4445. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4446. for (int index = 0; index < AC_QUANTITY; index++)
  4447. {
  4448. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4449. {
  4450. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4451. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4452. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4453. }
  4454. }
  4455. break;
  4456. default:
  4457. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4458. break;
  4459. }
  4460. }
  4461. }
  4462. }
  4463. else
  4464. {
  4465. DEBUG_ERROR("Model name parsing fail.\n");
  4466. result = FAIL;
  4467. }
  4468. if(result != PASS)sleep(5);
  4469. return result;
  4470. }
  4471. void checkRemoteStart(uint8_t connectorIdInt)
  4472. {
  4473. uint8_t tempIndex;
  4474. int result = PASS;
  4475. char cmdBuf[512];
  4476. //check Transaction active
  4477. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4478. {
  4479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4480. {
  4481. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4482. }
  4483. else
  4484. {
  4485. tempIndex = connectorIdInt -1;
  4486. }
  4487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4488. {
  4489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4490. {
  4491. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4492. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4493. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4494. {
  4495. //Reserved
  4496. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4497. }
  4498. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4499. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4500. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4501. {
  4502. //Reserved
  4503. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4504. result = FAIL;
  4505. goto end;
  4506. }
  4507. else
  4508. {
  4509. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4510. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4511. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4512. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4513. {
  4514. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4515. result = FAIL;
  4516. goto end;
  4517. }
  4518. }//END FOR ELSE
  4519. }
  4520. }// END FOR CHAdeMO_QUANTITY
  4521. }
  4522. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4523. {
  4524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4525. {
  4526. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4527. }
  4528. else
  4529. {
  4530. tempIndex = connectorIdInt -1;
  4531. }
  4532. for (int index = 0; index < CCS_QUANTITY; index++)
  4533. {
  4534. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4535. {
  4536. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4537. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4538. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4539. {
  4540. //Reserved
  4541. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4542. }
  4543. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4544. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4545. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4546. {
  4547. //Reserved
  4548. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4549. result = FAIL;
  4550. goto end;
  4551. }
  4552. else
  4553. {
  4554. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4555. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4556. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4557. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4558. {
  4559. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4560. result = FAIL;
  4561. goto end;
  4562. }
  4563. }// END FOR ELSE
  4564. }
  4565. }// END FOR CCS_QUANTITY
  4566. }
  4567. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4568. {
  4569. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4570. {
  4571. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4572. }
  4573. else
  4574. {
  4575. tempIndex = connectorIdInt -1;
  4576. }
  4577. for (int index = 0; index < GB_QUANTITY; index++)
  4578. {
  4579. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4580. {
  4581. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4582. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4583. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4584. {
  4585. //Reserved
  4586. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4587. }
  4588. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4589. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4590. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4591. {
  4592. //Reserved
  4593. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4594. result = FAIL;
  4595. goto end;
  4596. }
  4597. else
  4598. {
  4599. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4600. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4601. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4602. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4603. {
  4604. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4605. result = FAIL;
  4606. goto end;
  4607. }
  4608. }// END FOR ELSE
  4609. }
  4610. } // END FOR GB_QUANTITY
  4611. }
  4612. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4613. {
  4614. tempIndex = connectorIdInt -1;
  4615. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4616. {
  4617. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4618. {
  4619. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4620. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4621. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4622. {
  4623. //Reserved
  4624. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4625. }
  4626. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4627. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4628. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4629. {
  4630. //Reserved
  4631. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4632. result = FAIL;
  4633. goto end;
  4634. }
  4635. else
  4636. {
  4637. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4638. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4639. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4640. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4641. {
  4642. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4643. result = FAIL;
  4644. goto end;
  4645. }
  4646. }// END FOR ELSE
  4647. }
  4648. } // END FOR GB_QUANTITY
  4649. }
  4650. else
  4651. {
  4652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4653. {
  4654. tempIndex = 2;
  4655. }
  4656. else
  4657. {
  4658. tempIndex = connectorIdInt -1;
  4659. }
  4660. for (int index = 0; index < AC_QUANTITY; index++)
  4661. {
  4662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4663. {
  4664. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4665. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4666. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4667. {
  4668. //Reserved
  4669. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4670. }
  4671. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4672. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4673. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4674. {
  4675. //Reserved
  4676. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4677. result = FAIL;
  4678. goto end;
  4679. }
  4680. else
  4681. {
  4682. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4683. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4684. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4685. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4686. {
  4687. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4688. result = FAIL;
  4689. goto end;
  4690. }
  4691. }//END FOR ELSE
  4692. }
  4693. }// END FOR AC_QUANTITY
  4694. }
  4695. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4696. {
  4697. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4698. {
  4699. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4700. {
  4701. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4702. system(cmdBuf);
  4703. }
  4704. }
  4705. else
  4706. {
  4707. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4708. result = FAIL;
  4709. }
  4710. }
  4711. end:
  4712. if(result == PASS)
  4713. {
  4714. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4715. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4716. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4717. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4718. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4719. }
  4720. }
  4721. int isConnector0Unavailable()
  4722. {
  4723. uint8_t result = YES;
  4724. uint8_t tempIndex;
  4725. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4726. {
  4727. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4728. {
  4729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4730. {
  4731. tempIndex = ((gun_index==2) ? 1: 0);
  4732. }
  4733. else
  4734. {
  4735. tempIndex = gun_index;
  4736. }
  4737. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4738. {
  4739. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4740. {
  4741. 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))
  4742. {
  4743. result = NO;
  4744. }
  4745. }
  4746. }
  4747. }
  4748. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4749. {
  4750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4751. {
  4752. tempIndex = ((gun_index==2) ? 1: 0);
  4753. }
  4754. else
  4755. {
  4756. tempIndex = gun_index;
  4757. }
  4758. for (int index = 0; index < CCS_QUANTITY; index++)
  4759. {
  4760. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4761. {
  4762. 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))
  4763. {
  4764. result = NO;
  4765. }
  4766. }
  4767. }
  4768. }
  4769. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4770. {
  4771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4772. {
  4773. tempIndex = ((gun_index==2) ? 1: 0);
  4774. }
  4775. else
  4776. {
  4777. tempIndex = gun_index;
  4778. }
  4779. for (int index = 0; index < GB_QUANTITY; index++)
  4780. {
  4781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4782. {
  4783. 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))
  4784. {
  4785. result = NO;
  4786. }
  4787. }
  4788. }
  4789. }
  4790. else if(gunType[gun_index] == GUN_TYPE_DO)
  4791. {
  4792. tempIndex = gun_index;
  4793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4794. {
  4795. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4796. {
  4797. 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))
  4798. {
  4799. result = NO;
  4800. }
  4801. }
  4802. }
  4803. }
  4804. else
  4805. {
  4806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4807. {
  4808. tempIndex = 2;
  4809. }
  4810. else
  4811. {
  4812. tempIndex = gun_index;
  4813. }
  4814. for (int index = 0; index < AC_QUANTITY; index++)
  4815. {
  4816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4817. {
  4818. 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))
  4819. {
  4820. result = NO;
  4821. }
  4822. }
  4823. }// END
  4824. }
  4825. }
  4826. return result;
  4827. }
  4828. void CheckSystemValue(void)
  4829. {
  4830. char filenmae[100]={0};
  4831. char str[100]={0};
  4832. int tempIndex = 0;
  4833. //===============================
  4834. // send Heartbeat
  4835. //===============================
  4836. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4837. {
  4838. //parameter for test
  4839. sendHeartbeatRequest(0);
  4840. //===========================
  4841. // Reset Waiting Time
  4842. //===========================
  4843. HeartBeatWithNOResponse += 1;
  4844. }
  4845. //===============================
  4846. // Tcci credit deduct report
  4847. //===============================
  4848. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4849. {
  4850. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4851. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4852. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4853. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4854. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4855. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4856. }
  4857. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4858. {
  4859. OCPP_query_deduct_info();
  4860. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4861. }
  4862. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4863. {
  4864. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4865. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4866. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4867. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4868. }
  4869. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4870. {
  4871. OCPP_query_occupancyDeduct_info();
  4872. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4873. }
  4874. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4875. {
  4876. // ClockAlign MeterValue
  4877. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4878. {
  4879. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4880. {
  4881. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4882. {
  4883. tempIndex = ((gun_index==2) ? 1: 0);
  4884. }
  4885. else
  4886. {
  4887. tempIndex = gun_index;
  4888. }
  4889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4890. {
  4891. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4892. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4893. {
  4894. reqClockAlignMeter[gun_index] = 1;
  4895. }
  4896. }// End for CHAdeMO
  4897. }
  4898. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4899. {
  4900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4901. {
  4902. tempIndex = ((gun_index==2) ? 1: 0);
  4903. }
  4904. else
  4905. {
  4906. tempIndex = gun_index;
  4907. }
  4908. for (int index = 0; index < CCS_QUANTITY; index++)
  4909. {
  4910. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4911. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4912. {
  4913. reqClockAlignMeter[gun_index] = 1;
  4914. }
  4915. } // End for CCS
  4916. }
  4917. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4918. {
  4919. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4920. {
  4921. tempIndex = ((gun_index==2) ? 1: 0);
  4922. }
  4923. else
  4924. {
  4925. tempIndex = gun_index;
  4926. }
  4927. for (int index = 0; index < GB_QUANTITY; index++)
  4928. {
  4929. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4930. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4931. {
  4932. reqClockAlignMeter[gun_index] = 1;
  4933. }
  4934. }// End for GB
  4935. }
  4936. else if(gunType[gun_index] == GUN_TYPE_DO)
  4937. {
  4938. tempIndex = gun_index;
  4939. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4940. {
  4941. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4942. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4943. {
  4944. reqClockAlignMeter[gun_index] = 1;
  4945. }
  4946. }
  4947. }
  4948. else
  4949. {
  4950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4951. {
  4952. tempIndex = 2;
  4953. }
  4954. else
  4955. {
  4956. tempIndex = gun_index;
  4957. }
  4958. for (int index = 0; index < AC_QUANTITY; index++)
  4959. {
  4960. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4961. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4962. {
  4963. reqClockAlignMeter[gun_index] = 1;
  4964. }
  4965. }//End for AC
  4966. }
  4967. }
  4968. }
  4969. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4970. {
  4971. //==========================================
  4972. // Check remote start without connector id
  4973. //==========================================
  4974. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4975. {
  4976. int connectorIdInt = -1;
  4977. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4978. {
  4979. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4980. {
  4981. connectorIdInt = (gun_index+1);
  4982. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4983. checkRemoteStart(connectorIdInt);
  4984. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4985. break;
  4986. }
  4987. }
  4988. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4989. {
  4990. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4991. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4992. }
  4993. }
  4994. //==========================================
  4995. // csu trigger DataTransferReq
  4996. //==========================================
  4997. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4998. {
  4999. sendDataTransferRequest(gun_index);
  5000. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  5001. }
  5002. //==========================================
  5003. // CSU Trigger Authorize Request
  5004. //==========================================
  5005. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  5006. {
  5007. sendAuthorizeRequest(0);
  5008. authorizeRetryTimes = authorizeRetryTimes + 1;
  5009. if(authorizeRetryTimes < 3)
  5010. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5011. }
  5012. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  5013. {
  5014. authorizeRetryTimes = 0;
  5015. SetOcppConnStatus(FALSE);
  5016. server_sign = FALSE;
  5017. }
  5018. 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))
  5019. {
  5020. sendAuthorizeRequest(0);
  5021. }
  5022. //==========================================
  5023. // Charger start transaction
  5024. //==========================================
  5025. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  5026. {
  5027. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  5028. meterValueBufferClear(gun_index);
  5029. sendStartTransactionRequest(gun_index);
  5030. refreshStartTimer(&clientTime.StartTransaction);
  5031. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5032. storeTempStopTransaction(gun_index);
  5033. }
  5034. //==========================================
  5035. // Charger stop transaction
  5036. //==========================================
  5037. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  5038. {
  5039. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5040. sendStopTransactionRequest(gun_index);
  5041. OCPP_updatePeriodEnergy(gun_index);
  5042. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  5043. refreshStartTimer(&clientTime.StopTransaction);
  5044. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  5045. }
  5046. //==========================================
  5047. // Charger OCMF message
  5048. //==========================================
  5049. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  5050. {
  5051. sendOcmfByDataTransferRequest(gun_index);
  5052. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  5053. }
  5054. //==========================================
  5055. // Charger status report
  5056. //==========================================
  5057. //--- Check Mode Change ---//
  5058. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5059. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5060. {
  5061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5062. {
  5063. tempIndex = ((gun_index==2) ? 1: 0);
  5064. }
  5065. else
  5066. {
  5067. tempIndex = gun_index;
  5068. }
  5069. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5070. {
  5071. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5072. {
  5073. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5074. {
  5075. // Sent unplug message for California pricing logic
  5076. 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])
  5077. {
  5078. uint8_t ts[36];
  5079. getNowDatetime(ts);
  5080. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5081. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5082. if(strcmp((char*)dmsVersion, "2.0")==0)
  5083. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5084. else
  5085. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5086. sendUnplugByDataTransferRequest(gun_index);
  5087. interLock.isSentUnplug[gun_index] = 1;
  5088. }
  5089. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5090. {
  5091. interLock.isSentUnplug[gun_index] = 0;
  5092. }
  5093. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5094. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5095. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5096. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5097. {
  5098. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5099. if((access(filenmae,F_OK))!=-1)
  5100. {
  5101. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5102. sprintf(str,"rm -f %s",filenmae);
  5103. system(str);
  5104. }
  5105. }
  5106. }
  5107. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5108. #if 1 // for TempStopTransaction
  5109. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5110. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5111. {
  5112. checkTempStopTransaction(gun_index);
  5113. }
  5114. #endif
  5115. }
  5116. }
  5117. }
  5118. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5119. {
  5120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5121. {
  5122. tempIndex = ((gun_index==2) ? 1: 0);
  5123. }
  5124. else
  5125. {
  5126. tempIndex = gun_index;
  5127. }
  5128. for (int index = 0; index < CCS_QUANTITY; index++)
  5129. {
  5130. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5131. {
  5132. 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]*/ )
  5133. {
  5134. // Sent unplug message for California pricing logic
  5135. 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])
  5136. {
  5137. uint8_t ts[36];
  5138. getNowDatetime(ts);
  5139. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5140. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5141. if(strcmp((char*)dmsVersion, "2.0")==0)
  5142. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5143. else
  5144. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5145. sendUnplugByDataTransferRequest(gun_index);
  5146. interLock.isSentUnplug[gun_index] = 1;
  5147. }
  5148. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5149. {
  5150. interLock.isSentUnplug[gun_index] = 0;
  5151. }
  5152. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5153. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5154. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5155. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5156. {
  5157. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5158. if((access(filenmae,F_OK))!=-1)
  5159. {
  5160. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5161. sprintf(str,"rm -f %s",filenmae);
  5162. system(str);
  5163. }
  5164. }
  5165. }
  5166. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5167. #if 1 // for TempStopTransaction
  5168. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5169. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5170. {
  5171. checkTempStopTransaction(gun_index);
  5172. }
  5173. #endif
  5174. }
  5175. }
  5176. }
  5177. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5180. {
  5181. tempIndex = ((gun_index==2) ? 1: 0);
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < GB_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5190. {
  5191. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5192. {
  5193. // Sent unplug message for California pricing logic
  5194. 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])
  5195. {
  5196. uint8_t ts[36];
  5197. getNowDatetime(ts);
  5198. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5199. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5200. if(strcmp((char*)dmsVersion, "2.0")==0)
  5201. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5202. else
  5203. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5204. sendUnplugByDataTransferRequest(gun_index);
  5205. interLock.isSentUnplug[gun_index] = 1;
  5206. }
  5207. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5208. {
  5209. interLock.isSentUnplug[gun_index] = 0;
  5210. }
  5211. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5212. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5213. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5214. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5215. {
  5216. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5217. if((access(filenmae,F_OK))!=-1)
  5218. {
  5219. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5220. sprintf(str,"rm -f %s",filenmae);
  5221. system(str);
  5222. }
  5223. }
  5224. }
  5225. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5226. #if 1 // for TempStopTransaction
  5227. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5228. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5229. {
  5230. checkTempStopTransaction(gun_index);
  5231. }
  5232. #endif
  5233. }
  5234. }
  5235. }
  5236. else if(gunType[gun_index] == GUN_TYPE_DO)
  5237. {
  5238. tempIndex = gun_index;
  5239. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5240. {
  5241. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5242. {
  5243. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5244. {
  5245. // Sent unplug message for California pricing logic
  5246. 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])
  5247. {
  5248. uint8_t ts[36];
  5249. getNowDatetime(ts);
  5250. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5251. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5252. if(strcmp((char*)dmsVersion, "2.0")==0)
  5253. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5254. else
  5255. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5256. sendUnplugByDataTransferRequest(gun_index);
  5257. interLock.isSentUnplug[gun_index] = 1;
  5258. }
  5259. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  5260. {
  5261. interLock.isSentUnplug[gun_index] = 0;
  5262. }
  5263. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5264. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5265. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5266. 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
  5267. {
  5268. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5269. if((access(filenmae,F_OK))!=-1)
  5270. {
  5271. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5272. sprintf(str,"rm -f %s",filenmae);
  5273. system(str);
  5274. }
  5275. }
  5276. }
  5277. 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);
  5278. #if 1 // for TempStopTransaction
  5279. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5280. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5281. {
  5282. checkTempStopTransaction(gun_index);
  5283. }
  5284. #endif
  5285. }
  5286. }
  5287. }
  5288. else
  5289. {
  5290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5291. {
  5292. tempIndex = 2;
  5293. }
  5294. else
  5295. {
  5296. tempIndex = gun_index;
  5297. }
  5298. for (int index = 0; index < AC_QUANTITY; index++)
  5299. {
  5300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5301. {
  5302. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5303. {
  5304. // Sent unplug message for California pricing logic
  5305. 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])
  5306. {
  5307. uint8_t ts[36];
  5308. getNowDatetime(ts);
  5309. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5310. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5311. if(strcmp((char*)dmsVersion, "2.0")==0)
  5312. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5313. else
  5314. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5315. sendUnplugByDataTransferRequest(gun_index);
  5316. interLock.isSentUnplug[gun_index] = 1;
  5317. }
  5318. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5319. {
  5320. interLock.isSentUnplug[gun_index] = 0;
  5321. }
  5322. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5323. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5324. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5325. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5326. {
  5327. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5328. if((access(filenmae,F_OK))!=-1)
  5329. {
  5330. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5331. sprintf(str,"rm -f %s",filenmae);
  5332. system(str);
  5333. }
  5334. }
  5335. }
  5336. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5337. #if 1 // for TempStopTransaction
  5338. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5339. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5340. {
  5341. checkTempStopTransaction(gun_index);
  5342. }
  5343. #endif
  5344. }
  5345. }// END
  5346. }
  5347. if(isWebsocketSendable && (server_sign == TRUE) && (isConnector0Unavailable() != Connector0PreviousSystemStatus))
  5348. {
  5349. sendConnector0StatusNotificationRequest();
  5350. Connector0PreviousSystemStatus = isConnector0Unavailable();
  5351. }
  5352. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5353. (
  5354. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5355. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5356. )
  5357. )
  5358. {
  5359. sendStatusNotificationRequest(gun_index);
  5360. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5361. }
  5362. //==============================================
  5363. // TCCI related DataTransfer messages
  5364. //==============================================
  5365. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5366. {
  5367. reportReaderStatus(gun_index);
  5368. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5369. }
  5370. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq == 1))
  5371. {
  5372. occupancyFeeAct(gun_index);
  5373. }
  5374. //==============================================
  5375. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5376. //==============================================
  5377. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5378. ((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))))
  5379. {
  5380. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5381. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5382. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5383. }
  5384. //==============================================
  5385. // Meter report
  5386. //==============================================
  5387. // Trigger MeterValue
  5388. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5389. {
  5390. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5391. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5392. }
  5393. // Clock-aligned Meter value
  5394. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5395. {
  5396. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5397. reqClockAlignMeter[gun_index] = 0;
  5398. }
  5399. // Sample period MeterValue
  5400. 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))))
  5401. {
  5402. //check Transaction active
  5403. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5404. {
  5405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5406. {
  5407. tempIndex = ((gun_index==2) ? 1: 0);
  5408. }
  5409. else
  5410. {
  5411. tempIndex = gun_index;
  5412. }
  5413. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5414. {
  5415. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5416. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5417. {
  5418. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5419. {
  5420. reqSampleMeter[gun_index] = 1;
  5421. }
  5422. }
  5423. }// End for CHAdeMO
  5424. }
  5425. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5426. {
  5427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5428. {
  5429. tempIndex = ((gun_index==2) ? 1: 0);
  5430. }
  5431. else
  5432. {
  5433. tempIndex = gun_index;
  5434. }
  5435. for (int index = 0; index < CCS_QUANTITY; index++)
  5436. {
  5437. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5438. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5439. {
  5440. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5441. {
  5442. reqSampleMeter[gun_index] = 1;
  5443. }
  5444. }
  5445. } // End for CCS
  5446. }
  5447. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5448. {
  5449. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5450. {
  5451. tempIndex = ((gun_index==2) ? 1: 0);
  5452. }
  5453. else
  5454. {
  5455. tempIndex = gun_index;
  5456. }
  5457. for (int index = 0; index < GB_QUANTITY; index++)
  5458. {
  5459. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5460. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5461. {
  5462. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5463. {
  5464. reqSampleMeter[gun_index] = 1;
  5465. }
  5466. }
  5467. }// End for GB
  5468. }
  5469. else if(gunType[gun_index] == GUN_TYPE_DO)
  5470. {
  5471. tempIndex = gun_index;
  5472. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5473. {
  5474. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5475. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5476. {
  5477. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5478. {
  5479. reqSampleMeter[gun_index] = 1;
  5480. }
  5481. }
  5482. }
  5483. }
  5484. else
  5485. {
  5486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5487. {
  5488. tempIndex = 2;
  5489. }
  5490. else
  5491. {
  5492. tempIndex = gun_index;
  5493. }
  5494. for (int index = 0; index < AC_QUANTITY; index++)
  5495. {
  5496. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5497. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5498. {
  5499. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5500. {
  5501. reqSampleMeter[gun_index] = 1;
  5502. }
  5503. }
  5504. }//End for AC
  5505. }
  5506. if(reqSampleMeter[gun_index] == 1)
  5507. {
  5508. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5509. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5510. storeTempStopTransaction(gun_index);
  5511. reqSampleMeter[gun_index] = 0;
  5512. }
  5513. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5514. }
  5515. //==============================================
  5516. // Check Connector reserved
  5517. //==============================================
  5518. //===============================
  5519. // Check if Reserve is expired
  5520. //===============================
  5521. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5522. {
  5523. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5524. {
  5525. DEBUG_INFO("reserve expired.\n");
  5526. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5527. }
  5528. }//END OF Check if Reserve is expired
  5529. //==========================================
  5530. // csu trigger FirmwareStatusNotificationReq
  5531. //==========================================
  5532. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5533. {
  5534. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5535. }
  5536. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5537. {
  5538. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5539. }
  5540. //==========================================
  5541. // csu trigger DiagnosticsStatusNotificationReq
  5542. //==========================================
  5543. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5544. {
  5545. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5546. }
  5547. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5548. {
  5549. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5550. }
  5551. //==========================================
  5552. // csu trigger CancelReservationConf
  5553. //==========================================
  5554. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5555. {
  5556. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5557. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5558. }
  5559. //==========================================
  5560. // csu trigger ChangeAvailabilityConf
  5561. //==========================================
  5562. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5563. {
  5564. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5565. }
  5566. //==========================================
  5567. // csu trigger UnlockConnectorConf
  5568. //==========================================
  5569. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5570. {
  5571. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5572. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5573. }
  5574. //==========================================
  5575. // csu trigger ReserveNowConf
  5576. //==========================================
  5577. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5578. {
  5579. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5580. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5581. }
  5582. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5583. {
  5584. sendSignCertificateRequest();
  5585. }
  5586. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5587. {
  5588. sendSecurityEventNotificationRequest();
  5589. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5590. }
  5591. // Support 15118
  5592. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5593. {
  5594. json_object *data = json_object_new_object();
  5595. // Read csr file content
  5596. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5597. FILE *fp=fopen(CSR_V2G,"r");
  5598. char *line = NULL;
  5599. size_t len = 0;
  5600. while(getline(&line, &len, fp) != -1)
  5601. {
  5602. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5603. {
  5604. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5605. }
  5606. }
  5607. fclose(fp);
  5608. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5609. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5610. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5611. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5612. json_object_put(data);
  5613. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5614. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5615. }
  5616. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5617. {
  5618. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5619. int parseCertResult = FAIL;
  5620. json_object *data = json_object_new_object();
  5621. json_object *idToken = json_object_new_object();
  5622. json_object *iso15118CertificateHashData = json_object_new_array();
  5623. // Read CERTIFICATE_PnCAuth file content
  5624. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5625. {
  5626. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5627. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5628. char *line = NULL;
  5629. size_t len = 0;
  5630. while(getline(&line, &len, fp) != -1)
  5631. {
  5632. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5633. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5634. }
  5635. fclose(fp);
  5636. }
  5637. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5638. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5639. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5640. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5641. json_object_object_add(data, "idToken", idToken);
  5642. char parseData[512] = {0};
  5643. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5644. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5645. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5646. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5647. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5648. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5649. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5650. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5651. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5652. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5653. for(int idx=0; idx < 4; idx++)
  5654. {
  5655. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5656. {
  5657. json_object *OCSPRequestDataType = json_object_new_object();
  5658. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5659. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5660. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5661. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5662. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5663. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5664. parseCertResult = PASS;
  5665. }
  5666. }
  5667. if(parseCertResult == PASS)
  5668. {
  5669. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5670. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5671. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5672. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5673. json_object_put(data);
  5674. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5675. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5676. }
  5677. else
  5678. {
  5679. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5680. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5681. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5682. }
  5683. }
  5684. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5685. {
  5686. json_object *data = json_object_new_object();
  5687. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5688. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5689. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5690. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5691. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5692. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5693. json_object_put(data);
  5694. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5695. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5696. }
  5697. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5698. {
  5699. json_object *data = json_object_new_object();
  5700. json_object *OCSPRequestDataType = json_object_new_object();
  5701. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5702. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5703. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5704. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5705. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5706. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5707. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5708. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5709. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5710. json_object_put(data);
  5711. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5712. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5713. }
  5714. }
  5715. }
  5716. //==========================================
  5717. // send request routine
  5718. //==========================================
  5719. int sendAuthorizeRequest(int gun_index)
  5720. {
  5721. mtrace();
  5722. int result = FAIL;
  5723. char message[100]={0};
  5724. char guid[37];
  5725. char tempdata[65]={0};
  5726. DEBUG_INFO("sendAuthorizeRequest...\n");
  5727. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5728. //Local Authorize
  5729. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5730. {
  5731. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5732. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5733. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5734. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5735. result = PASS;
  5736. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5737. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5738. authorizeRetryTimes = 0;
  5739. return result;
  5740. }
  5741. 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))||
  5742. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5743. {
  5744. // Query from cache
  5745. DEBUG_INFO("Authorize from cache.\n");
  5746. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5747. // Query from list
  5748. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5749. {
  5750. DEBUG_INFO("Authorize from list.\n");
  5751. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5752. }
  5753. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5754. {
  5755. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5756. {
  5757. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5758. }
  5759. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5760. {
  5761. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5762. }
  5763. if(!GetOcppConnStatus())
  5764. {
  5765. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5766. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5767. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5768. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5769. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5770. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5771. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5772. authorizeRetryTimes = 0;
  5773. return result;
  5774. }
  5775. }
  5776. else
  5777. {
  5778. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5779. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5780. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5781. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5782. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5783. else
  5784. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5785. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5786. result = PASS;
  5787. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5788. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5789. authorizeRetryTimes = 0;
  5790. return result;
  5791. }
  5792. }
  5793. //initialize struct Authorize
  5794. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5795. //get data from shared memory
  5796. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5797. random_uuid(guid);
  5798. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5799. LWS_Send(message);
  5800. sprintf(tempdata, "Authorize,%d", gun_index);
  5801. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5802. {
  5803. result = PASS;
  5804. DEBUG_INFO("Authorize mapItem pass\n");
  5805. }
  5806. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5807. return result;
  5808. }
  5809. int sendBootNotificationRequest(void)
  5810. {
  5811. mtrace();
  5812. int result = FAIL;
  5813. char message[500]={0}, payload[700]={0};
  5814. char guid[37]={0};
  5815. char tempdata[65]={0};
  5816. // Fill BootNotification fields
  5817. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5818. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5819. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5820. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5821. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5822. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5823. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5824. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5825. ShmOCPP16Data->ChargeBoxId
  5826. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5827. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5828. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5829. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5830. ,ShmOCPP16Data->BootNotification.CpIccid
  5831. ,ShmOCPP16Data->BootNotification.CpImsi);
  5832. random_uuid(guid);
  5833. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5834. LWS_Send(message);
  5835. sprintf(tempdata, "BootNotification,0");
  5836. 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*/)
  5837. {
  5838. result = PASS;
  5839. }
  5840. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5841. strcpy(queuedata,message);
  5842. return result;
  5843. }
  5844. int sendDataTransferRequest(int gun_index)
  5845. {
  5846. mtrace();
  5847. char message[10240]={0};
  5848. char guid[37]={0};
  5849. char tempdata[65]={0};
  5850. int result = FAIL;
  5851. json_object *DataTransfer = json_object_new_object();
  5852. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5853. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5854. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5855. random_uuid(guid);
  5856. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5857. guid,
  5858. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5859. json_object_put(DataTransfer);
  5860. LWS_Send(message);
  5861. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5862. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5863. {
  5864. result = PASS;
  5865. DEBUG_INFO("DataTransfer mapItem pass\n");
  5866. }
  5867. return result;
  5868. }
  5869. int sendUnplugByDataTransferRequest(int gun_index)
  5870. {
  5871. mtrace();
  5872. char message[10752]={0};
  5873. char guid[37]={0};
  5874. char tempdata[65]={0};
  5875. int result = FAIL;
  5876. random_uuid(guid);
  5877. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5878. (gun_index+1),
  5879. MESSAGE_TYPE_CALL,
  5880. guid,
  5881. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5882. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5883. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5884. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5885. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5886. {
  5887. result = PASS;
  5888. DEBUG_INFO("DataTransfer mapItem pass\n");
  5889. }
  5890. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5891. return result;
  5892. }
  5893. int sendOcmfByDataTransferRequest(int gun_index)
  5894. {
  5895. mtrace();
  5896. json_object *DataTransfer = json_object_new_object();
  5897. json_object *data = json_object_new_object();
  5898. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5899. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5900. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5901. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5902. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5903. json_object_object_add(DataTransfer, "data", data);
  5904. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5905. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5906. char message[3000]={0};
  5907. char guid[37]={0};
  5908. char tempdata[65]={0};
  5909. int result = FAIL;
  5910. random_uuid(guid);
  5911. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5912. (gun_index+1),
  5913. MESSAGE_TYPE_CALL,
  5914. guid,
  5915. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5916. json_object_put(DataTransfer);
  5917. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5918. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5919. {
  5920. result = PASS;
  5921. DEBUG_INFO("DataTransfer mapItem pass\n");
  5922. }
  5923. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5924. return result;
  5925. }
  5926. int sendDiagnosticsStatusNotificationRequest(char *status)
  5927. {
  5928. mtrace();
  5929. int result = FAIL;
  5930. char message[110]={0};
  5931. char guid[37]={0};
  5932. char tempdata[65]={0};
  5933. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5934. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5935. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5936. random_uuid(guid);
  5937. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5938. LWS_SendNow(message);
  5939. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5940. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5941. {
  5942. result = PASS;
  5943. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5944. }
  5945. //#ifdef SystemLogMessage
  5946. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5947. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5948. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5949. //#endif
  5950. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5951. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5952. //record status
  5953. if(strcmp(status,"Idle")==0)
  5954. {
  5955. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5956. }
  5957. else if(strcmp(status,"Uploaded")==0)
  5958. {
  5959. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5960. }
  5961. else if(strcmp(status,"UploadFailed")==0)
  5962. {
  5963. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5964. }
  5965. else if(strcmp(status,"Uploading")==0)
  5966. {
  5967. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5968. }
  5969. return result;
  5970. }
  5971. int sendFirmwareStatusNotificationRequest(char *status)
  5972. {
  5973. mtrace();
  5974. int result = FAIL;
  5975. char message[110]={0};
  5976. char guid[37]={0};
  5977. char tempdata[65]={0};
  5978. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5979. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5980. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5981. random_uuid(guid);
  5982. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5983. LWS_SendNow(message);
  5984. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5985. 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*/)
  5986. {
  5987. result = PASS;
  5988. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5989. }
  5990. //#ifdef SystemLogMessage
  5991. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5992. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5993. //#endif
  5994. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5995. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5996. //record status
  5997. if(strcmp(status,"Downloaded")==0)
  5998. {
  5999. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  6000. }
  6001. else if(strcmp(status,"DownloadFailed")==0)
  6002. {
  6003. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  6004. }
  6005. else if(strcmp(status,"Downloading")==0)
  6006. {
  6007. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  6008. }
  6009. else if(strcmp(status,"Idle")==0)
  6010. {
  6011. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  6012. }
  6013. else if(strcmp(status,"InstallationFailed")==0)
  6014. {
  6015. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  6016. }
  6017. else if(strcmp(status,"Installing")==0)
  6018. {
  6019. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  6020. }
  6021. else if(strcmp(status,"Installed")==0)
  6022. {
  6023. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  6024. }
  6025. return result;
  6026. }
  6027. int sendHeartbeatRequest(int gun_index)
  6028. {
  6029. mtrace();
  6030. int result = FAIL;
  6031. char message[80]={0};
  6032. char guid[37]={0};
  6033. char tempdata[65]={0};
  6034. random_uuid(guid);
  6035. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6036. , MESSAGE_TYPE_CALL
  6037. , guid );
  6038. LWS_Send(message);
  6039. sprintf(tempdata, "Heartbeat,%d", 0);
  6040. 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*/)
  6041. {
  6042. result = PASS;
  6043. }
  6044. return result;
  6045. }
  6046. int sendStartTransactionRequest(int gun_index)
  6047. {
  6048. mtrace();
  6049. int result = FAIL;
  6050. char message[250]={0};
  6051. char guid[37]={0};
  6052. struct timeval tmnow;
  6053. struct tm *tm;
  6054. char buf[28];//, usec_buf[6];
  6055. char tempdata[65]={0};
  6056. int tempIndex = 0;
  6057. DEBUG_INFO("sendStartTransactionRequest...\n");
  6058. gettimeofday(&tmnow, NULL);
  6059. time_t t;
  6060. t = time(NULL);
  6061. /*UTC time and date*/
  6062. tm = gmtime(&t);
  6063. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6064. #if 0 // remove temporally
  6065. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6066. strcat(buf,".");
  6067. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6068. strcat(buf,usec_buf);
  6069. #endif
  6070. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  6071. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  6072. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6073. // clear StartTransaction Response
  6074. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  6075. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  6076. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  6077. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  6078. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6079. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6080. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6081. {
  6082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6083. {
  6084. tempIndex = ((gun_index==2) ? 1: 0);
  6085. }
  6086. else
  6087. {
  6088. tempIndex = gun_index;
  6089. }
  6090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6093. {
  6094. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6095. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  6096. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6097. }
  6098. }
  6099. }
  6100. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6101. {
  6102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6103. {
  6104. tempIndex = ((gun_index==2) ? 1: 0);
  6105. }
  6106. else
  6107. {
  6108. tempIndex = gun_index;
  6109. }
  6110. for (int index = 0; index < CCS_QUANTITY; index++)
  6111. {
  6112. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6113. {
  6114. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6115. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  6116. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6117. }
  6118. }
  6119. }
  6120. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6121. {
  6122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6123. {
  6124. tempIndex = ((gun_index==2) ? 1: 0);
  6125. }
  6126. else
  6127. {
  6128. tempIndex = gun_index;
  6129. }
  6130. for (int index = 0; index < GB_QUANTITY; index++)
  6131. {
  6132. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6133. {
  6134. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6135. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  6136. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6137. }
  6138. }
  6139. }
  6140. else if(gunType[gun_index] == GUN_TYPE_DO)
  6141. {
  6142. tempIndex = gun_index;
  6143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6144. {
  6145. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6146. {
  6147. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6148. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  6149. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6150. }
  6151. }
  6152. }
  6153. else
  6154. {
  6155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6156. {
  6157. tempIndex = 2;
  6158. }
  6159. else
  6160. {
  6161. tempIndex = gun_index;
  6162. }
  6163. for (int index = 0; index < AC_QUANTITY; index++)
  6164. {
  6165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6166. {
  6167. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6168. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  6169. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6170. }
  6171. }
  6172. }
  6173. random_uuid(guid);
  6174. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  6175. {
  6176. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  6177. , gun_index +1
  6178. , MESSAGE_TYPE_CALL
  6179. , guid
  6180. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6181. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6182. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6183. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6184. }
  6185. else
  6186. {
  6187. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  6188. , gun_index +1
  6189. , MESSAGE_TYPE_CALL
  6190. , guid
  6191. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6192. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6193. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6194. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  6195. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6196. }
  6197. #if 1
  6198. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  6199. 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*/)
  6200. {
  6201. result = PASS;
  6202. }
  6203. #endif
  6204. strcpy(queuedata, message);
  6205. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6206. OCPP_insert_transaction_msg(YES, queuedata);
  6207. return result;
  6208. }
  6209. int sendConnector0StatusNotificationRequest()
  6210. {
  6211. mtrace();
  6212. int result = FAIL;
  6213. char message[600]={0};
  6214. char guid[37];
  6215. struct timeval tmnow;
  6216. struct tm *tm;
  6217. char buf[28];//, usec_buf[6];
  6218. char tempdata[65]={0};
  6219. DEBUG_INFO("sendConnector0StatusNotificationRequest...\n");
  6220. gettimeofday(&tmnow, NULL);
  6221. time_t t;
  6222. t = time(NULL);
  6223. /*UTC time and date*/
  6224. tm = gmtime(&t);
  6225. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6226. random_uuid(guid);
  6227. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":0,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6228. , MESSAGE_TYPE_CALL
  6229. , guid
  6230. , "NoError"
  6231. , ""
  6232. , (isConnector0Unavailable()==YES?"Unavailable":"Available")
  6233. , buf
  6234. , ShmSysConfigAndInfo->SysConfig.chargePointVendor
  6235. , "");
  6236. LWS_Send(message);
  6237. sprintf(tempdata, "StatusNotification,%d", 99);
  6238. 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*/)
  6239. {
  6240. //DEBUG_ERROR("statusNotification mapitem pass");
  6241. result = PASS;
  6242. }
  6243. return result;
  6244. }
  6245. int sendStatusNotificationRequest(int gun_index)
  6246. {
  6247. mtrace();
  6248. int result = FAIL;
  6249. char message[600]={0};
  6250. char guid[37];
  6251. int currentStatus = 0;
  6252. struct timeval tmnow;
  6253. struct tm *tm;
  6254. char buf[28];//, usec_buf[6];
  6255. char tempdata[65]={0};
  6256. int tempIndex = 0;
  6257. uint8_t isStateChanged = TRUE;
  6258. uint8_t isContentIllegal = TRUE;
  6259. DEBUG_INFO("sendStatusNotificationRequest...\n");
  6260. gettimeofday(&tmnow, NULL);
  6261. time_t t;
  6262. t = time(NULL);
  6263. /*UTC time and date*/
  6264. tm = gmtime(&t);
  6265. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6266. #if 0 // remove temporally
  6267. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6268. strcat(buf,".");
  6269. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6270. strcat(buf,usec_buf);
  6271. #endif
  6272. //printf("%s",buf);
  6273. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  6274. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6275. // it's option
  6276. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  6277. /*
  6278. enum _SYSTEM_STATUS
  6279. {
  6280. S_BOOTING = 0,
  6281. S_IDLE, = 1
  6282. S_AUTHORIZING, =2
  6283. S_REASSIGN_CHECK, =3
  6284. S_REASSIGN, =4
  6285. S_PRECHARGE, =5
  6286. S_PREPARING_FOR_EV, =6
  6287. S_PREPARING_FOR_EVSE, =7
  6288. S_CHARGING, =8
  6289. S_TERMINATING, =9
  6290. S_COMPLETE, =10
  6291. S_ALARM, =11
  6292. S_FAULT =12
  6293. }
  6294. */
  6295. //check Transaction active
  6296. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6297. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6298. {
  6299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6300. {
  6301. tempIndex = ((gun_index==2) ? 1: 0);
  6302. }
  6303. else
  6304. {
  6305. tempIndex = gun_index;
  6306. }
  6307. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6308. {
  6309. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6310. {
  6311. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6312. {
  6313. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6314. {
  6315. currentStatus = Preparing; //OCPP Status: Preparing
  6316. }
  6317. else
  6318. {
  6319. currentStatus = Available; //OCPP Status: Available
  6320. }
  6321. }
  6322. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6323. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6324. ) //S_PRECHARGE
  6325. {
  6326. currentStatus = Preparing; //OCPP Status: Preparing
  6327. }
  6328. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6329. {
  6330. currentStatus = Charging; //OCPP Status: Charging
  6331. }
  6332. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6333. {
  6334. currentStatus = Finishing; //OCPP Status: Finishing
  6335. }
  6336. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6337. {
  6338. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6339. }
  6340. 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
  6341. {
  6342. currentStatus = Unavailable; //OCPP Status: Unavailable
  6343. }
  6344. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6345. {
  6346. currentStatus = Faulted; //OCPP Status: Faulted
  6347. }
  6348. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6349. {
  6350. currentStatus = Reserved; //OCPP Status: Reserved
  6351. }
  6352. } //end of the same index
  6353. }//end of for CHAdeMO_QUANTITY
  6354. }
  6355. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6356. {
  6357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6358. {
  6359. tempIndex = ((gun_index==2) ? 1: 0);
  6360. }
  6361. else
  6362. {
  6363. tempIndex = gun_index;
  6364. }
  6365. for (int index = 0; index < CCS_QUANTITY; index++)
  6366. {
  6367. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6368. {
  6369. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6370. {
  6371. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6372. {
  6373. currentStatus = Preparing; //OCPP Status: Preparing
  6374. }
  6375. else
  6376. {
  6377. currentStatus = Available; //OCPP Status: Available
  6378. }
  6379. }
  6380. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6381. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6382. ) //S_PRECHARGE
  6383. {
  6384. currentStatus = Preparing; //OCPP Status: Preparing
  6385. }
  6386. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6387. {
  6388. currentStatus = Charging; //OCPP Status: Charging
  6389. }
  6390. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6391. {
  6392. currentStatus = Finishing; //OCPP Status: Finishing
  6393. }
  6394. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6395. {
  6396. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6397. }
  6398. 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
  6399. {
  6400. currentStatus = Unavailable; //OCPP Status : Unavailable
  6401. }
  6402. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6403. {
  6404. currentStatus = Faulted; //OCPP Status: Faulted
  6405. }
  6406. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6407. {
  6408. currentStatus = Reserved; //OCPP Status: Reserved
  6409. }
  6410. } //end of the same index
  6411. } // end of for CCS_QUANTITY
  6412. }
  6413. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6414. {
  6415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6416. {
  6417. tempIndex = ((gun_index==2) ? 1: 0);
  6418. }
  6419. else
  6420. {
  6421. tempIndex = gun_index;
  6422. }
  6423. for (int index = 0; index < GB_QUANTITY; index++)
  6424. {
  6425. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6426. {
  6427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6428. {
  6429. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6430. {
  6431. currentStatus = Preparing; //OCPP Status: Preparing
  6432. }
  6433. else
  6434. {
  6435. currentStatus = Available; //OCPP Status: Available
  6436. }
  6437. }
  6438. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6439. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6440. ) //S_PRECHARGE
  6441. {
  6442. currentStatus = Preparing; //OCPP Status: Preparing
  6443. }
  6444. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6445. {
  6446. currentStatus = Charging; //OCPP Status: Charging
  6447. }
  6448. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6449. {
  6450. currentStatus = Finishing; //OCPP Status: Finishing
  6451. }
  6452. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6453. {
  6454. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6455. }
  6456. 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
  6457. {
  6458. currentStatus = Unavailable; //OCPP Status: Unavailable
  6459. }
  6460. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6461. {
  6462. currentStatus = Faulted; //OCPP Status: Faulted
  6463. }
  6464. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6465. {
  6466. currentStatus = Reserved; //OCPP Status: Reserved
  6467. }
  6468. } //end of the same index
  6469. } // end of for GB_QUANTITY
  6470. }
  6471. else if(gunType[gun_index] == GUN_TYPE_DO)
  6472. {
  6473. tempIndex = gun_index;
  6474. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6475. {
  6476. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6477. {
  6478. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6479. {
  6480. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6481. {
  6482. currentStatus = Preparing; //OCPP Status: Preparing
  6483. }
  6484. else
  6485. {
  6486. currentStatus = Available; //OCPP Status: Available
  6487. }
  6488. }
  6489. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6490. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6491. ) //S_PRECHARGE
  6492. {
  6493. currentStatus = Preparing; //OCPP Status: Preparing
  6494. }
  6495. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6496. {
  6497. currentStatus = Charging; //OCPP Status: Charging
  6498. }
  6499. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6500. {
  6501. currentStatus = Finishing; //OCPP Status: Finishing
  6502. }
  6503. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6504. {
  6505. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6506. }
  6507. 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
  6508. {
  6509. currentStatus = Unavailable; //OCPP Status: Unavailable
  6510. }
  6511. 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
  6512. {
  6513. currentStatus = Faulted; //OCPP Status: Faulted
  6514. }
  6515. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6516. {
  6517. currentStatus = Reserved; //OCPP Status: Reserved
  6518. }
  6519. } //end of the same index
  6520. }
  6521. }
  6522. else
  6523. {
  6524. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6525. {
  6526. tempIndex = 2;
  6527. }
  6528. else
  6529. {
  6530. tempIndex = gun_index;
  6531. }
  6532. for (int index = 0; index < AC_QUANTITY; index++)
  6533. {
  6534. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6535. {
  6536. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6537. {
  6538. 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))
  6539. {
  6540. currentStatus = Preparing; //OCPP Status: Preparing
  6541. }
  6542. else
  6543. {
  6544. currentStatus = Available; //OCPP Status: Available
  6545. }
  6546. }
  6547. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6548. {
  6549. currentStatus = Preparing; //OCPP Status: Preparing
  6550. }
  6551. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6552. {
  6553. currentStatus = Charging; //OCPP Status: Charging
  6554. }
  6555. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6556. {
  6557. currentStatus = Finishing; //OCPP Status: Finishing
  6558. }
  6559. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6560. {
  6561. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6562. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6563. else
  6564. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6565. }
  6566. 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
  6567. {
  6568. currentStatus = Unavailable; //OCPP Status: Unavailable
  6569. }
  6570. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6571. {
  6572. currentStatus = Faulted; //OCPP Status: Faulted
  6573. }
  6574. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6575. {
  6576. currentStatus = Reserved; //OCPP Status: Reserved
  6577. }
  6578. }//end of the same index
  6579. }//end of for AC_QUANTITY
  6580. }
  6581. //it's option
  6582. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6583. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6584. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6585. {
  6586. isStateChanged = FALSE;
  6587. }
  6588. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6589. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6590. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6591. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6592. isContentIllegal = TRUE;
  6593. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6594. {
  6595. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6596. {
  6597. isContentIllegal = FALSE;
  6598. break;
  6599. }
  6600. }
  6601. if(isContentIllegal)
  6602. {
  6603. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6604. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6605. }
  6606. random_uuid(guid);
  6607. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6608. , MESSAGE_TYPE_CALL
  6609. , guid
  6610. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6611. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6612. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6613. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6614. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6615. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6616. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6617. if((server_sign == TRUE) && isStateChanged)
  6618. {
  6619. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6620. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6621. LWS_Send(message);
  6622. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6623. 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*/)
  6624. {
  6625. //DEBUG_ERROR("statusNotification mapitem pass");
  6626. result = PASS;
  6627. }
  6628. }
  6629. else
  6630. {
  6631. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6632. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6633. result = PASS;
  6634. }
  6635. return result;
  6636. }
  6637. int sendStopTransactionRequest(int gun_index)
  6638. {
  6639. mtrace();
  6640. int result = FAIL;
  6641. //char message[1500]={0};
  6642. char guid[37]={0};
  6643. char tempdata[65]={0};
  6644. int tempIndex = 0;
  6645. char TempStopTransaction[256];
  6646. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6647. DEBUG_INFO("sendStopTransactionRequest \n");
  6648. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6649. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6650. //=========================== Stop Transaction Time ===============================================
  6651. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  6652. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6653. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6654. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6655. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6656. {
  6657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6658. {
  6659. tempIndex = ((gun_index==2) ? 1: 0);
  6660. }
  6661. else
  6662. {
  6663. tempIndex = gun_index;
  6664. }
  6665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6666. {
  6667. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6668. {
  6669. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6670. }
  6671. }// END OF CHAdeMO_QUANTITY
  6672. }
  6673. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6674. {
  6675. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6676. {
  6677. tempIndex = ((gun_index==2) ? 1: 0);
  6678. }
  6679. else
  6680. {
  6681. tempIndex = gun_index;
  6682. }
  6683. for (int index = 0; index < CCS_QUANTITY; index++)
  6684. {
  6685. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6686. {
  6687. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6688. }
  6689. }// END OF CCS_QUANTITY
  6690. }
  6691. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6692. {
  6693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6694. {
  6695. tempIndex = ((gun_index==2) ? 1: 0);
  6696. }
  6697. else
  6698. {
  6699. tempIndex = gun_index;
  6700. }
  6701. for (int index = 0; index < GB_QUANTITY; index++)
  6702. {
  6703. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6704. {
  6705. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6706. }
  6707. }// END OF GB_QUANTITY
  6708. }
  6709. else if(gunType[gun_index] == GUN_TYPE_DO)
  6710. {
  6711. tempIndex = gun_index;
  6712. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6713. {
  6714. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6715. {
  6716. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6717. }
  6718. }// END OF GB_QUANTITY
  6719. }
  6720. else
  6721. {
  6722. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6723. {
  6724. tempIndex = 2;
  6725. }
  6726. else
  6727. {
  6728. tempIndex = gun_index;
  6729. }
  6730. for (int index = 0; index < AC_QUANTITY; index++)
  6731. {
  6732. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6733. {
  6734. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6735. }
  6736. }// END OF AC_QUANTITY
  6737. }
  6738. //================================================ Message create ====================================================
  6739. json_object *StopTransaction = json_object_new_object();
  6740. json_object *transactionDatas = json_object_new_array();
  6741. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6742. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6743. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6744. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6745. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6746. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6747. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6748. meterValueBufferQuery(gun_index, transactionDatas);
  6749. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6750. random_uuid(guid);
  6751. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6752. ,MESSAGE_TYPE_CALL
  6753. ,guid
  6754. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6755. json_object_put(StopTransaction);
  6756. #if 1 // for TempStopTransaction
  6757. //Delete TempStopTransaction
  6758. if((access(TempStopTransaction,F_OK))!=-1)
  6759. {
  6760. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6761. }
  6762. #endif
  6763. #if 1
  6764. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6765. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6766. {
  6767. result = PASS;
  6768. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6769. }
  6770. #endif
  6771. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6772. OCPP_insert_transaction_msg(NO, queuedata);
  6773. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6774. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6775. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6776. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6777. {
  6778. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6779. }
  6780. //for test
  6781. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6782. return result;
  6783. }
  6784. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6785. {
  6786. mtrace();
  6787. int result = FAIL;
  6788. char guid[37]={0};
  6789. char tempdata[65]={0};
  6790. int tempIndex = 0;
  6791. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6792. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6793. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6794. //set value
  6795. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6796. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6797. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6798. -1);
  6799. random_uuid(guid);
  6800. //UTC Date time
  6801. struct timeval tmnow;
  6802. struct tm *tm;
  6803. char buf[28];//, usec_buf[6];
  6804. gettimeofday(&tmnow, NULL);
  6805. time_t t;
  6806. t = time(NULL);
  6807. /*UTC time and date*/
  6808. tm = gmtime(&t);
  6809. if(dataType == ReadingContext_Sample_Clock)
  6810. {
  6811. struct tm *tmTarget;
  6812. struct timeb tbTarget;
  6813. tbTarget.time = mktime(tm);
  6814. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6815. tmTarget = gmtime(&tbTarget.time);
  6816. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6817. }
  6818. else
  6819. {
  6820. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6821. }
  6822. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6823. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6824. //********************************(1)Current.Import L1************************************************/
  6825. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6826. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6827. (dataType == ReadingContext_Trigger))
  6828. {
  6829. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6830. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6831. {
  6832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6833. {
  6834. tempIndex = ((gun_index==2) ? 1: 0);
  6835. }
  6836. else
  6837. {
  6838. tempIndex = gun_index;
  6839. }
  6840. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6841. {
  6842. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6843. {
  6844. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6845. }
  6846. }
  6847. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6848. }
  6849. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6850. {
  6851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6852. {
  6853. tempIndex = ((gun_index==2) ? 1: 0);
  6854. }
  6855. else
  6856. {
  6857. tempIndex = gun_index;
  6858. }
  6859. for (int index = 0; index < CCS_QUANTITY; index++)
  6860. {
  6861. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6862. {
  6863. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6864. }
  6865. }
  6866. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6867. }
  6868. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6869. {
  6870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6871. {
  6872. tempIndex = ((gun_index==2) ? 1: 0);
  6873. }
  6874. else
  6875. {
  6876. tempIndex = gun_index;
  6877. }
  6878. for (int index = 0; index < GB_QUANTITY; index++)
  6879. {
  6880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6881. {
  6882. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6883. }
  6884. }
  6885. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6886. }
  6887. else if(gunType[gun_index] == GUN_TYPE_DO)
  6888. {
  6889. tempIndex = gun_index;
  6890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6891. {
  6892. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6893. {
  6894. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6895. }
  6896. }
  6897. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6898. }
  6899. else
  6900. {
  6901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6902. {
  6903. tempIndex = 2;
  6904. }
  6905. else
  6906. {
  6907. tempIndex = gun_index;
  6908. }
  6909. for (int index = 0; index < AC_QUANTITY; index++)
  6910. {
  6911. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6912. {
  6913. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6914. }
  6915. }
  6916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6917. }
  6918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6923. }
  6924. //********************************(2)Energy.Active.Import.Register ************************************************/
  6925. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6926. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6927. (dataType == ReadingContext_Trigger))
  6928. {
  6929. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6930. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6931. {
  6932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6933. {
  6934. tempIndex = ((gun_index==2) ? 1: 0);
  6935. }
  6936. else
  6937. {
  6938. tempIndex = gun_index;
  6939. }
  6940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6941. {
  6942. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6943. {
  6944. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6945. }
  6946. }
  6947. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6948. }
  6949. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6950. {
  6951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6952. {
  6953. tempIndex = ((gun_index==2) ? 1: 0);
  6954. }
  6955. else
  6956. {
  6957. tempIndex = gun_index;
  6958. }
  6959. for (int index = 0; index < CCS_QUANTITY; index++)
  6960. {
  6961. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6962. {
  6963. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6964. }
  6965. }
  6966. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6967. }
  6968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6969. {
  6970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6971. {
  6972. tempIndex = ((gun_index==2) ? 1: 0);
  6973. }
  6974. else
  6975. {
  6976. tempIndex = gun_index;
  6977. }
  6978. for (int index = 0; index < GB_QUANTITY; index++)
  6979. {
  6980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6981. {
  6982. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6983. }
  6984. }
  6985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6986. }
  6987. else if(gunType[gun_index] == GUN_TYPE_DO)
  6988. {
  6989. tempIndex = gun_index;
  6990. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6991. {
  6992. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6993. {
  6994. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6995. }
  6996. }
  6997. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6998. }
  6999. else
  7000. {
  7001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7002. {
  7003. tempIndex = 2;
  7004. }
  7005. else
  7006. {
  7007. tempIndex = gun_index;
  7008. }
  7009. for (int index = 0; index < AC_QUANTITY; index++)
  7010. {
  7011. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7012. {
  7013. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7014. }
  7015. }
  7016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7017. }
  7018. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7020. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7021. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7023. }
  7024. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7025. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7026. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7027. (dataType == ReadingContext_Trigger))
  7028. {
  7029. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7030. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7031. {
  7032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7033. {
  7034. tempIndex = ((gun_index==2) ? 1: 0);
  7035. }
  7036. else
  7037. {
  7038. tempIndex = gun_index;
  7039. }
  7040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7041. {
  7042. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7043. {
  7044. if(dataType == ReadingContext_Sample_Clock)
  7045. {
  7046. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7047. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7048. }
  7049. else if(dataType == ReadingContext_Sample_Periodic)
  7050. {
  7051. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7052. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7053. }
  7054. else
  7055. {
  7056. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7057. }
  7058. }
  7059. } // END OF FOR CHAdeMO_QUANTITY
  7060. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7061. }
  7062. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7063. {
  7064. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7065. {
  7066. tempIndex = ((gun_index==2) ? 1: 0);
  7067. }
  7068. else
  7069. {
  7070. tempIndex = gun_index;
  7071. }
  7072. for (int index = 0; index < CCS_QUANTITY; index++)
  7073. {
  7074. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7075. {
  7076. if(dataType == ReadingContext_Sample_Clock)
  7077. {
  7078. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7079. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7080. }
  7081. else if(dataType == ReadingContext_Sample_Periodic)
  7082. {
  7083. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7084. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7085. }
  7086. else
  7087. {
  7088. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7089. }
  7090. }
  7091. } // END OF CCS_QUANTITY
  7092. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7093. }
  7094. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7095. {
  7096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7097. {
  7098. tempIndex = ((gun_index==2) ? 1: 0);
  7099. }
  7100. else
  7101. {
  7102. tempIndex = gun_index;
  7103. }
  7104. for (int index = 0; index < GB_QUANTITY; index++)
  7105. {
  7106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7107. {
  7108. if(dataType == ReadingContext_Sample_Clock)
  7109. {
  7110. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7111. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7112. }
  7113. else if(dataType == ReadingContext_Sample_Periodic)
  7114. {
  7115. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7116. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7117. }
  7118. else
  7119. {
  7120. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7121. }
  7122. }
  7123. } // END OF GB_QUANTITY
  7124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7125. }
  7126. else if(gunType[gun_index] == GUN_TYPE_DO)
  7127. {
  7128. tempIndex = gun_index;
  7129. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7130. {
  7131. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7132. {
  7133. if(dataType == ReadingContext_Sample_Clock)
  7134. {
  7135. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7136. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7137. }
  7138. else if(dataType == ReadingContext_Sample_Periodic)
  7139. {
  7140. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7141. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7142. }
  7143. else
  7144. {
  7145. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7146. }
  7147. }
  7148. }
  7149. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7150. }
  7151. else
  7152. {
  7153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7154. {
  7155. tempIndex = 2;
  7156. }
  7157. else
  7158. {
  7159. tempIndex = gun_index;
  7160. }
  7161. for (int index = 0; index < AC_QUANTITY; index++)
  7162. {
  7163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7164. {
  7165. if(dataType == ReadingContext_Sample_Clock)
  7166. {
  7167. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7168. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7169. }
  7170. else if(dataType == ReadingContext_Sample_Periodic)
  7171. {
  7172. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7173. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7174. }
  7175. else
  7176. {
  7177. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7178. }
  7179. }
  7180. }
  7181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7182. }
  7183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7188. }
  7189. //********************************(4)Power.Active.Import************************************************/
  7190. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7191. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7192. (dataType == ReadingContext_Trigger))
  7193. {
  7194. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7195. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7196. {
  7197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7198. {
  7199. tempIndex = ((gun_index==2) ? 1: 0);
  7200. }
  7201. else
  7202. {
  7203. tempIndex = gun_index;
  7204. }
  7205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7206. {
  7207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7208. {
  7209. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7210. }
  7211. } // END OF FOR
  7212. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7213. }
  7214. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7215. {
  7216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7217. {
  7218. tempIndex = ((gun_index==2) ? 1: 0);
  7219. }
  7220. else
  7221. {
  7222. tempIndex = gun_index;
  7223. }
  7224. for (int index = 0; index < CCS_QUANTITY; index++)
  7225. {
  7226. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7227. {
  7228. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7229. }
  7230. }
  7231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7232. }
  7233. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7234. {
  7235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7236. {
  7237. tempIndex = ((gun_index==2) ? 1: 0);
  7238. }
  7239. else
  7240. {
  7241. tempIndex = gun_index;
  7242. }
  7243. for (int index = 0; index < GB_QUANTITY; index++)
  7244. {
  7245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7246. {
  7247. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7248. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7249. }
  7250. }
  7251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7252. }
  7253. else if(gunType[gun_index] == GUN_TYPE_DO)
  7254. {
  7255. tempIndex = gun_index;
  7256. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7257. {
  7258. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7259. {
  7260. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7261. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7262. }
  7263. }
  7264. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7265. }
  7266. else
  7267. {
  7268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7269. {
  7270. tempIndex = 2;
  7271. }
  7272. else
  7273. {
  7274. tempIndex = gun_index;
  7275. }
  7276. for (int index = 0; index < AC_QUANTITY; index++)
  7277. {
  7278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7279. {
  7280. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7281. }
  7282. }
  7283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7284. }
  7285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7286. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7288. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7289. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7290. }
  7291. //***********************************************(5)VOLTAGE L1******************************************************/
  7292. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7293. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7294. (dataType == ReadingContext_Trigger))
  7295. {
  7296. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7297. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7298. {
  7299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7300. {
  7301. tempIndex = ((gun_index==2) ? 1: 0);
  7302. }
  7303. else
  7304. {
  7305. tempIndex = gun_index;
  7306. }
  7307. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7308. {
  7309. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7310. {
  7311. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7312. }
  7313. }
  7314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7315. }
  7316. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7317. {
  7318. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7319. {
  7320. tempIndex = ((gun_index==2) ? 1: 0);
  7321. }
  7322. else
  7323. {
  7324. tempIndex = gun_index;
  7325. }
  7326. for (int index = 0; index < CCS_QUANTITY; index++)
  7327. {
  7328. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7329. {
  7330. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7331. }
  7332. }
  7333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7334. }
  7335. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7336. {
  7337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7338. {
  7339. tempIndex = ((gun_index==2) ? 1: 0);
  7340. }
  7341. else
  7342. {
  7343. tempIndex = gun_index;
  7344. }
  7345. for (int index = 0; index < GB_QUANTITY; index++)
  7346. {
  7347. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7348. {
  7349. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7350. }
  7351. }
  7352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7353. }
  7354. else if(gunType[gun_index] == GUN_TYPE_DO)
  7355. {
  7356. tempIndex = gun_index;
  7357. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7358. {
  7359. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7360. {
  7361. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7362. }
  7363. }
  7364. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7365. }
  7366. else
  7367. {
  7368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7369. {
  7370. tempIndex = 2;
  7371. }
  7372. else
  7373. {
  7374. tempIndex = gun_index;
  7375. }
  7376. for (int index = 0; index < AC_QUANTITY; index++)
  7377. {
  7378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7379. {
  7380. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7381. }
  7382. }
  7383. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7384. }
  7385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7389. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7390. }
  7391. //***********************************************(6)SOC******************************************************/
  7392. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7393. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7394. (dataType == ReadingContext_Trigger))
  7395. {
  7396. 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))
  7397. {
  7398. //idx_sample=5;
  7399. //sampledValue = NULL;
  7400. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7401. {
  7402. tempIndex = ((gun_index==2) ? 1: 0);
  7403. }
  7404. else
  7405. {
  7406. tempIndex = gun_index;
  7407. }
  7408. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7409. {
  7410. //tempIndex = ((gun_index==2) ? 1: 0);
  7411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7412. {
  7413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7414. {
  7415. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7416. }
  7417. }
  7418. }
  7419. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7420. {
  7421. //tempIndex = ((gun_index==2) ? 1: 0);
  7422. for (int index = 0; index < CCS_QUANTITY; index++)
  7423. {
  7424. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7425. {
  7426. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7427. }
  7428. }
  7429. }
  7430. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7431. {
  7432. //tempIndex = ((gun_index==2) ? 1: 0);
  7433. for (int index = 0; index < GB_QUANTITY; index++)
  7434. {
  7435. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7436. {
  7437. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7438. }
  7439. }
  7440. }
  7441. else if(gunType[gun_index] == GUN_TYPE_DO)
  7442. {
  7443. //tempIndex = ((gun_index==2) ? 1: 0);
  7444. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7445. {
  7446. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7447. {
  7448. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7449. }
  7450. }
  7451. }
  7452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7453. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7454. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7455. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7457. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7458. }
  7459. }
  7460. //********************************(7)Current.Import L2************************************************/
  7461. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7462. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7463. (dataType == ReadingContext_Trigger))
  7464. {
  7465. // Only for AC 3 phase
  7466. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7467. {
  7468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7469. {
  7470. tempIndex = 2;
  7471. }
  7472. else
  7473. {
  7474. tempIndex = gun_index;
  7475. }
  7476. for (int index = 0; index < AC_QUANTITY; index++)
  7477. {
  7478. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7479. {
  7480. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7481. }
  7482. }
  7483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7484. }
  7485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7490. }
  7491. //********************************(8)Current.Import L3************************************************/
  7492. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7493. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7494. (dataType == ReadingContext_Trigger))
  7495. {
  7496. // Only for AC 3 phase
  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[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7512. }
  7513. }
  7514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7515. }
  7516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7521. }
  7522. //***********************************************(9)VOLTAGE L2******************************************************/
  7523. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7524. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7525. (dataType == ReadingContext_Trigger))
  7526. {
  7527. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7528. {
  7529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7530. {
  7531. tempIndex = 2;
  7532. }
  7533. else
  7534. {
  7535. tempIndex = gun_index;
  7536. }
  7537. for (int index = 0; index < AC_QUANTITY; index++)
  7538. {
  7539. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7540. {
  7541. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7542. }
  7543. }
  7544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7545. }
  7546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7551. }
  7552. //***********************************************(10)VOLTAGE L3******************************************************/
  7553. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7554. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7555. (dataType == ReadingContext_Trigger))
  7556. {
  7557. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7558. {
  7559. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7560. {
  7561. tempIndex = 2;
  7562. }
  7563. else
  7564. {
  7565. tempIndex = gun_index;
  7566. }
  7567. for (int index = 0; index < AC_QUANTITY; index++)
  7568. {
  7569. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7570. {
  7571. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7572. }
  7573. }
  7574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7575. }
  7576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7581. }
  7582. //***********************************************(11)Current.Offered******************************************************/
  7583. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7584. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7585. (dataType == ReadingContext_Trigger))
  7586. {
  7587. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7588. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7589. {
  7590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7591. {
  7592. tempIndex = ((gun_index==2) ? 1: 0);
  7593. }
  7594. else
  7595. {
  7596. tempIndex = gun_index;
  7597. }
  7598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7599. {
  7600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7601. {
  7602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7603. }
  7604. } // END OF FOR CHAdeMO_QUANTITY
  7605. }
  7606. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7607. {
  7608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7609. {
  7610. tempIndex = ((gun_index==2) ? 1: 0);
  7611. }
  7612. else
  7613. {
  7614. tempIndex = gun_index;
  7615. }
  7616. for (int index = 0; index < CCS_QUANTITY; index++)
  7617. {
  7618. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7619. {
  7620. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7621. }
  7622. } // END OF CCS_QUANTITY
  7623. }
  7624. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7625. {
  7626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7627. {
  7628. tempIndex = ((gun_index==2) ? 1: 0);
  7629. }
  7630. else
  7631. {
  7632. tempIndex = gun_index;
  7633. }
  7634. for (int index = 0; index < GB_QUANTITY; index++)
  7635. {
  7636. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7637. {
  7638. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7639. }
  7640. } // END OF GB_QUANTITY
  7641. }
  7642. else if(gunType[gun_index] == GUN_TYPE_DO)
  7643. {
  7644. tempIndex = gun_index;
  7645. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7646. {
  7647. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7648. {
  7649. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7650. }
  7651. }
  7652. }
  7653. else
  7654. {
  7655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7656. {
  7657. tempIndex = 2;
  7658. }
  7659. else
  7660. {
  7661. tempIndex = gun_index;
  7662. }
  7663. for (int index = 0; index < AC_QUANTITY; index++)
  7664. {
  7665. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7666. {
  7667. uint16_t currentOffer;
  7668. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7669. {
  7670. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7671. }
  7672. else
  7673. {
  7674. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7675. }
  7676. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7677. }
  7678. }
  7679. }
  7680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7685. }
  7686. //***********************************************(12)Power.Offered******************************************************/
  7687. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7688. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7689. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7690. {
  7691. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7692. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7693. {
  7694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7695. {
  7696. tempIndex = ((gun_index==2) ? 1: 0);
  7697. }
  7698. else
  7699. {
  7700. tempIndex = gun_index;
  7701. }
  7702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7703. {
  7704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7705. {
  7706. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7707. }
  7708. } // END OF FOR CHAdeMO_QUANTITY
  7709. }
  7710. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7711. {
  7712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7713. {
  7714. tempIndex = ((gun_index==2) ? 1: 0);
  7715. }
  7716. else
  7717. {
  7718. tempIndex = gun_index;
  7719. }
  7720. for (int index = 0; index < CCS_QUANTITY; index++)
  7721. {
  7722. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7723. {
  7724. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7725. }
  7726. } // END OF CCS_QUANTITY
  7727. }
  7728. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7729. {
  7730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7731. {
  7732. tempIndex = ((gun_index==2) ? 1: 0);
  7733. }
  7734. else
  7735. {
  7736. tempIndex = gun_index;
  7737. }
  7738. for (int index = 0; index < GB_QUANTITY; index++)
  7739. {
  7740. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7741. {
  7742. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7743. }
  7744. } // END OF GB_QUANTITY
  7745. }
  7746. else if(gunType[gun_index] == GUN_TYPE_DO)
  7747. {
  7748. tempIndex = gun_index;
  7749. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7750. {
  7751. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7752. {
  7753. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7754. }
  7755. }
  7756. }
  7757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7761. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7762. }
  7763. // Message create ====================================================================================================
  7764. if(TRUE)
  7765. {
  7766. json_object *MeterValueReq = json_object_new_object();
  7767. json_object *MeterValues = json_object_new_array();
  7768. json_object *sampledValues = json_object_new_array();
  7769. json_object *sampledValuesBuffer = json_object_new_array();
  7770. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7771. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7772. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7773. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7774. {
  7775. json_object *MeterValue = json_object_new_object();
  7776. json_object *MeterValueBuffer = json_object_new_object();
  7777. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7778. {
  7779. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7780. {
  7781. json_object *sampledValue = json_object_new_object();
  7782. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7783. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7784. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7785. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7786. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7787. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7788. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7789. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7790. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7791. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7792. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7793. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7794. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7795. json_object_array_add(sampledValues, sampledValue);
  7796. // For StopTxn data
  7797. 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)) ||
  7798. ((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)))
  7799. {
  7800. json_object *sampledValue = json_object_new_object();
  7801. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7802. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7803. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7804. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7805. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7806. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7807. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7808. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7809. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7810. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7811. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7812. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7813. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7814. json_object_array_add(sampledValuesBuffer, sampledValue);
  7815. }
  7816. }
  7817. }
  7818. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7819. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7820. json_object_array_add(MeterValues, MeterValue);
  7821. // For StopTxn data
  7822. if((dataType != ReadingContext_Trigger) &&
  7823. (json_object_array_length(sampledValuesBuffer) > 0))
  7824. {
  7825. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7826. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  7827. 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));
  7828. json_object_put(MeterValueBuffer);
  7829. }
  7830. else
  7831. {
  7832. json_object_put(sampledValuesBuffer);
  7833. json_object_put(MeterValueBuffer);
  7834. }
  7835. }
  7836. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7837. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7838. ,gun_index + 1
  7839. ,MESSAGE_TYPE_CALL
  7840. ,guid
  7841. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7842. json_object_put(MeterValueReq);
  7843. }
  7844. // Put request guid to hash map
  7845. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7846. 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*/)
  7847. {
  7848. result = PASS;
  7849. //DEBUG_INFO("MeterValues mapitem pass\n");
  7850. }
  7851. if((dataType != ReadingContext_Trigger) &&
  7852. (dataType != ReadingContext_Sample_Clock) &&
  7853. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7854. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7855. else
  7856. {
  7857. if(FirstHeartBeat)
  7858. LWS_Send(queuedata +2);
  7859. }
  7860. return result;
  7861. }
  7862. int sendLogStatusNotificationRequest(char *status)
  7863. {
  7864. mtrace();
  7865. int result = PASS;
  7866. char message[4096]={0};
  7867. char guid[37]={0};
  7868. char tempdata[128]={0};
  7869. json_object *LogStatusNotification = json_object_new_object();
  7870. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7871. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7872. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7873. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7874. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7875. random_uuid(guid);
  7876. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7877. json_object_put(LogStatusNotification);
  7878. LWS_Send(message);
  7879. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7880. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7881. {
  7882. result = PASS;
  7883. }
  7884. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7885. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7886. return result;
  7887. }
  7888. int sendSecurityEventNotificationRequest()
  7889. {
  7890. mtrace();
  7891. int result = PASS;
  7892. char message[4096]={0};
  7893. char guid[37]={0};
  7894. char tempdata[128]={0};
  7895. json_object *SecurityEventNotification = json_object_new_object();
  7896. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7897. //Stop Transaction Time
  7898. struct timeval tmnow;
  7899. struct tm *tm;
  7900. gettimeofday(&tmnow, NULL);
  7901. time_t t;
  7902. t = time(NULL);
  7903. /*UTC time and date*/
  7904. tm = gmtime(&t);
  7905. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7906. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7907. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7908. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7909. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7910. random_uuid(guid);
  7911. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7912. json_object_put(SecurityEventNotification);
  7913. LWS_Send(message);
  7914. sprintf(tempdata, "SecurityEventNotification,0");
  7915. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7916. {
  7917. result = PASS;
  7918. }
  7919. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7920. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7921. return result;
  7922. }
  7923. int sendSignCertificateRequest()
  7924. {
  7925. mtrace();
  7926. int result = PASS;
  7927. char message[4096]={0};
  7928. char guid[37]={0};
  7929. char tempdata[128]={0};
  7930. json_object *SignCertificate = json_object_new_object();
  7931. DEBUG_INFO("sendSignCertificateRequest...\n");
  7932. // Read csr file content
  7933. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7934. FILE *fp=fopen(CSR_CP,"r");
  7935. char *line = NULL;
  7936. size_t len = 0;
  7937. while(getline(&line, &len, fp) != -1)
  7938. {
  7939. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7940. {
  7941. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7942. }
  7943. }
  7944. fclose(fp);
  7945. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7946. random_uuid(guid);
  7947. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7948. json_object_put(SignCertificate);
  7949. LWS_Send(message);
  7950. sprintf(tempdata, "SignCertificate,0");
  7951. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7952. {
  7953. result = PASS;
  7954. }
  7955. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7956. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7957. return result;
  7958. }
  7959. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7960. {
  7961. mtrace();
  7962. int result = PASS;
  7963. char message[4096]={0};
  7964. char guid[37]={0};
  7965. char tempdata[128]={0};
  7966. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  7967. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7968. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7969. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7970. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7971. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7972. random_uuid(guid);
  7973. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7974. json_object_put(SignedFirmwareStatusNotification);
  7975. LWS_Send(message);
  7976. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  7977. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7978. {
  7979. result = PASS;
  7980. }
  7981. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7982. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7983. return result;
  7984. }
  7985. //==========================================
  7986. // send confirm routine
  7987. //==========================================
  7988. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7989. {
  7990. mtrace();
  7991. int result = FAIL;
  7992. char message[100]={0};
  7993. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7994. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7995. LWS_Send(message);
  7996. result = TRUE;
  7997. return result;
  7998. }
  7999. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8000. {
  8001. mtrace();
  8002. int result = FAIL;
  8003. char message[100]={0};
  8004. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8005. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8006. LWS_Send(message);
  8007. result = TRUE;
  8008. return result;
  8009. }
  8010. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8011. {
  8012. mtrace();
  8013. int result = FAIL;
  8014. char message[100]={0};
  8015. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8016. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8017. LWS_Send(message);
  8018. result = TRUE;
  8019. return result;
  8020. }
  8021. int sendClearCacheConfirmation(char *uuid,char *payload)
  8022. {
  8023. mtrace();
  8024. int result = FAIL;
  8025. char message[500]={0};
  8026. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8027. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8028. LWS_Send(message);
  8029. return result;
  8030. }
  8031. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8032. {
  8033. mtrace();
  8034. int result = FAIL;
  8035. char message[500]={0};
  8036. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8037. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8038. LWS_Send(message);
  8039. return result;
  8040. }
  8041. int sendDataTransferConfirmation(char *uuid,char *payload)
  8042. {
  8043. mtrace();
  8044. char statusStr[20]={0};
  8045. char dataStr[10]={0};
  8046. char sstr[20]={0};
  8047. int c = 0;
  8048. char *loc;
  8049. int result = FAIL;
  8050. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8051. /**********************status**************************/
  8052. loc = strstr(payload, "status");
  8053. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8054. c = 0;
  8055. while (loc[3+strlen("status")+c] != '\"')
  8056. {
  8057. sstr[c] = loc[3+strlen("status")+c];
  8058. c++;
  8059. }
  8060. sstr[c] = '\0';
  8061. strcpy(statusStr, sstr);
  8062. /**********************data**************************/
  8063. loc = strstr(payload, "data");
  8064. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8065. c = 0;
  8066. while (loc[3+strlen("data")+c] != '\"')
  8067. {
  8068. sstr[c] = loc[3+strlen("data")+c];
  8069. c++;
  8070. }
  8071. sstr[c] = '\0';
  8072. strcpy(dataStr, sstr);
  8073. return result;
  8074. }
  8075. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8076. {
  8077. mtrace();
  8078. int result = FAIL;
  8079. char message[1000]={0};
  8080. int CompositeScheduleIndex = 0;
  8081. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8082. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8083. if(nPeriod == 0)
  8084. {
  8085. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8086. {
  8087. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8088. ,MESSAGE_TYPE_CALLRESULT
  8089. ,uuid
  8090. ,payload
  8091. ,connectorIdInt);
  8092. }
  8093. else
  8094. {
  8095. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8096. ,MESSAGE_TYPE_CALLRESULT
  8097. ,uuid
  8098. ,payload
  8099. ,connectorIdInt
  8100. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8101. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8102. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8103. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8104. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8105. }
  8106. }
  8107. else
  8108. {
  8109. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8110. ,MESSAGE_TYPE_CALLRESULT
  8111. ,uuid
  8112. ,payload
  8113. ,connectorIdInt
  8114. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8115. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8116. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8117. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8118. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8119. {
  8120. if (idx_sample == 0)
  8121. {
  8122. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8123. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8124. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8125. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8126. }
  8127. else
  8128. {
  8129. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8130. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8131. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8132. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8133. }
  8134. }
  8135. sprintf(message + strlen(message), "]}}]");
  8136. }
  8137. LWS_Send(message);
  8138. result = TRUE;
  8139. return result;
  8140. }
  8141. int sendGetConfigurationConfirmation(char *uuid)
  8142. {
  8143. mtrace();
  8144. int result = FAIL;
  8145. int MaxKeySupported = 0;
  8146. int sentConfigurationNumber= 0;
  8147. int sentunConfigurationNumber= 0;
  8148. char message[1024*10]={0};
  8149. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8150. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8151. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8152. ,MESSAGE_TYPE_CALLRESULT
  8153. ,uuid );
  8154. //configuration key
  8155. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8156. {
  8157. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8158. {
  8159. if (sentConfigurationNumber == 0)
  8160. {
  8161. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8162. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8163. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8164. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8165. }
  8166. else
  8167. {
  8168. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8169. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8170. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8171. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8172. }
  8173. sentConfigurationNumber = sentConfigurationNumber + 1;
  8174. }
  8175. }
  8176. sprintf(message + strlen(message), "]");
  8177. if(UnknownKeynum != 0)
  8178. {
  8179. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8180. //unkown key
  8181. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8182. {
  8183. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8184. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8185. if(sentunConfigurationNumber == 0)
  8186. {
  8187. sprintf(message + strlen(message), "\"%s\""
  8188. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8189. }
  8190. else
  8191. {
  8192. sprintf(message + strlen(message), ",\"%s\""
  8193. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8194. }
  8195. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8196. }
  8197. sprintf(message + strlen(message), "]");
  8198. }
  8199. sprintf(message + strlen(message), "}]");
  8200. LWS_Send(message);
  8201. return result;
  8202. }
  8203. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8204. {
  8205. mtrace();
  8206. int result = FAIL;
  8207. char message[400]={0};
  8208. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8209. if(strcmp(payload,"")==0)
  8210. {
  8211. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8212. }
  8213. else
  8214. {
  8215. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8216. }
  8217. LWS_Send(message);
  8218. result = TRUE;
  8219. return result;
  8220. }
  8221. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8222. {
  8223. mtrace();
  8224. int result = FAIL;
  8225. char message[80]={0};
  8226. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8227. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8228. LWS_Send(message);
  8229. result = TRUE;
  8230. return result;
  8231. }
  8232. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8233. {
  8234. mtrace();
  8235. int result = FAIL;
  8236. char message[80]={0};
  8237. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8238. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8239. LWS_Send(message);
  8240. result = TRUE;
  8241. return result;
  8242. }
  8243. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8244. {
  8245. mtrace();
  8246. int result = FAIL;
  8247. char message[80]={0};
  8248. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8249. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8250. LWS_Send(message);
  8251. result = TRUE;
  8252. return result;
  8253. }
  8254. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8255. {
  8256. mtrace();
  8257. int result = FAIL;
  8258. char message[80]={0};
  8259. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8260. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8261. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8262. LWS_Send(message);
  8263. result = TRUE;
  8264. return result;
  8265. }
  8266. int sendResetConfirmation(char *uuid,char *payload)
  8267. {
  8268. mtrace();
  8269. int result = FAIL;
  8270. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8271. char message[80]={0};
  8272. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8273. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8274. LWS_Send(message);
  8275. result = TRUE;
  8276. return result;
  8277. }
  8278. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8279. {
  8280. mtrace();
  8281. int result = FAIL;
  8282. char message[500]={0};
  8283. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8284. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8285. LWS_Send(message);
  8286. result = TRUE;
  8287. return result;
  8288. }
  8289. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8290. {
  8291. mtrace();
  8292. int result = FAIL;
  8293. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8294. char message[80]={0};
  8295. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8296. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8297. LWS_Send(message);
  8298. result = TRUE;
  8299. return result;
  8300. }
  8301. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8302. {
  8303. mtrace();
  8304. int result = FAIL;
  8305. char message[80]={0};
  8306. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8307. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8308. LWS_Send(message);
  8309. result = TRUE;
  8310. return result;
  8311. }
  8312. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8313. {
  8314. mtrace();
  8315. int result = FAIL;
  8316. char message[80]={0};
  8317. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8318. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8319. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8320. LWS_Send(message);
  8321. result = TRUE;
  8322. return result;
  8323. }
  8324. int sendUpdateFirmwareConfirmation(char *uuid)
  8325. {
  8326. mtrace();
  8327. int result = FAIL;
  8328. char message[60]={0};
  8329. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8330. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8331. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8332. LWS_Send(message);
  8333. result = TRUE;
  8334. return result;
  8335. }
  8336. int sendCertificateSignedConfirmation(char *uuid)
  8337. {
  8338. mtrace();
  8339. int result = PASS;
  8340. char message[4096]={0};
  8341. json_object *CertificateSigned = json_object_new_object();
  8342. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8343. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8344. sprintf(message,"[%d,\"%s\",%s]"
  8345. ,MESSAGE_TYPE_CALLRESULT
  8346. ,uuid
  8347. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8348. json_object_put(CertificateSigned);
  8349. LWS_Send(message);
  8350. return result;
  8351. }
  8352. int sendDeleteCertificateConfirmation(char *uuid)
  8353. {
  8354. mtrace();
  8355. int result = PASS;
  8356. char message[4096]={0};
  8357. json_object *DeleteCertificate = json_object_new_object();
  8358. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8359. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8360. sprintf(message,"[%d,\"%s\",%s]"
  8361. ,MESSAGE_TYPE_CALLRESULT
  8362. ,uuid
  8363. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8364. json_object_put(DeleteCertificate);
  8365. LWS_Send(message);
  8366. return result;
  8367. }
  8368. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8369. {
  8370. mtrace();
  8371. int result = PASS;
  8372. char message[4096]={0};
  8373. json_object *ExtendedTriggerMessage = json_object_new_object();
  8374. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8375. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8376. sprintf(message,"[%d,\"%s\",%s]"
  8377. ,MESSAGE_TYPE_CALLRESULT
  8378. ,uuid
  8379. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8380. json_object_put(ExtendedTriggerMessage);
  8381. LWS_Send(message);
  8382. return result;
  8383. }
  8384. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8385. {
  8386. mtrace();
  8387. int result = PASS;
  8388. char message[4096]={0};
  8389. json_object *GetInstalledCertificateIds = json_object_new_object();
  8390. json_object *certificateHashDataDatas = json_object_new_array();
  8391. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8392. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8393. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8394. {
  8395. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8396. {
  8397. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8398. {
  8399. json_object *certificateHashData = json_object_new_object();
  8400. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8401. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8402. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8403. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8404. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8405. }
  8406. }
  8407. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8408. }
  8409. else
  8410. {
  8411. json_object_put(certificateHashDataDatas);
  8412. }
  8413. sprintf(message,"[%d,\"%s\",%s]"
  8414. ,MESSAGE_TYPE_CALLRESULT
  8415. ,uuid
  8416. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8417. json_object_put(GetInstalledCertificateIds);
  8418. LWS_Send(message);
  8419. return result;
  8420. }
  8421. int sendGetLogConfirmation(char *uuid)
  8422. {
  8423. mtrace();
  8424. int result = PASS;
  8425. char message[4096]={0};
  8426. json_object *GetLog = json_object_new_object();
  8427. DEBUG_INFO("sendGetLogConfirmation...\n");
  8428. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8429. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8430. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8431. sprintf(message,"[%d,\"%s\",%s]"
  8432. ,MESSAGE_TYPE_CALLRESULT
  8433. ,uuid
  8434. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8435. json_object_put(GetLog);
  8436. LWS_Send(message);
  8437. return result;
  8438. }
  8439. int sendInstallCertificateConfirmation(char *uuid)
  8440. {
  8441. mtrace();
  8442. int result = PASS;
  8443. char message[4096]={0};
  8444. json_object *InstallCertificate = json_object_new_object();
  8445. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8446. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8447. sprintf(message,"[%d,\"%s\",%s]"
  8448. ,MESSAGE_TYPE_CALLRESULT
  8449. ,uuid
  8450. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8451. json_object_put(InstallCertificate);
  8452. LWS_Send(message);
  8453. return result;
  8454. }
  8455. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8456. {
  8457. mtrace();
  8458. int result = PASS;
  8459. char message[4096]={0};
  8460. json_object *SignedUpdateFirmware = json_object_new_object();
  8461. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8462. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8463. sprintf(message,"[%d,\"%s\",%s]"
  8464. ,MESSAGE_TYPE_CALLRESULT
  8465. ,uuid
  8466. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8467. json_object_put(SignedUpdateFirmware);
  8468. LWS_Send(message);
  8469. return result;
  8470. }
  8471. int sendUnknownConfirmation(char *uuid)
  8472. {
  8473. mtrace();
  8474. int result = PASS;
  8475. char message[256]={0};
  8476. DEBUG_INFO("sendUnknownConfirmation...\n");
  8477. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8478. LWS_Send(message);
  8479. return result;
  8480. }
  8481. //==========================================
  8482. // Handle server request routine Start
  8483. //==========================================
  8484. int handleCancelReservationRequest(char *uuid, char *payload)
  8485. {
  8486. mtrace();
  8487. int result = FAIL;
  8488. int gunNO = 0;
  8489. int reservationIdInt = -1;
  8490. char comfirmstr[20];
  8491. DEBUG_INFO("handleCancelReservationRequest...\n");
  8492. json_object *CancelReservation;
  8493. CancelReservation = json_tokener_parse(payload);
  8494. if(!is_error(CancelReservation))
  8495. {
  8496. // Required data
  8497. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8498. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8499. }
  8500. json_object_put(CancelReservation);
  8501. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8502. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8503. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8504. if(reservationIdInt != -1)
  8505. {
  8506. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8507. //check Transaction active
  8508. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8509. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8510. {
  8511. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8512. {
  8513. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8514. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8515. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8516. {
  8517. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8518. }
  8519. else
  8520. {
  8521. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8522. }
  8523. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8524. goto end;
  8525. }
  8526. }
  8527. for (int index = 0; index < CCS_QUANTITY; index++)
  8528. {
  8529. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8530. {
  8531. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8532. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8533. if(gunType[2] == GUN_TYPE_CCS)
  8534. {
  8535. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8536. }
  8537. else
  8538. {
  8539. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8540. }
  8541. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8542. goto end;
  8543. }
  8544. }
  8545. for (int index = 0; index < GB_QUANTITY; index++)
  8546. {
  8547. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8548. {
  8549. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8550. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8551. if(gunType[2] == GUN_TYPE_GBT)
  8552. {
  8553. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8554. }
  8555. else
  8556. {
  8557. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8558. }
  8559. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8560. goto end;
  8561. }
  8562. }
  8563. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8564. {
  8565. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8566. {
  8567. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8568. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8569. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8570. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8571. goto end;
  8572. }
  8573. }
  8574. for (int index = 0; index < AC_QUANTITY; index++)
  8575. {
  8576. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8577. {
  8578. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8579. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8580. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8581. {
  8582. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8583. }
  8584. else
  8585. {
  8586. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8587. }
  8588. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8589. goto end;
  8590. }
  8591. }
  8592. }
  8593. //The reservationId does NOT match the reservationId
  8594. sendCancelReservationConfirmation(uuid, comfirmstr);
  8595. end:
  8596. // Fill in ocpp packet uuid
  8597. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8598. return result;
  8599. }
  8600. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8601. {
  8602. mtrace();
  8603. int result = FAIL;
  8604. int gunIndex = -1;
  8605. char typeStr[16]={0};
  8606. char comfirmstr[20];
  8607. int specificId = FALSE;
  8608. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8609. json_object *ChangeAvailability;
  8610. ChangeAvailability = json_tokener_parse(payload);
  8611. if(!is_error(ChangeAvailability))
  8612. {
  8613. // Required data
  8614. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8615. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8616. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8617. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8618. }
  8619. json_object_put(ChangeAvailability);
  8620. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8621. {
  8622. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8623. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8624. }
  8625. else if(gunIndex == 0)
  8626. {
  8627. for(int i=0; i < gunTotalNumber; i++)
  8628. {
  8629. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8630. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8631. }
  8632. }
  8633. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8634. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8635. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8636. {
  8637. specificId = TRUE;
  8638. }
  8639. if(specificId == FALSE)
  8640. goto end;
  8641. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8642. {
  8643. //----------------------gunIndex is 0 ------------------------------------------------//
  8644. if(gunIndex == 0)
  8645. {
  8646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8647. {
  8648. for(int i=0; i < gunTotalNumber; i++)
  8649. {
  8650. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8651. {
  8652. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8653. {
  8654. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8655. {
  8656. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8657. goto end;
  8658. }
  8659. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8660. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8661. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8662. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8663. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8664. {
  8665. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8666. goto end;
  8667. }
  8668. }
  8669. }//END FOR CHAdeMO_QUANTITY
  8670. for (int index = 0; index < CCS_QUANTITY; index++)
  8671. {
  8672. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8673. {
  8674. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8675. {
  8676. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8677. goto end;
  8678. }
  8679. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8680. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8681. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8682. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8683. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8684. {
  8685. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8686. goto end;
  8687. }
  8688. }
  8689. }//END FOR CCS_QUANTITY
  8690. for (int index = 0; index < GB_QUANTITY; index++)
  8691. {
  8692. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8693. {
  8694. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8695. {
  8696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8697. goto end;
  8698. }
  8699. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8700. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8701. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8702. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8703. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8704. {
  8705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8706. goto end;
  8707. }
  8708. }
  8709. }// END FOR GB_QUANTITY
  8710. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8711. {
  8712. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8713. {
  8714. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8715. {
  8716. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8717. goto end;
  8718. }
  8719. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8720. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8721. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8722. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8723. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8724. {
  8725. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8726. goto end;
  8727. }
  8728. }
  8729. }// END FOR GENERAL_GUN_QUANTITY
  8730. for (int index = 0; index < AC_QUANTITY; index++)
  8731. {
  8732. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8733. {
  8734. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8735. {
  8736. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8737. goto end;
  8738. }
  8739. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8740. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8741. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8742. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8743. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8744. {
  8745. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8746. goto end;
  8747. }
  8748. }
  8749. }//END FOR AC_QUANTITY
  8750. }// END FOR gunTotalNumber
  8751. }
  8752. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8753. {
  8754. for(int i=0; i < gunTotalNumber; i++)
  8755. {
  8756. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8757. {
  8758. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8759. goto end;
  8760. }
  8761. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8762. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8763. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8764. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8765. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8766. {
  8767. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8768. goto end;
  8769. }
  8770. }
  8771. }
  8772. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8773. goto end;
  8774. }
  8775. //----------------------gunIndex is not 0 ------------------------------------------------//
  8776. //check Transaction active
  8777. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8778. {
  8779. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8780. {
  8781. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8782. {
  8783. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8784. goto end;
  8785. }
  8786. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8787. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8788. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8789. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8790. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8791. {
  8792. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8793. goto end;
  8794. }
  8795. else
  8796. {
  8797. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8798. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8799. goto end;
  8800. }
  8801. }
  8802. }//END FOR CHAdeMO_QUANTITY
  8803. for (int index = 0; index < CCS_QUANTITY; index++)
  8804. {
  8805. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8806. {
  8807. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8808. {
  8809. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8810. goto end;
  8811. }
  8812. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8813. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8814. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8815. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8816. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8817. {
  8818. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8819. goto end;
  8820. }
  8821. else
  8822. {
  8823. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8824. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8825. goto end;
  8826. }
  8827. }
  8828. }//END FOR CCS_QUANTITY
  8829. for (int index = 0; index < GB_QUANTITY; index++)
  8830. {
  8831. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8832. {
  8833. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8834. {
  8835. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8836. goto end;
  8837. }
  8838. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8839. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8840. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8841. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8842. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8843. {
  8844. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8845. goto end;
  8846. }
  8847. else
  8848. {
  8849. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8850. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8851. goto end;
  8852. }
  8853. }
  8854. }// END FOR GB_QUANTITY
  8855. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8856. {
  8857. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8858. {
  8859. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8860. {
  8861. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8862. goto end;
  8863. }
  8864. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8865. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8866. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8867. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8868. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8869. {
  8870. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8871. goto end;
  8872. }
  8873. else
  8874. {
  8875. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8876. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8877. goto end;
  8878. }
  8879. }
  8880. }// END FOR GENERAL_GUN_QUANTITY
  8881. for (int index = 0; index < AC_QUANTITY; index++)
  8882. {
  8883. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8884. {
  8885. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8886. {
  8887. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8888. goto end;
  8889. }
  8890. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8891. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8892. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8893. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8894. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8895. {
  8896. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8897. goto end;
  8898. }
  8899. else
  8900. {
  8901. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8902. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8903. goto end;
  8904. }
  8905. }
  8906. }//END FOR AC_QUANTITY
  8907. }//END FOR AvailabilityTypeStr[Inoperative]
  8908. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8909. {
  8910. //----------------------gunIndex is 0 ------------------------------------------------//
  8911. if(gunIndex == 0)
  8912. {
  8913. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8914. {
  8915. for(int i=0; i < gunTotalNumber; i++)
  8916. {
  8917. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8918. {
  8919. 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
  8920. {
  8921. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8922. goto end;
  8923. }
  8924. }//END FOR CHAdeMO_QUANTITY
  8925. for (int index = 0; index < CCS_QUANTITY; index++)
  8926. {
  8927. 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
  8928. {
  8929. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8930. goto end;
  8931. }
  8932. }//END FOR CCS_QUANTITY
  8933. for (int index = 0; index < GB_QUANTITY; index++)
  8934. {
  8935. 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
  8936. {
  8937. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8938. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8939. goto end;
  8940. }
  8941. }// END FOR GB_QUANTITY
  8942. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8943. {
  8944. 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
  8945. {
  8946. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8947. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8948. goto end;
  8949. }
  8950. }// END FOR GENERAL_GUN_QUANTITY
  8951. for (int index = 0; index < AC_QUANTITY; index++)
  8952. {
  8953. 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
  8954. {
  8955. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8956. goto end;
  8957. }
  8958. }//END FOR CHAdeMO_QUANTITY
  8959. }// END FOR gunTotalNumber
  8960. }
  8961. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8962. {
  8963. for(int i=0; i < gunTotalNumber; i++)
  8964. {
  8965. for (int index = 0; index < AC_QUANTITY; index++)
  8966. {
  8967. 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
  8968. {
  8969. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8970. goto end;
  8971. }
  8972. }//END FOR CHAdeMO_QUANTITY
  8973. } // END FOR gunTotalNumber
  8974. }
  8975. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8976. goto end;
  8977. }
  8978. //----------------------gunIndex is not 0 ------------------------------------------------//
  8979. //check Transaction active
  8980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8981. {
  8982. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8983. {
  8984. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8985. goto end;
  8986. }
  8987. }//END FOR CHAdeMO_QUANTITY
  8988. for (int index = 0; index < CCS_QUANTITY; index++)
  8989. {
  8990. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8991. {
  8992. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8993. goto end;
  8994. }
  8995. }//END FOR CCS_QUANTITY
  8996. for (int index = 0; index < GB_QUANTITY; index++)
  8997. {
  8998. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8999. {
  9000. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9001. goto end;
  9002. }
  9003. }// END FOR GB_QUANTITY
  9004. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9005. {
  9006. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9007. {
  9008. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9009. goto end;
  9010. }
  9011. }// END FOR GENERAL_GUN_QUANTITY
  9012. for (int index = 0; index < AC_QUANTITY; index++)
  9013. {
  9014. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9015. {
  9016. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9017. goto end;
  9018. }
  9019. }//END FOR AC_QUANTITY
  9020. }//END FOR AvailabilityTypeStr[Operative]
  9021. end:
  9022. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9023. {
  9024. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9025. }
  9026. else
  9027. {
  9028. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9029. }
  9030. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9031. {
  9032. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9033. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9034. }
  9035. else if(gunIndex == 0)
  9036. {
  9037. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9038. {
  9039. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9040. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9041. }
  9042. }
  9043. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9044. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9045. return result;
  9046. }
  9047. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9048. {
  9049. mtrace();
  9050. int valueInvalid = NO;
  9051. int result = FAIL;
  9052. char keystr[40]={0};
  9053. char valuestr[501]={0}; //value should be limited in 500 bytes
  9054. char comfirmstr[20]={0};
  9055. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9056. json_object *ChangeConfiguration;
  9057. ChangeConfiguration = json_tokener_parse(payload);
  9058. if(!is_error(ChangeConfiguration))
  9059. {
  9060. // Required data
  9061. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9062. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9063. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9064. {
  9065. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9066. }
  9067. else
  9068. {
  9069. valueInvalid = YES;
  9070. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9071. }
  9072. }
  9073. json_object_put(ChangeConfiguration);
  9074. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9075. {
  9076. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9077. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9078. }
  9079. else
  9080. {
  9081. int status = setKeyValue(keystr, valuestr);
  9082. switch(status)
  9083. {
  9084. case ConfigurationStatus_Accepted:
  9085. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9086. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9087. StoreConfigurationTable();
  9088. break;
  9089. case RebootRequired:
  9090. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9091. StoreConfigurationTable();
  9092. break;
  9093. case NotSupported:
  9094. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9095. break;
  9096. case ConfigurationStatus_Rejected:
  9097. default:
  9098. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9099. break;
  9100. }
  9101. }
  9102. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9103. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9104. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9105. {
  9106. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9107. SetOcppConnStatus(FALSE);
  9108. }
  9109. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9110. {
  9111. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9112. }
  9113. return result;
  9114. }
  9115. int handleClearCacheRequest(char *uuid, char *payload)
  9116. {
  9117. mtrace();
  9118. int result = FAIL;
  9119. char comfirmstr[20];
  9120. char rmFileCmd[100]={0};
  9121. struct stat stats;
  9122. DEBUG_INFO("handleClearCacheRequest...\n");
  9123. stat("/Storage/OCPP", &stats);
  9124. // Check for directory existence
  9125. if (S_ISDIR(stats.st_mode) == 1)
  9126. {}
  9127. else
  9128. {
  9129. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9130. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9131. system(rmFileCmd);
  9132. }
  9133. if(OCPP_cleanLocalCache())
  9134. {
  9135. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9136. }
  9137. else
  9138. {
  9139. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9140. }
  9141. sendClearCacheConfirmation(uuid, comfirmstr);
  9142. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9143. return result;
  9144. }
  9145. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9146. {
  9147. mtrace();
  9148. int result = FAIL;
  9149. int resultRename;
  9150. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9151. char chargingProfilePurposeStr[26]={0};
  9152. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9153. char tempchargingProfilePurposeStr[26]={0};
  9154. char str[100]={0};
  9155. char fname[200]={0};
  9156. char comfirmstr[20]={0};
  9157. char word[1600]={0};
  9158. int clearflag = FALSE;
  9159. int chargingProfileIdIsNULL = FALSE;
  9160. int connectorIsNULL = FALSE;
  9161. int chargingProfilePurposeIsNULL = FALSE;
  9162. int stackLevelIsNULL = FALSE;
  9163. //int GotoEnd = FALSE;
  9164. FILE *fptr1, *fptr2;
  9165. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9166. int n_chargingProfile=0;
  9167. int isEmptyFile = FALSE;
  9168. char sLineWord[1600]={0};
  9169. char chargingProfiles[10][100]={0};
  9170. int ChargeProfileCount = 0;
  9171. int ch;
  9172. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9173. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9174. json_object *ClearChargingProfile;
  9175. ClearChargingProfile = json_tokener_parse(payload);
  9176. if(!is_error(ClearChargingProfile))
  9177. {
  9178. // Optional data
  9179. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9180. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9181. else
  9182. chargingProfileIdIsNULL = TRUE;
  9183. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9184. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9185. else
  9186. connectorIsNULL = TRUE;
  9187. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9188. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9189. else
  9190. chargingProfilePurposeIsNULL = TRUE;
  9191. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9192. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9193. else
  9194. stackLevelIsNULL = TRUE;
  9195. }
  9196. json_object_put(ClearChargingProfile);
  9197. if(connectorIsNULL == FALSE)
  9198. {
  9199. switch(connectorIdInt)
  9200. {
  9201. case 0:
  9202. if(chargingProfilePurposeIsNULL == TRUE)
  9203. {
  9204. int l = 0;
  9205. strcpy(fname, ChargePointMaxProfile_JSON);
  9206. if((access(fname,F_OK))!=-1)
  9207. {
  9208. strcpy(chargingProfiles[l], fname);
  9209. l = l + 1;
  9210. }
  9211. strcpy(fname, TxDefaultProfile_0_JSON);
  9212. if((access(fname,F_OK))!=-1)
  9213. {
  9214. strcpy(chargingProfiles[l], fname);
  9215. l = l + 1;
  9216. }
  9217. ChargeProfileCount = l;
  9218. }
  9219. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9220. {
  9221. strcpy(fname, ChargePointMaxProfile_JSON);
  9222. if((access(fname,F_OK))!=-1)
  9223. {
  9224. strcpy(chargingProfiles[0], fname);
  9225. ChargeProfileCount = 1;
  9226. }
  9227. }
  9228. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9229. {
  9230. strcpy(fname, TxDefaultProfile_0_JSON);
  9231. if((access(fname,F_OK))!=-1)
  9232. {
  9233. strcpy(chargingProfiles[0], fname);
  9234. ChargeProfileCount = 1;
  9235. }
  9236. }
  9237. break;
  9238. default:
  9239. if(chargingProfilePurposeIsNULL == TRUE)
  9240. {
  9241. int m = 0;
  9242. memset(fname, 0, ARRAY_SIZE(fname));
  9243. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9244. if((access(fname,F_OK))!=-1)
  9245. {
  9246. strcpy(chargingProfiles[m], fname);
  9247. m = m + 1;
  9248. }
  9249. memset(fname, 0, ARRAY_SIZE(fname));
  9250. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9251. if((access(fname,F_OK))!=-1)
  9252. {
  9253. strcpy(chargingProfiles[m], fname);
  9254. m = m + 1;
  9255. }
  9256. ChargeProfileCount = m;
  9257. }
  9258. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9259. {
  9260. //strcpy(fname, TxDefaultProfile_1_JSON);
  9261. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9262. if((access(fname,F_OK))!=-1)
  9263. {
  9264. strcpy(chargingProfiles[0], fname);
  9265. ChargeProfileCount = 1;
  9266. }
  9267. }
  9268. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9269. {
  9270. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9271. if((access(fname,F_OK))!=-1)
  9272. {
  9273. strcpy(chargingProfiles[0], fname);
  9274. ChargeProfileCount = 1;
  9275. }
  9276. //strcpy(fname, TxProfile_1_JSON);
  9277. }
  9278. //strcpy(fname, ChargePointMaxProfile_JSON );
  9279. break;
  9280. }
  9281. }
  9282. else // Check all Charging Profiles
  9283. {
  9284. int i = 0;
  9285. char fnametemp[200]={0};
  9286. ChargeProfileCount = 0;
  9287. //Check ChargePointMaxProfile.json exit
  9288. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9289. {
  9290. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9291. i = i + 1;
  9292. }
  9293. //Check TxDefaultProfile_0.json exit
  9294. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9295. {
  9296. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9297. i = i + 1;
  9298. }
  9299. //Check TxDefaultProfile_%d.json
  9300. for(int j=1; j <= gunTotalNumber; j++)
  9301. {
  9302. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9303. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9304. if((access(fnametemp,F_OK))!=-1)
  9305. {
  9306. strcpy(chargingProfiles[i], fnametemp);
  9307. i = i + 1;
  9308. }
  9309. }
  9310. //Check TxProfile_%d.json
  9311. for(int j=1; j <= gunTotalNumber; j++)
  9312. {
  9313. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9314. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9315. if((access(fnametemp,F_OK))!=-1)
  9316. {
  9317. strcpy(chargingProfiles[i], fnametemp);
  9318. i = i + 1;
  9319. }
  9320. }
  9321. ChargeProfileCount = i;
  9322. }// End connectorIsNULL is TRUE
  9323. if(ChargeProfileCount == 0)
  9324. {
  9325. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9326. goto end;
  9327. }
  9328. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9329. {
  9330. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9331. goto end;
  9332. }
  9333. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9334. {
  9335. memset(str, 0, ARRAY_SIZE(str));
  9336. // clear temp file
  9337. sprintf(str,"rm -f %s",temp);
  9338. system(str);
  9339. for(int k=0; k < ChargeProfileCount; k++)
  9340. {
  9341. memset(str, 0, ARRAY_SIZE(str));
  9342. //clear file in C
  9343. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9344. system(str);
  9345. }
  9346. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9347. goto end;
  9348. }
  9349. else if(connectorIsNULL == TRUE)
  9350. {
  9351. for(int k=0; k < ChargeProfileCount; k++)
  9352. {
  9353. fptr1 = fopen(chargingProfiles[k], "r");
  9354. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9355. //Check Charging Profile Count
  9356. while(fscanf(fptr1, "%s", word) != EOF)
  9357. {
  9358. //DEBUG_INFO("word=%s\n",word);
  9359. if(strstr(word, "chargingProfileId")!= NULL)
  9360. {
  9361. //DEBUG_INFO("test chargingProfileId \n");
  9362. n_chargingProfile = n_chargingProfile + 1;
  9363. //DEBUG_INFO("chargingProfileId Found\n");
  9364. }
  9365. }
  9366. rewind(fptr1);
  9367. //search Charging Profile Element
  9368. //int i= 0;
  9369. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9370. {
  9371. json_object *tmpProfilee;
  9372. tmpProfilee = json_tokener_parse(sLineWord);
  9373. if(!is_error(tmpProfilee))
  9374. {
  9375. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9376. {
  9377. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9378. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9379. }
  9380. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9381. {
  9382. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9383. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9384. }
  9385. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9386. {
  9387. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9388. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9389. }
  9390. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9391. {
  9392. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9393. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9394. }
  9395. }
  9396. json_object_put(tmpProfilee);
  9397. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9398. {
  9399. //------- not write to fptr2-------//
  9400. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9401. //clearflag = TRUE;
  9402. }
  9403. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9404. {
  9405. //------- not write to fptr2-------//
  9406. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9407. }
  9408. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9409. {
  9410. //------- not write to fptr2-------//
  9411. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9412. }
  9413. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9414. {
  9415. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9416. }
  9417. else
  9418. {
  9419. fprintf(fptr2, sLineWord);//writing data into file
  9420. }
  9421. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9422. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9423. if(clearflag == TRUE)
  9424. {
  9425. fclose(fptr1);
  9426. fclose(fptr2);
  9427. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9428. system(str);
  9429. // clear temp file
  9430. sprintf(str,"rm -f %s",temp);
  9431. system(str);
  9432. }
  9433. else
  9434. {
  9435. fclose(fptr1);
  9436. fclose(fptr2);
  9437. memset(str, 0, ARRAY_SIZE(str));
  9438. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9439. system(str);
  9440. resultRename = rename(temp, chargingProfiles[k]);
  9441. if(resultRename == 0)
  9442. {
  9443. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9444. }
  9445. else
  9446. {
  9447. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9448. }
  9449. if(comfirmstr[0]== 0)
  9450. {
  9451. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9452. }
  9453. //Check chargingProfile is empty file
  9454. /*------ Read the file ----------------*/
  9455. fptr1=fopen(chargingProfiles[k],"r");
  9456. ch=fgetc(fptr1);
  9457. rewind(fptr1);
  9458. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9459. if(ch!=EOF)
  9460. {
  9461. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9462. {
  9463. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9464. if(sLineWord[0]=='\0')
  9465. {
  9466. isEmptyFile = TRUE;
  9467. break;
  9468. }
  9469. else
  9470. {
  9471. isEmptyFile = FALSE;
  9472. break;
  9473. }
  9474. }
  9475. }
  9476. else
  9477. isEmptyFile = TRUE;
  9478. fclose(fptr1);
  9479. if(isEmptyFile == TRUE)
  9480. {
  9481. memset(str, 0, ARRAY_SIZE(str));
  9482. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9483. system(str);
  9484. }
  9485. }
  9486. }// End of while(int k=0; k < ChargePointCount; k++)
  9487. }
  9488. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9489. {
  9490. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9491. for(int k=0; k < ChargeProfileCount; k++)
  9492. {
  9493. fptr1 = fopen(chargingProfiles[k], "r");
  9494. fptr2 = fopen(temp, "w+");
  9495. //Check Charging Profile Count
  9496. while(fscanf(fptr1, "%s", word) != EOF)
  9497. {
  9498. //DEBUG_INFO("word=%s\n",word);
  9499. if(strstr(word, "chargingProfileId")!= NULL)
  9500. {
  9501. n_chargingProfile = n_chargingProfile + 1;
  9502. }
  9503. }
  9504. rewind(fptr1);
  9505. //search Charging Profile Element
  9506. //int i= 0;
  9507. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9508. {
  9509. json_object *tmpProfilee;
  9510. tmpProfilee = json_tokener_parse(sLineWord);
  9511. if(!is_error(tmpProfilee))
  9512. {
  9513. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9514. {
  9515. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9516. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9517. }
  9518. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9519. {
  9520. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9521. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9522. }
  9523. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9524. {
  9525. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9526. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9527. }
  9528. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9529. {
  9530. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9531. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9532. }
  9533. }
  9534. json_object_put(tmpProfilee);
  9535. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9536. {
  9537. //------- not write to fptr2-------//
  9538. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9539. //clearflag = TRUE;
  9540. }
  9541. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9542. {
  9543. //------- not write to fptr2-------//
  9544. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9545. }
  9546. else if(stackLevelIsNULL == TRUE)
  9547. {
  9548. //Clear Whole File
  9549. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9550. clearflag = TRUE;
  9551. break;
  9552. }
  9553. else
  9554. {
  9555. fprintf(fptr2, sLineWord);//writing data into file
  9556. }
  9557. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9558. }
  9559. if(clearflag == TRUE)
  9560. {
  9561. fclose(fptr1);
  9562. fclose(fptr2);
  9563. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9564. system(str);
  9565. // clear temp file
  9566. sprintf(str,"rm -f %s",temp);
  9567. system(str);
  9568. }
  9569. else
  9570. {
  9571. fclose(fptr1);
  9572. fclose(fptr2);
  9573. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9574. system(str);
  9575. resultRename = rename(temp, chargingProfiles[k]);
  9576. if(resultRename == 0)
  9577. {
  9578. DEBUG_INFO("File ChargingProfile renamed successfully");
  9579. }
  9580. else
  9581. {
  9582. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9583. }
  9584. if(comfirmstr[0]== 0)
  9585. {
  9586. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9587. }
  9588. //Check chargingProfile is empty file
  9589. /*------ Read the file ----------------*/
  9590. fptr1=fopen(chargingProfiles[k],"r");
  9591. ch=fgetc(fptr1);
  9592. rewind(fptr1);
  9593. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9594. if(ch!=EOF)
  9595. {
  9596. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9597. {
  9598. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9599. if(sLineWord[0]=='\0')
  9600. {
  9601. isEmptyFile = TRUE;
  9602. break;
  9603. }
  9604. else
  9605. {
  9606. isEmptyFile = FALSE;
  9607. break;
  9608. }
  9609. }
  9610. }
  9611. else
  9612. isEmptyFile = TRUE;
  9613. fclose(fptr1);
  9614. if(isEmptyFile == TRUE)
  9615. {
  9616. memset(str, 0, ARRAY_SIZE(str));
  9617. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9618. system(str);
  9619. }
  9620. /*------- End of reading ---------------*/
  9621. }
  9622. } // while(int k=0; k < ChargeProfileCount; k++)
  9623. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9624. end:
  9625. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9626. {
  9627. if(connectorIdInt == 0)
  9628. {
  9629. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9630. {
  9631. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9632. }
  9633. }
  9634. else
  9635. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9636. }
  9637. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9638. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9639. return result;
  9640. }
  9641. void createFirmwareVersionByDataTransfer(void)
  9642. {
  9643. json_object *FirmwareDataTransfer = json_object_new_object();
  9644. // AC & DC model
  9645. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9646. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9647. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9648. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9649. // DC model
  9650. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9651. {
  9652. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9653. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9654. (gunType[3] != GUN_TYPE_UNKNOWN))
  9655. {
  9656. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9657. }
  9658. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9659. {
  9660. // DS DM DW
  9661. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9662. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9663. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9664. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9665. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9666. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9667. }
  9668. else
  9669. {
  9670. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9671. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9672. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9673. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9674. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9675. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9676. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9677. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9678. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9679. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9680. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9681. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9682. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9683. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9684. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9685. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9686. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9687. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9688. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9689. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9690. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9691. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9692. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9693. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9694. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9695. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9696. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9697. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9698. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9699. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9700. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9701. }
  9702. }
  9703. // 4G model
  9704. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9705. {
  9706. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9707. }
  9708. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9709. json_object_put(FirmwareDataTransfer);
  9710. }
  9711. int handleDataTransferRequest(char *uuid, char *payload)
  9712. {
  9713. mtrace();
  9714. json_object *response = json_object_new_object();
  9715. int result = FAIL;
  9716. char tempvendorId[255]={0};
  9717. char tempmessageId[50]={0};
  9718. char tempdata[10240]={0};
  9719. char message[20480]={0};
  9720. DEBUG_INFO("handleDataTransferRequest...\n");
  9721. if((uuid != NULL) && (payload != NULL))
  9722. {
  9723. json_object *DataTransfer;
  9724. DataTransfer = json_tokener_parse(payload);
  9725. if(!is_error(DataTransfer))
  9726. {
  9727. // Required data
  9728. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9729. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9730. // Optional data
  9731. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9732. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9733. if(json_object_object_get(DataTransfer, "data") != NULL)
  9734. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9735. result = PASS;
  9736. }
  9737. json_object_put(DataTransfer);
  9738. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9739. {
  9740. // Send all moudle firmware version on EVSE
  9741. createFirmwareVersionByDataTransfer();
  9742. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9743. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9744. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9745. json_object_put(response);
  9746. }
  9747. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9748. {
  9749. system("/usr/bin/run_tmate_restart.sh &");
  9750. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9751. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9752. json_object_put(response);
  9753. }
  9754. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9755. {
  9756. json_object *data;
  9757. data = json_tokener_parse(tempdata);
  9758. if(!is_error(data))
  9759. {
  9760. 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))
  9761. {
  9762. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9763. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9764. if(json_object_object_get(data, "SOC") != NULL)
  9765. {
  9766. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9767. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9768. }
  9769. if(json_object_object_get(data, "Energy") != NULL)
  9770. {
  9771. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9772. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9773. }
  9774. if(json_object_object_get(data, "Duration") != NULL)
  9775. {
  9776. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9777. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9778. }
  9779. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9780. }
  9781. else
  9782. {
  9783. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9784. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9785. }
  9786. }
  9787. else
  9788. {
  9789. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9790. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9791. }
  9792. json_object_put(data);
  9793. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9794. json_object_put(response);
  9795. }
  9796. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9797. {
  9798. json_object *data;
  9799. data = json_tokener_parse(tempdata);
  9800. if(!is_error(data))
  9801. {
  9802. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9803. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9804. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9805. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9806. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9807. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9808. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9809. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9810. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9811. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9812. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9813. }
  9814. else
  9815. {
  9816. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9817. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9818. }
  9819. json_object_put(data);
  9820. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9821. json_object_put(response);
  9822. }
  9823. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9824. {
  9825. json_object *data;
  9826. data = json_tokener_parse(tempdata);
  9827. if(!is_error(data))
  9828. {
  9829. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9830. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9831. if(json_object_object_get(data, "idToken") != NULL)
  9832. {
  9833. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9834. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9835. }
  9836. else
  9837. {
  9838. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9839. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9840. }
  9841. if(json_object_object_get(data, "price") != NULL) //v1.0
  9842. {
  9843. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9844. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9845. }
  9846. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9847. {
  9848. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9849. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9850. }
  9851. else
  9852. {
  9853. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9854. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9855. }
  9856. }
  9857. else
  9858. {
  9859. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9860. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9861. }
  9862. json_object_put(data);
  9863. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9864. json_object_put(response);
  9865. }
  9866. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9867. {
  9868. json_object *data;
  9869. data = json_tokener_parse(tempdata);
  9870. if(!is_error(data))
  9871. {
  9872. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9873. if(json_object_object_get(data, "txId") != NULL)
  9874. {
  9875. // California pricing V1.0
  9876. DEBUG_INFO("California pricing V1.0\n");
  9877. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9878. sprintf((char*)dmsVersion, "1.0");
  9879. for(int idx = 0;idx<gunTotalNumber;idx++)
  9880. {
  9881. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9882. {
  9883. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9884. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9885. if(json_object_object_get(data, "description") != NULL)
  9886. {
  9887. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9888. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9889. }
  9890. else
  9891. {
  9892. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9893. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9894. }
  9895. }
  9896. }
  9897. }
  9898. else if(json_object_object_get(data, "transactionId") != NULL)
  9899. {
  9900. // California pricing V2.0
  9901. DEBUG_INFO("California pricing V2.0\n");
  9902. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9903. sprintf((char*)dmsVersion, "2.0");
  9904. for(int idx=0;idx<gunTotalNumber;idx++)
  9905. {
  9906. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9907. {
  9908. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9909. if(json_object_object_get(data, "timestamp") != NULL)
  9910. {
  9911. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9912. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9913. }
  9914. else
  9915. {
  9916. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9917. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9918. }
  9919. if(json_object_object_get(data, "meterValue") != NULL)
  9920. {
  9921. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9922. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9923. }
  9924. else
  9925. {
  9926. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9927. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9928. }
  9929. if(json_object_object_get(data, "cost") != NULL)
  9930. {
  9931. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9932. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9933. }
  9934. else
  9935. {
  9936. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9937. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9938. }
  9939. if(json_object_object_get(data, "state") != NULL)
  9940. {
  9941. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9942. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9943. }
  9944. else
  9945. {
  9946. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9947. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9948. }
  9949. if(json_object_object_get(data, "chargingPrice") != NULL)
  9950. {
  9951. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9952. {
  9953. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9954. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9955. }
  9956. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9957. {
  9958. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9959. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9960. }
  9961. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9962. {
  9963. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9964. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9965. }
  9966. }
  9967. else
  9968. {
  9969. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9970. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9971. }
  9972. if(json_object_object_get(data, "idlePrice") != NULL)
  9973. {
  9974. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9975. {
  9976. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9977. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9978. }
  9979. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9980. {
  9981. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9982. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9983. }
  9984. }
  9985. if(json_object_object_get(data, "nextPeriod") != NULL)
  9986. {
  9987. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9988. {
  9989. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9990. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9991. }
  9992. else
  9993. {
  9994. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9995. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9996. }
  9997. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9998. {
  9999. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  10000. {
  10001. 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")));
  10002. 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"));
  10003. }
  10004. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  10005. {
  10006. 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")));
  10007. 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"));
  10008. }
  10009. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  10010. {
  10011. 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")));
  10012. 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"));
  10013. }
  10014. }
  10015. else
  10016. {
  10017. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10018. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10019. }
  10020. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10021. {
  10022. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10023. {
  10024. 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")));
  10025. 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"));
  10026. }
  10027. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10028. {
  10029. 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")));
  10030. 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"));
  10031. }
  10032. }
  10033. }
  10034. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10035. {
  10036. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10037. {
  10038. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10039. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10040. }
  10041. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10042. {
  10043. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10044. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10045. }
  10046. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10047. {
  10048. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10049. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10050. }
  10051. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10052. {
  10053. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10054. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10055. }
  10056. }
  10057. }
  10058. }
  10059. }
  10060. else
  10061. {
  10062. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10063. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10064. }
  10065. }
  10066. else
  10067. {
  10068. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10069. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10070. }
  10071. json_object_put(data);
  10072. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10073. json_object_put(response);
  10074. }
  10075. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10076. {
  10077. json_object *data;
  10078. data = json_tokener_parse(tempdata);
  10079. if(!is_error(data))
  10080. {
  10081. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10082. if(json_object_object_get(data, "txId") != NULL)
  10083. {
  10084. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10085. for(int idx = 0;idx<gunTotalNumber;idx++)
  10086. {
  10087. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10088. {
  10089. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10090. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10091. if(json_object_object_get(data, "description") != NULL)
  10092. {
  10093. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10094. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10095. }
  10096. else
  10097. {
  10098. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10099. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10100. }
  10101. }
  10102. }
  10103. }
  10104. else if(json_object_object_get(data, "transactionId") != NULL)
  10105. {
  10106. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10107. for(int idx = 0;idx<gunTotalNumber;idx++)
  10108. {
  10109. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10110. {
  10111. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10112. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10113. if(json_object_object_get(data, "cost") != NULL)
  10114. {
  10115. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10116. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  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("cost not found."));
  10122. }
  10123. if(json_object_object_get(data, "priceText") != NULL)
  10124. {
  10125. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10126. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10127. }
  10128. else
  10129. {
  10130. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10131. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10132. }
  10133. if(json_object_object_get(data, "qrCodeText") != NULL)
  10134. {
  10135. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10136. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10137. }
  10138. }
  10139. }
  10140. }
  10141. else
  10142. {
  10143. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10144. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10145. }
  10146. }
  10147. else
  10148. {
  10149. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10150. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10151. }
  10152. json_object_put(data);
  10153. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10154. json_object_put(response);
  10155. }
  10156. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10157. {
  10158. json_object *data;
  10159. data = json_tokener_parse(tempdata);
  10160. if(!is_error(data))
  10161. {
  10162. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10163. if(json_object_object_get(data, "Content_Type") != NULL)
  10164. {
  10165. 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))
  10166. {
  10167. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10168. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10169. {
  10170. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10171. }
  10172. }
  10173. else
  10174. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10175. }
  10176. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10177. }
  10178. else
  10179. {
  10180. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10181. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10182. }
  10183. json_object_put(data);
  10184. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10185. json_object_put(response);
  10186. }
  10187. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10188. {
  10189. json_object *data;
  10190. data = json_tokener_parse(tempdata);
  10191. if(!is_error(data))
  10192. {
  10193. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10194. if(json_object_object_get(data, "ConnectorId") != NULL)
  10195. {
  10196. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10197. }
  10198. if(json_object_object_get(data, "SerialNo") != NULL)
  10199. {
  10200. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10201. }
  10202. if(json_object_object_get(data, "Page_Index") != NULL)
  10203. {
  10204. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10205. }
  10206. if(json_object_object_get(data, "Duration") != NULL)
  10207. {
  10208. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10209. }
  10210. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10211. }
  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. json_object_put(data);
  10218. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10219. json_object_put(response);
  10220. }
  10221. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10222. {
  10223. json_object *data;
  10224. data = json_tokener_parse(tempdata);
  10225. if(!is_error(data))
  10226. {
  10227. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10228. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10229. {
  10230. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10231. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10232. else
  10233. {
  10234. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10235. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10236. }
  10237. }
  10238. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10239. {
  10240. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10241. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10242. else
  10243. {
  10244. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10245. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10246. }
  10247. }
  10248. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10249. {
  10250. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10251. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10252. else
  10253. {
  10254. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10255. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10256. }
  10257. }
  10258. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10259. {
  10260. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10261. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10262. else
  10263. {
  10264. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10265. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10266. }
  10267. }
  10268. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10269. {
  10270. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10271. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10272. else
  10273. {
  10274. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10275. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10276. }
  10277. }
  10278. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10279. {
  10280. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10281. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10282. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10283. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10284. else
  10285. {
  10286. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10287. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10288. }
  10289. }
  10290. if(json_object_object_get(data, "isAuthentication") != NULL)
  10291. {
  10292. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10293. {
  10294. case 0:
  10295. case 1:
  10296. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10297. break;
  10298. default:
  10299. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10300. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10301. break;
  10302. }
  10303. }
  10304. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10305. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10306. }
  10307. else
  10308. {
  10309. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10310. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10311. }
  10312. json_object_put(data);
  10313. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10314. json_object_put(response);
  10315. }
  10316. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10317. {
  10318. json_object *data;
  10319. data = json_tokener_parse(tempdata);
  10320. if(!is_error(data))
  10321. {
  10322. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10323. {
  10324. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10325. {
  10326. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10327. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10328. }
  10329. else
  10330. {
  10331. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10332. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10333. }
  10334. }
  10335. else
  10336. {
  10337. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10338. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10339. }
  10340. }
  10341. else
  10342. {
  10343. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10344. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10345. }
  10346. json_object_put(data);
  10347. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10348. json_object_put(response);
  10349. }
  10350. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10351. {
  10352. json_object *data;
  10353. data = json_tokener_parse(tempdata);
  10354. if(!is_error(data))
  10355. {
  10356. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10357. if(json_object_object_get(data, "stationName") != NULL)
  10358. {
  10359. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10360. }
  10361. else
  10362. {
  10363. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10364. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10365. }
  10366. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10367. {
  10368. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10369. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10370. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10371. }
  10372. }
  10373. else
  10374. {
  10375. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10376. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10377. }
  10378. json_object_put(data);
  10379. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10380. json_object_put(response);
  10381. }
  10382. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10383. {
  10384. json_object *data;
  10385. data = json_tokener_parse(tempdata);
  10386. if(!is_error(data))
  10387. {
  10388. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10389. if(json_object_object_get(data, "weatherId") != NULL)
  10390. {
  10391. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10392. }
  10393. else
  10394. {
  10395. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10396. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10397. }
  10398. if(json_object_object_get(data, "Temperature") != NULL)
  10399. {
  10400. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10401. }
  10402. else
  10403. {
  10404. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10405. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10406. }
  10407. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10408. {
  10409. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10410. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10411. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10412. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10413. );
  10414. }
  10415. }
  10416. else
  10417. {
  10418. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10419. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10420. }
  10421. json_object_put(data);
  10422. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10423. json_object_put(response);
  10424. }
  10425. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10426. {
  10427. json_object *data;
  10428. data = json_tokener_parse(tempdata);
  10429. if(!is_error(data))
  10430. {
  10431. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10432. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10433. {
  10434. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10435. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10436. }
  10437. else
  10438. {
  10439. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10440. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10441. }
  10442. }
  10443. else
  10444. {
  10445. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10446. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10447. }
  10448. json_object_put(data);
  10449. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10450. json_object_put(response);
  10451. }
  10452. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10453. {
  10454. json_object *data;
  10455. data = json_tokener_parse(tempdata);
  10456. if(!is_error(data))
  10457. {
  10458. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10459. {
  10460. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10461. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10462. if(gun_index < gunTotalNumber)
  10463. {
  10464. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10465. {
  10466. json_object *responsedata = json_object_new_object();
  10467. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10468. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10469. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10470. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10471. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10472. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10473. }
  10474. else
  10475. {
  10476. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10477. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10478. }
  10479. }
  10480. else
  10481. {
  10482. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10483. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10484. }
  10485. }
  10486. else
  10487. {
  10488. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10489. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10490. }
  10491. }
  10492. else
  10493. {
  10494. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10495. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10496. }
  10497. json_object_put(data);
  10498. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10499. json_object_put(response);
  10500. }
  10501. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10502. {
  10503. json_object *data;
  10504. data = json_tokener_parse(tempdata);
  10505. if(!is_error(data))
  10506. {
  10507. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10508. int gun_index = 0;
  10509. if(json_object_object_get(data, "ConnectorId") != NULL)
  10510. {
  10511. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10512. if(json_object_object_get(data, "occupancySN") != NULL)
  10513. {
  10514. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10515. }
  10516. else
  10517. {
  10518. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10519. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10520. }
  10521. if(json_object_object_get(data, "actionId") != NULL)
  10522. {
  10523. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10524. }
  10525. else
  10526. {
  10527. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10528. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10529. }
  10530. }
  10531. else
  10532. {
  10533. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10534. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  10535. }
  10536. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10537. {
  10538. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10539. }
  10540. }
  10541. else
  10542. {
  10543. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10544. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  10545. }
  10546. json_object_put(data);
  10547. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10548. json_object_put(response);
  10549. }
  10550. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10551. {
  10552. json_object *data;
  10553. data = json_tokener_parse(tempdata);
  10554. if(!is_error(data))
  10555. {
  10556. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10557. if(json_object_object_get(data, "price") != NULL)
  10558. {
  10559. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10560. }
  10561. else
  10562. {
  10563. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10564. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  10565. }
  10566. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10567. {
  10568. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10569. }
  10570. }
  10571. else
  10572. {
  10573. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10574. json_object_object_add(response, "data", json_object_new_string("SetOccupancyPrice content got something wrong."));
  10575. }
  10576. json_object_put(data);
  10577. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10578. json_object_put(response);
  10579. }
  10580. // Support ISO-15118 related message
  10581. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10582. {
  10583. char cmdBuf[1024]={0};
  10584. 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);
  10585. system(cmdBuf);
  10586. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10587. json_object *responsedata = json_object_new_object();
  10588. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10589. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10590. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10591. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10592. json_object_put(response);
  10593. }
  10594. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10595. {
  10596. json_object *data;
  10597. data = json_tokener_parse(tempdata);
  10598. if(!is_error(data))
  10599. {
  10600. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10601. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10602. fclose(fp);
  10603. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10604. json_object *responsedata = json_object_new_object();
  10605. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10606. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10607. else
  10608. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  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("Rejected"));
  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("Rejected"));
  10618. }
  10619. json_object_put(data);
  10620. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10621. json_object_put(response);
  10622. }
  10623. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10624. {
  10625. json_object *data;
  10626. data = json_tokener_parse(tempdata);
  10627. DEBUG_INFO("DeleteCertificate processing...\n");
  10628. if(!is_error(data))
  10629. {
  10630. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10631. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10632. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10633. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10634. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10635. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10636. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10637. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10638. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10639. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10640. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10641. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10642. char temp[256] = {0};
  10643. char compareData[256] = {0};
  10644. int isMatch = TRUE;
  10645. // Check certV2G
  10646. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10647. {
  10648. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10649. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10650. isMatch = FALSE;
  10651. if(isMatch == TRUE)
  10652. {
  10653. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10654. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10655. isMatch = FALSE;
  10656. }
  10657. if(isMatch == TRUE)
  10658. {
  10659. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10660. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10661. isMatch = FALSE;
  10662. }
  10663. if(isMatch == TRUE)
  10664. {
  10665. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10666. system(temp);
  10667. json_object *responsedata = json_object_new_object();
  10668. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10669. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10670. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10671. }
  10672. else
  10673. {
  10674. json_object *responsedata = json_object_new_object();
  10675. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10676. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10677. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10678. }
  10679. }
  10680. else
  10681. {
  10682. json_object *responsedata = json_object_new_object();
  10683. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10684. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10685. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10686. }
  10687. }
  10688. else
  10689. {
  10690. json_object *responsedata = json_object_new_object();
  10691. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10692. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10693. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10694. }
  10695. json_object_put(data);
  10696. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10697. json_object_put(response);
  10698. }
  10699. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10700. {
  10701. json_object *data;
  10702. data = json_tokener_parse(tempdata);
  10703. if(!is_error(data))
  10704. {
  10705. /*
  10706. * TODO:
  10707. * 1. Query certificate to response
  10708. */
  10709. json_object *responsedata = json_object_new_object();
  10710. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10711. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10712. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10713. }
  10714. else
  10715. {
  10716. json_object *responsedata = json_object_new_object();
  10717. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10718. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10719. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10720. }
  10721. json_object_put(data);
  10722. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10723. json_object_put(response);
  10724. }
  10725. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10726. {
  10727. json_object *data;
  10728. data = json_tokener_parse(tempdata);
  10729. if(!is_error(data))
  10730. {
  10731. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10732. if(json_object_object_get(data, "certificateType") != NULL)
  10733. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10734. if(json_object_object_get(data, "certificate") != NULL)
  10735. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10736. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10737. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10738. char temp[1024];
  10739. FILE *fp = fopen(tempCert, "w");
  10740. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10741. fclose(fp);
  10742. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10743. char strExpDate[30];
  10744. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10745. fp = popen(temp, "r");
  10746. if(fp)
  10747. {
  10748. while(fgets(temp, sizeof(temp), fp) != NULL)
  10749. {
  10750. if(strstr(temp, "notAfter=") != NULL)
  10751. {
  10752. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10753. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10754. break;
  10755. }
  10756. }
  10757. }
  10758. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10759. struct tm tmExpDate;
  10760. struct timeb tbExpDate;
  10761. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10762. tbExpDate.time = mktime(&tmExpDate);
  10763. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10764. {
  10765. DEBUG_INFO("The enddate is already expired...\n");
  10766. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10767. }
  10768. else
  10769. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10770. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10771. {
  10772. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10773. {
  10774. if(access(ROOTCA_V2G,F_OK) != -1)
  10775. {
  10776. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10777. rename(ROOTCA_V2G, "/Storage/rootCaV2g_fallback.pem");
  10778. rename(tempCert, ROOTCA_V2G);
  10779. }
  10780. else
  10781. {
  10782. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10783. rename(tempCert, ROOTCA_V2G);
  10784. }
  10785. json_object *responsedata = json_object_new_object();
  10786. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10787. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10788. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10789. }
  10790. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10791. {
  10792. if(access(ROOTCA_MO,F_OK) != -1)
  10793. {
  10794. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10795. rename(ROOTCA_MO, "/Storage/rootCaMo_fallback.pem");
  10796. rename(tempCert, ROOTCA_MO);
  10797. }
  10798. else
  10799. {
  10800. DEBUG_INFO("No existed MORootCertificate. Creating...\n");
  10801. rename(tempCert, ROOTCA_MO);
  10802. }
  10803. json_object *responsedata = json_object_new_object();
  10804. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10805. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10806. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10807. }
  10808. else
  10809. {
  10810. json_object *responsedata = json_object_new_object();
  10811. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10812. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10813. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10814. }
  10815. }
  10816. else
  10817. {
  10818. json_object *responsedata = json_object_new_object();
  10819. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10820. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10821. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10822. }
  10823. }
  10824. else
  10825. {
  10826. json_object *responsedata = json_object_new_object();
  10827. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10828. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10829. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10830. }
  10831. json_object_put(data);
  10832. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10833. json_object_put(response);
  10834. }
  10835. else
  10836. {
  10837. // Can not find valid message id
  10838. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10839. }
  10840. }
  10841. else
  10842. {
  10843. // Payload is null
  10844. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10845. }
  10846. LWS_Send(message);
  10847. return result;
  10848. }
  10849. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10850. {
  10851. mtrace();
  10852. int result = FAIL;
  10853. int connectorIdInt, durationInt;
  10854. char chargingRateUnitStr[4]={0};
  10855. char comfirmstr[20];
  10856. int confirmPeriods = 0;
  10857. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10858. json_object *GetCompositeSchedule;
  10859. GetCompositeSchedule = json_tokener_parse(payload);
  10860. if(!is_error(GetCompositeSchedule))
  10861. {
  10862. // Required data
  10863. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10864. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10865. else
  10866. connectorIdInt = -1;
  10867. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10868. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10869. else
  10870. durationInt = 86400;
  10871. // Optional data
  10872. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10873. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10874. }
  10875. json_object_put(GetCompositeSchedule);
  10876. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10877. if((connectorIdInt == 0) ||
  10878. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10879. {
  10880. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10881. struct StructChargingProfile tmpProfile[1];
  10882. if(strstr(chargingRateUnitStr, "W") != NULL)
  10883. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10884. else
  10885. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10886. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10887. {
  10888. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10889. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10890. }
  10891. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10892. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10893. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10894. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10895. {
  10896. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10897. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10898. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10899. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10900. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10901. {
  10902. confirmPeriods = idx;
  10903. break;
  10904. }
  10905. }
  10906. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10907. {
  10908. confirmPeriods += 1;
  10909. }
  10910. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10911. }
  10912. else
  10913. {
  10914. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10915. }
  10916. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10917. return result;
  10918. }
  10919. int handleGetConfigurationRequest(char *uuid, char *payload)
  10920. {
  10921. mtrace();
  10922. int result = FAIL;
  10923. int MaxKeySupported = 0;
  10924. int n_keys = 0;
  10925. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10926. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10927. json_object *GetConfiguration;
  10928. GetConfiguration = json_tokener_parse(payload);
  10929. if(!is_error(GetConfiguration))
  10930. {
  10931. // Optional data
  10932. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10933. {
  10934. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10935. {
  10936. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10937. n_keys = idx + 1;
  10938. }
  10939. }
  10940. }
  10941. json_object_put(GetConfiguration);
  10942. UnknownKeynum = 0;
  10943. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10944. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10945. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10946. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10947. if(n_keys != 0)
  10948. {
  10949. for(int i=0;i<n_keys;i++)
  10950. {
  10951. getKeyValue(requestKey[i]);
  10952. }
  10953. }
  10954. else
  10955. {
  10956. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10957. getKeyValue("");
  10958. }
  10959. processUnkownKey();
  10960. sendGetConfigurationConfirmation(uuid);
  10961. return result;
  10962. }
  10963. static char fnamePlusPath[100]={0};
  10964. static char fnamePWithNoPath[60]={0};
  10965. void checkUploadLog(void)
  10966. {
  10967. FILE *fp;
  10968. /* Open the command for reading. */
  10969. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10970. if (fp == NULL) {
  10971. DEBUG_WARN("Failed to run command\n" );
  10972. exit(1);
  10973. }
  10974. int ftppathlen = 0;
  10975. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10976. int i = 0;
  10977. /* Read the output a line at a time - output it. */
  10978. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10979. if(i==0)
  10980. {
  10981. ftppathlen = strlen(fnamePlusPath);
  10982. DEBUG_INFO("%s\n", fnamePlusPath);
  10983. fnamePlusPath[ftppathlen]='\0';
  10984. break;
  10985. }
  10986. i= i+1;
  10987. }
  10988. /* close */
  10989. pclose(fp);
  10990. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10991. {
  10992. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10993. {
  10994. fnamePlusPath[k]='\0';
  10995. }
  10996. }
  10997. i=1;
  10998. //char fname[60]={0};
  10999. while(i < ftppathlen)
  11000. {
  11001. int len=ftppathlen-i;
  11002. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  11003. {
  11004. DEBUG_INFO("compare '/' all right\n");
  11005. break;
  11006. }
  11007. i=i+1;
  11008. }
  11009. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11010. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11011. fnamePWithNoPath[i+1] = '\0';
  11012. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11013. {
  11014. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11015. {
  11016. fnamePWithNoPath[j]='\0';
  11017. }
  11018. }
  11019. FILE* fp1 = fopen(fnamePlusPath, "r");
  11020. if (fp1)
  11021. {
  11022. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11023. // file exists
  11024. fclose(fp1);
  11025. }
  11026. else
  11027. {
  11028. // file doesn't exist
  11029. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11030. }
  11031. }
  11032. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11033. {
  11034. mtrace();
  11035. int result = FAIL;
  11036. time_t CurrentTime;
  11037. struct tm *tm;
  11038. pthread_t th_Status;
  11039. CurrentTime = time(NULL);
  11040. tm = localtime(&CurrentTime);
  11041. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11042. 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);
  11043. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11044. if(!interLock.isGetDiagnosticGoing)
  11045. {
  11046. interLock.isGetDiagnosticGoing = 1;
  11047. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11048. sleep(1);
  11049. }
  11050. else
  11051. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11052. return result;
  11053. }
  11054. void* GetDiagnosticsProcess(void* data)
  11055. {
  11056. pthread_detach(pthread_self());
  11057. mtrace();
  11058. int retriesInt=0, retryIntervalInt=0;
  11059. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11060. 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};
  11061. int port=0;
  11062. int isSuccess = FALSE;
  11063. char cmdBuf[2048];
  11064. struct tm *tmNow;
  11065. time_t CurrentTime;
  11066. struct tm tmStart;
  11067. struct tm tmStop;
  11068. CurrentTime = time(NULL);
  11069. tmNow=localtime(&CurrentTime);
  11070. uint16_t targetYear, targetMonth;
  11071. json_object *GetDiagnostics;
  11072. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11073. GetDiagnostics = json_tokener_parse(data);
  11074. if(!is_error(GetDiagnostics))
  11075. {
  11076. // Required data
  11077. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11078. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11079. // Optional data
  11080. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11081. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11082. else
  11083. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11084. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11085. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11086. else
  11087. retryIntervalInt = 30;
  11088. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11089. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11090. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11091. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11092. }
  11093. json_object_put(GetDiagnostics);
  11094. // Notify CSU to get log of dispensers.
  11095. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  11096. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  11097. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  11098. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  11099. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  11100. )
  11101. {
  11102. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StartTime,"%s",startTimestr);
  11103. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StopTime,"%s",stopTimestr);
  11104. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = TRUE;
  11105. struct timespec timerGetDiagnostics;
  11106. refreshStartTimer(&timerGetDiagnostics);
  11107. while(ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq != FALSE)
  11108. {
  11109. if(getDiffSecNow(timerGetDiagnostics)>=180)
  11110. {
  11111. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = FALSE;
  11112. DEBUG_INFO("Waiting log of dispenser timeout.");
  11113. }
  11114. }
  11115. }
  11116. // Pack log to compress file
  11117. if((sscanf((char*)startTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  11118. (sscanf((char*)stopTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  11119. {
  11120. // Pack system log
  11121. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11122. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11123. targetYear = tmStart.tm_year;
  11124. targetMonth = tmStart.tm_mon;
  11125. do
  11126. {
  11127. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11128. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11129. if(targetMonth+1>=13)
  11130. {
  11131. targetYear += 1;
  11132. targetMonth = 1;
  11133. }
  11134. else
  11135. {
  11136. targetMonth += 1;
  11137. }
  11138. }while((targetYear < (tmNow->tm_year+1900)) ||
  11139. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11140. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11141. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11142. sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
  11143. sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
  11144. sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
  11145. system(cmdBuf);
  11146. // Pack charging & event log
  11147. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11148. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11149. targetYear = tmStart.tm_year;
  11150. targetMonth = tmStart.tm_mon;
  11151. do
  11152. {
  11153. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11154. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  11155. if(targetMonth+1>=13)
  11156. {
  11157. targetYear += 1;
  11158. targetMonth = 1;
  11159. }
  11160. else
  11161. {
  11162. targetMonth += 1;
  11163. }
  11164. }while((targetYear < (tmNow->tm_year+1900)) ||
  11165. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11166. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11167. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11168. system(cmdBuf);
  11169. // Combine log file
  11170. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11171. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11172. }
  11173. else
  11174. {
  11175. system("exec /root/logPackTools 'log' 6");
  11176. }
  11177. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11178. system(cmdBuf);
  11179. checkUploadLog();
  11180. //****************location*******************/
  11181. if(strcmp(locationstr,"")==0)
  11182. {
  11183. DEBUG_INFO("location is <Empty>!\n");
  11184. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11185. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11186. goto end;
  11187. }
  11188. memset(protocol, 0, ARRAY_SIZE(protocol));
  11189. memset(user, 0, ARRAY_SIZE(user) );
  11190. memset(password, 0, ARRAY_SIZE(password));
  11191. memset(host, 0, ARRAY_SIZE(host));
  11192. memset(path, 0, ARRAY_SIZE(path));
  11193. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11194. memset(host1, 0, ARRAY_SIZE(host1));
  11195. memset(path1, 0, ARRAY_SIZE(path1));
  11196. /*location: ftp://user:password@host:port/path*/
  11197. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11198. if((access(fnamePlusPath,F_OK))!=-1)
  11199. {
  11200. DEBUG_INFO("fnamePlusPath exist.\n");
  11201. }
  11202. else
  11203. {
  11204. DEBUG_INFO("fnamePlusPath not exist!\n");
  11205. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11206. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11207. goto end;
  11208. }
  11209. if(strchr(locationstr,'@')==NULL)
  11210. {
  11211. sscanf(locationstr,
  11212. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11213. protocol, host, &port, path);
  11214. strcpy(user,"anonymous");
  11215. strcpy(password,"");
  11216. }
  11217. else
  11218. {
  11219. //DEBUG_INFO("pch=%s\n", pch);
  11220. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11221. protocol, user, password, host, &port, path);
  11222. }
  11223. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11224. {
  11225. DEBUG_INFO("protocol is not ftp/http ! \n");
  11226. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11227. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11228. goto end;
  11229. }
  11230. if(strncmp(locationstr,"http", 4) == 0)
  11231. {
  11232. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11233. sprintf(ftppath,"/%s", path);
  11234. do
  11235. {
  11236. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11237. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11238. sleep(3);
  11239. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11240. if(!isSuccess)
  11241. {
  11242. DEBUG_INFO("Diagnostics fail.\n");
  11243. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11244. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11245. sleep(retryIntervalInt);
  11246. }
  11247. else
  11248. {
  11249. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11250. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11251. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11252. }
  11253. retriesInt--;
  11254. }while((isSuccess == 0)&&(retriesInt >= 0));
  11255. }
  11256. else
  11257. {
  11258. sscanf(host,"%[^/]%s",host1, path1);
  11259. if(strlen(path) > 0)
  11260. sprintf(ftppath,"/%s", path);
  11261. else
  11262. sprintf(ftppath,"/%s", path1);
  11263. int ftppathlen=strlen(ftppath);
  11264. int i=1;
  11265. char filenametemp[50];
  11266. while(i < ftppathlen)
  11267. {
  11268. int len=ftppathlen-i;
  11269. if(ftppath[len]== 47) // '/' ascll code: 47
  11270. {
  11271. DEBUG_INFO("find '/' all right\n");
  11272. break;
  11273. }
  11274. i=i+1;
  11275. }
  11276. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11277. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11278. filenametemp[i+1] = 0;
  11279. if(port == 0)
  11280. port = 21;
  11281. do
  11282. {
  11283. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11284. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11285. sleep(3);
  11286. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11287. if(!isSuccess)
  11288. {
  11289. DEBUG_INFO("Diagnostics fail.\n");
  11290. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11291. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11292. sleep(retryIntervalInt);
  11293. }
  11294. else
  11295. {
  11296. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11297. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11298. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11299. }
  11300. retriesInt--;
  11301. }while((!isSuccess)&&(retriesInt >= 0));
  11302. }
  11303. end:
  11304. system("rm -f /mnt/*");
  11305. sleep(5);
  11306. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11307. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11308. interLock.isGetDiagnosticGoing = 0;
  11309. pthread_exit(NULL);
  11310. }
  11311. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11312. {
  11313. mtrace();
  11314. int result = FAIL;
  11315. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11316. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11317. {
  11318. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11319. locallistVersion = -1;
  11320. }
  11321. else
  11322. {
  11323. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11324. locallistVersion = 0;
  11325. OCPP_getListVerion();
  11326. }
  11327. //from db.OCPP_getListVerion
  11328. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11329. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11330. sendGetLocalListVersionConfirmation(uuid,"");
  11331. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11332. return result;
  11333. }
  11334. int handleRemoteStartRequest(char *uuid, char *payload)
  11335. {
  11336. mtrace();
  11337. int result = PASS;
  11338. int connectorIdInt=-1;
  11339. int tempIndex = 0;
  11340. char comfirmstr[20]={0};
  11341. char cmdBuf[512];
  11342. json_object *RemoteStartTransaction;
  11343. FILE *fp;
  11344. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11345. if(server_pending == TRUE)
  11346. {
  11347. result = FAIL;
  11348. }
  11349. RemoteStartTransaction = json_tokener_parse(payload);
  11350. if(!is_error(RemoteStartTransaction))
  11351. {
  11352. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11353. {
  11354. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11355. }
  11356. else
  11357. {
  11358. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11359. {
  11360. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11361. {
  11362. connectorIdInt = (gun_index+1);
  11363. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11364. break;
  11365. }
  11366. }
  11367. }
  11368. if(connectorIdInt == 0)
  11369. {
  11370. DEBUG_WARN("Connector id shall not equal 0.\n");
  11371. result = FAIL;
  11372. }
  11373. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11374. {
  11375. DEBUG_WARN("idTag should not be NULL.\n");
  11376. result = FAIL;
  11377. }
  11378. else if(connectorIdInt == -1)
  11379. {
  11380. DEBUG_INFO("Connector id does not specific.\n");
  11381. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11382. {
  11383. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11384. // Required data
  11385. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11386. // Optional data
  11387. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11388. {
  11389. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11390. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11391. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11392. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11393. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11394. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11395. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11396. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11397. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11398. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11399. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11400. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11401. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11402. {
  11403. 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")));
  11404. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11405. 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"));
  11406. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11407. 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"));
  11408. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11409. 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")));
  11410. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11411. {
  11412. 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++)
  11413. {
  11414. 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"));
  11415. 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"));
  11416. 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)
  11417. 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"));
  11418. }
  11419. }
  11420. }
  11421. }
  11422. else
  11423. {
  11424. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11425. }
  11426. }
  11427. }
  11428. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11429. {
  11430. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11431. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11432. // Required data
  11433. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11434. // Optional data
  11435. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11436. {
  11437. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11438. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11439. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11440. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11441. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11442. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11443. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11444. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11445. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11446. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11447. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11448. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11449. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11450. {
  11451. 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")));
  11452. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11453. 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"));
  11454. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11455. 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"));
  11456. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11457. 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")));
  11458. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11459. {
  11460. 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++)
  11461. {
  11462. 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"));
  11463. 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"));
  11464. 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)
  11465. 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"));
  11466. }
  11467. }
  11468. }
  11469. }
  11470. else
  11471. {
  11472. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11473. }
  11474. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] != 'D') && (ShmSysConfigAndInfo->SysConfig.ModelName[1] != 'W'))
  11475. {
  11476. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11477. {
  11478. if(cpinitateMsg.bits[gun_index].isOnCharging ||
  11479. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL) ||
  11480. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing") != NULL))
  11481. {
  11482. if(connectorIdInt != (gun_index+1))
  11483. {
  11484. DEBUG_WARN("DWseries--> Other connector is in charging.\n");
  11485. result = FAIL;
  11486. }
  11487. break;
  11488. }
  11489. }
  11490. }
  11491. }
  11492. else
  11493. {
  11494. DEBUG_WARN("Connector id is over maximun value.\n");
  11495. result = FAIL;
  11496. }
  11497. }
  11498. if(result == PASS)
  11499. {
  11500. if(connectorIdInt > 0)
  11501. {
  11502. //check Transaction active
  11503. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11504. {
  11505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11506. {
  11507. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11508. }
  11509. else
  11510. {
  11511. tempIndex = connectorIdInt -1;
  11512. }
  11513. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11514. {
  11515. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11516. {
  11517. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11518. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11519. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11520. {
  11521. //Reserved
  11522. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11523. }
  11524. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11525. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11526. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11527. {
  11528. //Reserved
  11529. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11530. {
  11531. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11532. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11533. goto end;
  11534. }
  11535. }
  11536. else
  11537. {
  11538. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11539. {
  11540. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11542. goto end;
  11543. }
  11544. }//END FOR ELSE
  11545. }
  11546. }// END FOR CHAdeMO_QUANTITY
  11547. }
  11548. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11549. {
  11550. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11551. {
  11552. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11553. }
  11554. else
  11555. {
  11556. tempIndex = connectorIdInt -1;
  11557. }
  11558. for (int index = 0; index < CCS_QUANTITY; index++)
  11559. {
  11560. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11561. {
  11562. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11563. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11564. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11565. {
  11566. //Reserved
  11567. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11568. }
  11569. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11570. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11571. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11572. {
  11573. //Reserved
  11574. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11575. {
  11576. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11577. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11578. goto end;
  11579. }
  11580. }
  11581. else
  11582. {
  11583. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11584. {
  11585. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11586. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11587. goto end;
  11588. }
  11589. }// END FOR ELSE
  11590. }
  11591. }// END FOR CCS_QUANTITY
  11592. }
  11593. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11594. {
  11595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11596. {
  11597. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11598. }
  11599. else
  11600. {
  11601. tempIndex = connectorIdInt -1;
  11602. }
  11603. for (int index = 0; index < GB_QUANTITY; index++)
  11604. {
  11605. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11606. {
  11607. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11608. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11609. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11610. {
  11611. //Reserved
  11612. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11613. }
  11614. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11615. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11616. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11617. {
  11618. //Reserved
  11619. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11620. {
  11621. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11622. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11623. goto end;
  11624. }
  11625. }
  11626. else
  11627. {
  11628. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11629. {
  11630. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11631. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11632. goto end;
  11633. }
  11634. }// END FOR ELSE
  11635. }
  11636. } // END FOR GB_QUANTITY
  11637. }
  11638. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11639. {
  11640. tempIndex = connectorIdInt -1;
  11641. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11642. {
  11643. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11644. {
  11645. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11646. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11647. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11648. {
  11649. //Reserved
  11650. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11651. }
  11652. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11653. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11654. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11655. {
  11656. //Reserved
  11657. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11658. {
  11659. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11660. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11661. goto end;
  11662. }
  11663. }
  11664. else
  11665. {
  11666. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11667. {
  11668. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11669. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11670. goto end;
  11671. }
  11672. }// END FOR ELSE
  11673. }
  11674. } // END FOR GB_QUANTITY
  11675. }
  11676. else
  11677. {
  11678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11679. {
  11680. tempIndex = 2;
  11681. }
  11682. else
  11683. {
  11684. tempIndex = connectorIdInt -1;
  11685. }
  11686. for (int index = 0; index < AC_QUANTITY; index++)
  11687. {
  11688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11689. {
  11690. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11691. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11692. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11693. {
  11694. //Reserved
  11695. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11696. }
  11697. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11698. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11699. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11700. {
  11701. //Reserved
  11702. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11703. {
  11704. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11705. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11706. goto end;
  11707. }
  11708. }
  11709. else
  11710. {
  11711. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11712. {
  11713. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11714. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11715. goto end;
  11716. }
  11717. }//END FOR ELSE
  11718. }
  11719. }// END FOR AC_QUANTITY
  11720. }
  11721. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11722. {
  11723. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11724. {
  11725. // Save profile to file
  11726. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11727. system(cmdBuf);
  11728. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11729. fp = fopen(cmdBuf, "w");
  11730. 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));
  11731. fclose(fp);
  11732. }
  11733. else
  11734. {
  11735. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11736. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11737. goto end;
  11738. }
  11739. }
  11740. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11741. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11742. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11743. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11744. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11745. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11746. }
  11747. else
  11748. {
  11749. uint8_t isHasIdleConnector = FALSE;
  11750. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11751. {
  11752. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11753. {
  11754. isHasIdleConnector = TRUE;
  11755. break;
  11756. }
  11757. }
  11758. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11759. {
  11760. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11761. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11762. {
  11763. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11764. {
  11765. // Save profile to file
  11766. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11767. system(cmdBuf);
  11768. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11769. fp = fopen(cmdBuf, "w");
  11770. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11771. fclose(fp);
  11772. refreshStartTimer(&clientTime.RemoteStartWait);
  11773. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11774. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11775. }
  11776. else
  11777. {
  11778. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11779. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11780. }
  11781. }
  11782. else
  11783. {
  11784. refreshStartTimer(&clientTime.RemoteStartWait);
  11785. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11786. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11787. }
  11788. }
  11789. else
  11790. {
  11791. DEBUG_INFO("There is not any connector is idle.\n");
  11792. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11793. }
  11794. }
  11795. }
  11796. else
  11797. {
  11798. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11799. }
  11800. end:
  11801. json_object_put(RemoteStartTransaction);
  11802. sendRemoteStartConfirmation(uuid, comfirmstr);
  11803. return result;
  11804. }
  11805. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11806. {
  11807. mtrace();
  11808. int result = FAIL;
  11809. int match = FALSE;
  11810. int GunNO = 0;
  11811. int tempIndex = 0;
  11812. int transactionIdInt=0;
  11813. int transactionIdIsNULL= TRUE;
  11814. char comfirmstr[20];
  11815. json_object *RemoteStopTransaction;
  11816. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11817. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11818. if(server_pending == TRUE)
  11819. {
  11820. return 0;
  11821. }
  11822. RemoteStopTransaction = json_tokener_parse(payload);
  11823. if(!is_error(RemoteStopTransaction))
  11824. {
  11825. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11826. {
  11827. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11828. transactionIdIsNULL = FALSE;
  11829. }
  11830. }
  11831. json_object_put(RemoteStopTransaction);
  11832. if(transactionIdIsNULL == FALSE)
  11833. {
  11834. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11835. {
  11836. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11837. {
  11838. //check Transaction active
  11839. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11840. {
  11841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11842. {
  11843. tempIndex = ((gun_index==2) ? 1: 0);
  11844. }
  11845. else
  11846. {
  11847. tempIndex = gun_index;
  11848. }
  11849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11850. {
  11851. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11852. {
  11853. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11854. {
  11855. match = TRUE;
  11856. GunNO = gun_index;
  11857. }
  11858. }
  11859. }// END FOR CHAdeMO_QUANTITY
  11860. }
  11861. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11862. {
  11863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11864. {
  11865. tempIndex = ((gun_index==2) ? 1: 0);
  11866. }
  11867. else
  11868. {
  11869. tempIndex = gun_index;
  11870. }
  11871. for (int index = 0; index < CCS_QUANTITY; index++)
  11872. {
  11873. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11874. {
  11875. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11876. {
  11877. match = TRUE;
  11878. GunNO = gun_index;
  11879. }
  11880. }
  11881. }// END FOR CCS_QUANTITY
  11882. }
  11883. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11884. {
  11885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11886. {
  11887. tempIndex = ((gun_index==2) ? 1: 0);
  11888. }
  11889. else
  11890. {
  11891. tempIndex = gun_index;
  11892. }
  11893. for (int index = 0; index < GB_QUANTITY; index++)
  11894. {
  11895. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11896. {
  11897. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11898. {
  11899. match = TRUE;
  11900. GunNO = gun_index;
  11901. }
  11902. }
  11903. }// END FOR GB_QUANTITY
  11904. }
  11905. else if(gunType[gun_index] == GUN_TYPE_DO)
  11906. {
  11907. tempIndex = gun_index;
  11908. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11909. {
  11910. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11911. {
  11912. 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
  11913. {
  11914. match = TRUE;
  11915. GunNO = gun_index;
  11916. }
  11917. }
  11918. }// END FOR GB_QUANTITY
  11919. }
  11920. else
  11921. {
  11922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11923. {
  11924. tempIndex = 2;
  11925. }
  11926. else
  11927. {
  11928. tempIndex = gun_index;
  11929. }
  11930. for (int index = 0; index < AC_QUANTITY; index++)
  11931. {
  11932. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11933. {
  11934. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11935. {
  11936. match = TRUE;
  11937. GunNO = gun_index;
  11938. }
  11939. }
  11940. }// END FOR CHAdeMO_QUANTITY
  11941. } // END FOR AC ELSE
  11942. }// CHECK IF ResponseTransactionId == transactionIdInt
  11943. }//END FOR
  11944. if( match == TRUE)
  11945. {
  11946. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11947. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11948. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11949. }
  11950. else
  11951. {
  11952. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11953. }
  11954. }
  11955. else
  11956. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11957. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11958. return result;
  11959. }
  11960. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11961. {
  11962. mtrace();
  11963. int result = FAIL;
  11964. int connectorIdInt=0, reservationIdInt=0;
  11965. int tempIndex = 0;
  11966. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11967. char comfirmstr[20]={0};
  11968. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11969. int c = 0;
  11970. char *loc;
  11971. //char *ptr;
  11972. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11973. strcpy(sstrtemp, stringtrimspace(payload));
  11974. //***(1)connectorId ****/
  11975. c=0;
  11976. loc = strstr(sstrtemp, "connectorId");
  11977. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11978. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11979. {
  11980. sstr[c] = loc[strlen("connectorId")+2+c];
  11981. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11982. c++;
  11983. }
  11984. sstr[c] = '\0';
  11985. connectorIdInt = atoi(sstr);
  11986. //***(2)expiryDate ****/
  11987. loc = strstr(sstrtemp, "expiryDate");
  11988. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11989. c = 0;
  11990. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11991. {
  11992. sstr[c] = loc[3+strlen("expiryDate")+c];
  11993. c++;
  11994. }
  11995. sstr[c] = '\0';
  11996. strcpy(expiryDatestr, sstr);
  11997. //***(3)idTag ****/
  11998. loc = strstr(sstrtemp, "idTag");
  11999. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12000. c = 0;
  12001. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  12002. {
  12003. sstr[c] = loc[3+strlen("idTag")+c];
  12004. c++;
  12005. }
  12006. sstr[c] = '\0';
  12007. strcpy(idTagstr, sstr);
  12008. //***(4)parentIdTag ****/
  12009. loc = strstr(sstrtemp, "parentIdTag");
  12010. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12011. c = 0;
  12012. if(loc == NULL)
  12013. {
  12014. strcpy(parentIdTagstr, "");
  12015. }
  12016. else
  12017. {
  12018. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  12019. {
  12020. sstr[c] = loc[3+strlen("parentIdTag")+c];
  12021. c++;
  12022. }
  12023. sstr[c] = '\0';
  12024. strcpy(parentIdTagstr, sstr);
  12025. }
  12026. //***(5)reservationId ****/
  12027. c=0;
  12028. loc = strstr(sstrtemp, "reservationId");
  12029. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12030. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  12031. {
  12032. sstr[c] = loc[strlen("reservationId")+2+c];
  12033. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12034. c++;
  12035. }
  12036. sstr[c] = '\0';
  12037. reservationIdInt = atoi(sstr);
  12038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12039. /*
  12040. enum SYSTEM_STATUS
  12041. {
  12042. SYS_MODE_BOOTING = 0,
  12043. SYS_MODE_IDLE = 1,
  12044. SYS_MODE_AUTHORIZING = 2,
  12045. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12046. SYS_MODE_REASSIGN = 4,
  12047. SYS_MODE_PREPARING = 5,
  12048. SYS_MODE_PREPARE_FOR_EV = 6,
  12049. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12050. SYS_MODE_CHARGING = 8,
  12051. SYS_MODE_TERMINATING = 9,
  12052. SYS_MODE_COMPLETE = 10,
  12053. SYS_MODE_ALARM = 11,
  12054. SYS_MODE_FAULT = 12,
  12055. SYS_MODE_RESERVATION = 13,
  12056. SYS_MODE_BOOKING = 14,
  12057. SYS_MODE_MAINTAIN = 15,
  12058. SYS_MODE_DEBUG = 16,
  12059. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12060. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12061. SYS_MODE_UPDATE = 19
  12062. };
  12063. */
  12064. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12065. {
  12066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12067. goto end;
  12068. }
  12069. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12070. {
  12071. //check Transaction active
  12072. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12073. {
  12074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12075. {
  12076. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12077. }
  12078. else
  12079. {
  12080. tempIndex = connectorIdInt -1;
  12081. }
  12082. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12083. {
  12084. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12085. {
  12086. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12087. {
  12088. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12089. {
  12090. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12091. {
  12092. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12093. {
  12094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12095. }
  12096. else
  12097. {
  12098. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12100. }
  12101. }
  12102. 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'))
  12103. {
  12104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12105. }
  12106. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12107. {
  12108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12109. }
  12110. else
  12111. {
  12112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12113. }
  12114. }
  12115. 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
  12116. {
  12117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12118. }
  12119. }
  12120. else
  12121. {
  12122. //replace reservation
  12123. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12124. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12125. }
  12126. }
  12127. } // END FOR CHAdeMO_QUANTITY
  12128. }
  12129. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12130. {
  12131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12132. {
  12133. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12134. }
  12135. else
  12136. {
  12137. tempIndex = connectorIdInt -1;
  12138. }
  12139. for (int index = 0; index < CCS_QUANTITY; index++)
  12140. {
  12141. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12142. {
  12143. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12144. {
  12145. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12146. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12147. {
  12148. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12149. {
  12150. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12151. {
  12152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12153. }
  12154. else
  12155. {
  12156. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12158. }
  12159. }
  12160. 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'))
  12161. {
  12162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12163. }
  12164. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12165. {
  12166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12167. }
  12168. else
  12169. {
  12170. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12171. }
  12172. }
  12173. 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
  12174. {
  12175. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12176. }
  12177. }
  12178. else
  12179. {
  12180. //replace reservation
  12181. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12182. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12183. }
  12184. }
  12185. } // END FOR CCS_QUANTITY
  12186. }
  12187. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12188. {
  12189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12190. {
  12191. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12192. }
  12193. else
  12194. {
  12195. tempIndex = connectorIdInt -1;
  12196. }
  12197. for (int index = 0; index < GB_QUANTITY; index++)
  12198. {
  12199. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12200. {
  12201. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12202. {
  12203. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12204. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12205. {
  12206. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12207. {
  12208. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12209. {
  12210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12211. }
  12212. else
  12213. {
  12214. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12216. }
  12217. }
  12218. 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'))
  12219. {
  12220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12221. }
  12222. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12223. {
  12224. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12225. }
  12226. else
  12227. {
  12228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12229. }
  12230. }
  12231. 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
  12232. {
  12233. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12234. }
  12235. }
  12236. else
  12237. {
  12238. //replace reservation
  12239. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12241. }
  12242. }
  12243. }// END FOR GB_QUANTITY
  12244. }
  12245. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12246. {
  12247. tempIndex = connectorIdInt -1;
  12248. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12249. {
  12250. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12251. {
  12252. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12253. {
  12254. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12255. 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
  12256. {
  12257. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12258. {
  12259. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12260. {
  12261. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12262. }
  12263. else
  12264. {
  12265. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12266. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12267. }
  12268. }
  12269. 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'))
  12270. {
  12271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12272. }
  12273. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12274. {
  12275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12276. }
  12277. else
  12278. {
  12279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12280. }
  12281. }
  12282. 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
  12283. {
  12284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12285. }
  12286. }
  12287. else
  12288. {
  12289. //replace reservation
  12290. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12291. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12292. }
  12293. }
  12294. }// END FOR GB_QUANTITY
  12295. }
  12296. else
  12297. {
  12298. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12299. {
  12300. tempIndex = 2;
  12301. }
  12302. else
  12303. {
  12304. tempIndex = (connectorIdInt -1);
  12305. }
  12306. for (int index = 0; index < AC_QUANTITY; index++)
  12307. {
  12308. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12309. {
  12310. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12311. {
  12312. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12313. {
  12314. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12315. {
  12316. 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))
  12317. {
  12318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12319. }
  12320. else
  12321. {
  12322. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12324. }
  12325. }
  12326. 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'))
  12327. {
  12328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12329. }
  12330. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12331. {
  12332. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12333. }
  12334. else
  12335. {
  12336. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12337. }
  12338. }
  12339. 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
  12340. {
  12341. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12342. }
  12343. }
  12344. else
  12345. {
  12346. //replace reservation
  12347. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12348. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12349. }
  12350. }
  12351. } // END FOR AC_QUANTITY
  12352. }
  12353. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12354. }
  12355. else if(connectorIdInt == 0)
  12356. {
  12357. //check Transaction active
  12358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12359. {
  12360. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12361. {
  12362. 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'))
  12363. {
  12364. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12365. goto end;
  12366. }
  12367. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12368. {
  12369. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12370. goto end;
  12371. }
  12372. 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
  12373. {
  12374. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12375. goto end;
  12376. }
  12377. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12378. {
  12379. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12380. goto end;
  12381. }
  12382. }
  12383. }// END FOR CHAdeMO_QUANTITY
  12384. for (int index = 0; index < CCS_QUANTITY; index++)
  12385. {
  12386. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12387. {
  12388. 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'))
  12389. {
  12390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12391. goto end;
  12392. }
  12393. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12394. {
  12395. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12396. goto end;
  12397. }
  12398. 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
  12399. {
  12400. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12401. goto end;
  12402. }
  12403. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12404. {
  12405. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12406. goto end;
  12407. }
  12408. }
  12409. } // END FOR CCS_QUANTITY
  12410. for (int index = 0; index < GB_QUANTITY; index++)
  12411. {
  12412. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12413. {
  12414. 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'))
  12415. {
  12416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12417. goto end;
  12418. }
  12419. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12420. {
  12421. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12422. goto end;
  12423. }
  12424. 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
  12425. {
  12426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12427. goto end;
  12428. }
  12429. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12430. {
  12431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12432. goto end;
  12433. }
  12434. }
  12435. } // END FOR GB_QUANTITY
  12436. for (int index = 0; index < AC_QUANTITY; index++)
  12437. {
  12438. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12439. {
  12440. 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'))
  12441. {
  12442. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12443. goto end;
  12444. }
  12445. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12446. {
  12447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12448. goto end;
  12449. }
  12450. 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
  12451. {
  12452. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12453. goto end;
  12454. }
  12455. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12456. {
  12457. 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))
  12458. {
  12459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12460. goto end;
  12461. }
  12462. }
  12463. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12464. {
  12465. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12466. goto end;
  12467. }
  12468. }
  12469. }// END FOR AC_QUANTITY
  12470. //The connectorId is 0
  12471. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12472. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12473. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12474. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12475. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12476. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12477. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12478. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12479. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12480. result = TRUE;
  12481. return result;
  12482. }
  12483. else
  12484. {
  12485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12486. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12487. }
  12488. if(strcmp(comfirmstr,"Accepted") == 0)
  12489. {
  12490. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12491. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12492. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12493. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12494. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12495. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12496. result = TRUE;
  12497. return result;
  12498. }
  12499. end:
  12500. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12501. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12502. return result;
  12503. }
  12504. int handleResetRequest(char *uuid, char *payload)
  12505. {
  12506. mtrace();
  12507. int result = FAIL;
  12508. char sstr[10]={0},sstrtemp[30]={ 0 };
  12509. char typestr[10]={0};
  12510. char comfirmstr[20]={0};
  12511. int c = 0;
  12512. char *loc;
  12513. DEBUG_INFO("handleResetRequest...\n");
  12514. strcpy(sstrtemp, stringtrimspace(payload));
  12515. loc = strstr(sstrtemp, "type");
  12516. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12517. c = 0;
  12518. while (loc[3+strlen("type")+c] != '\"')
  12519. {
  12520. sstr[c] = loc[3+strlen("type")+c];
  12521. c++;
  12522. }
  12523. sstr[c] = '\0';
  12524. strcpy(typestr,sstr);
  12525. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12526. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12527. {
  12528. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12529. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12530. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12531. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12532. }
  12533. else
  12534. {
  12535. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12536. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12537. result = PASS;
  12538. }
  12539. sendResetConfirmation(uuid, comfirmstr);
  12540. return result;
  12541. }
  12542. int handleSendLocalListRequest(char *uuid, char *payload)
  12543. {
  12544. mtrace();
  12545. int result = FAIL;
  12546. char comfirmstr[20];
  12547. int checkState_Faulted = FALSE;
  12548. json_object *SendLocalList;
  12549. DEBUG_INFO("handleSendLocalListRequest...\n");
  12550. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12551. {
  12552. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12553. goto end;
  12554. }
  12555. //check Charge Point state
  12556. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12557. {
  12558. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12559. {
  12560. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12561. }
  12562. }
  12563. for (int index = 0; index < CCS_QUANTITY; index++)
  12564. {
  12565. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12566. {
  12567. checkState_Faulted = TRUE; //OCPP Status
  12568. }
  12569. }
  12570. for (int index = 0; index < GB_QUANTITY; index++)
  12571. {
  12572. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12573. {
  12574. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12575. }
  12576. }
  12577. //check Charge Point state
  12578. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12579. {
  12580. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12581. {
  12582. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12583. }
  12584. }
  12585. //check Charge Point state
  12586. for (int index = 0; index < AC_QUANTITY; index++)
  12587. {
  12588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12589. {
  12590. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12591. }
  12592. }
  12593. if(checkState_Faulted == TRUE)
  12594. {
  12595. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12596. goto end;
  12597. }
  12598. // Parsing payload
  12599. SendLocalList = json_tokener_parse(payload);
  12600. if(!is_error(SendLocalList))
  12601. {
  12602. // Required data
  12603. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12604. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12605. // Optional data
  12606. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12607. {
  12608. //Check UpdateType
  12609. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12610. {
  12611. //Local list full update
  12612. DEBUG_INFO("Local list full update.\n");
  12613. locallistVersion = 0;
  12614. OCPP_getListVerion();
  12615. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12616. {
  12617. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12618. goto end;
  12619. }
  12620. OCPP_cleanLocalList();
  12621. }
  12622. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12623. {
  12624. //Local list different update
  12625. DEBUG_INFO("Local list different update.\n");
  12626. locallistVersion = 0;
  12627. OCPP_getListVerion();
  12628. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12629. {
  12630. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12631. goto end;
  12632. }
  12633. }
  12634. else
  12635. {
  12636. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12637. goto end;
  12638. }
  12639. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12640. {
  12641. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12642. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12643. goto end;
  12644. }
  12645. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12646. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12647. {
  12648. 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"))));
  12649. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12650. {
  12651. 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"))));
  12652. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12653. 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"))));
  12654. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12655. 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"))));
  12656. }
  12657. // Add to db
  12658. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12659. {
  12660. //Local list full update
  12661. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12662. idx,
  12663. ShmOCPP16Data->SendLocalList.ListVersion,
  12664. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12665. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12666. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12667. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12668. // update list
  12669. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12670. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12671. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12672. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12673. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12674. }
  12675. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12676. {
  12677. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12678. idx,
  12679. ShmOCPP16Data->SendLocalList.ListVersion,
  12680. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12681. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12682. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12683. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12684. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12685. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12686. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12687. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12688. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12689. }
  12690. }
  12691. }
  12692. else
  12693. {
  12694. //Check UpdateType
  12695. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12696. {
  12697. //Local list full update
  12698. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12699. OCPP_cleanLocalList();
  12700. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12701. goto end;
  12702. }
  12703. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12704. {
  12705. //Local list different update
  12706. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12707. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12708. goto end;
  12709. }
  12710. }
  12711. result = PASS;
  12712. }
  12713. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12714. end:
  12715. json_object_put(SendLocalList);
  12716. sendSendLocalListConfirmation(uuid, comfirmstr);
  12717. return result;
  12718. }
  12719. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12720. {
  12721. mtrace();
  12722. int result = FAIL;
  12723. struct StructSetChargingProfile SetProfileReq = {0};
  12724. int tempchargingProfileIdInt;
  12725. int tempstackLevelInt;
  12726. int chargingSchedulePeriodCount = 0;
  12727. char comfirmstr[20]={0};
  12728. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12729. char rmFileCmd[128]={0};
  12730. int profileQuantity = 0;
  12731. int replaceableProfileCnt = 0;
  12732. json_object *SetChargingProfile;
  12733. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12734. SetChargingProfile = json_tokener_parse(payload);
  12735. if(!is_error(SetChargingProfile))
  12736. {
  12737. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12738. {
  12739. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12740. }
  12741. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12742. {
  12743. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12744. {
  12745. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12746. }
  12747. else
  12748. {
  12749. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12750. DEBUG_WARN("Cannot find chargingProfileId field.");
  12751. goto end;
  12752. }
  12753. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12754. {
  12755. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12756. }
  12757. else
  12758. {
  12759. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12760. DEBUG_WARN("Cannot find stackLevel field.");
  12761. goto end;
  12762. }
  12763. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12764. {
  12765. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12766. }
  12767. else
  12768. {
  12769. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12770. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12771. goto end;
  12772. }
  12773. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12774. {
  12775. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12776. }
  12777. else
  12778. {
  12779. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12780. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12781. goto end;
  12782. }
  12783. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12784. {
  12785. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12786. }
  12787. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12788. {
  12789. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12790. }
  12791. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12792. {
  12793. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12794. }
  12795. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12796. {
  12797. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12798. }
  12799. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12800. {
  12801. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12802. {
  12803. 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")));
  12804. }
  12805. else
  12806. {
  12807. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12808. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12809. goto end;
  12810. }
  12811. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12812. {
  12813. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12814. }
  12815. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12816. {
  12817. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12818. }
  12819. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12820. {
  12821. 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")));
  12822. }
  12823. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12824. {
  12825. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12826. if(chargingSchedulePeriodCount <= 10)
  12827. {
  12828. 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++)
  12829. {
  12830. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  12831. {
  12832. 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"));
  12833. }
  12834. else
  12835. {
  12836. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12837. DEBUG_WARN("Cannot find startPeriod field.");
  12838. goto end;
  12839. }
  12840. 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)
  12841. {
  12842. 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"));
  12843. }
  12844. else
  12845. {
  12846. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12847. DEBUG_WARN("Cannot find limit field.");
  12848. goto end;
  12849. }
  12850. 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)
  12851. {
  12852. 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"));
  12853. }
  12854. }
  12855. }
  12856. }
  12857. else
  12858. {
  12859. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12860. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12861. goto end;
  12862. }
  12863. }
  12864. else
  12865. {
  12866. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12867. DEBUG_WARN("Cannot find chargingSchedule field.");
  12868. goto end;
  12869. }
  12870. }
  12871. }
  12872. // Profile periods quantity check
  12873. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12874. {
  12875. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12876. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12877. goto end;
  12878. }
  12879. // Check invalid limit
  12880. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12881. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12882. {
  12883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12884. {
  12885. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12886. {
  12887. 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)))) ||
  12888. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12889. {
  12890. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12891. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12892. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12893. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12894. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12895. goto end;
  12896. }
  12897. }
  12898. }
  12899. else
  12900. {
  12901. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12902. {
  12903. 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) ||
  12904. (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)))
  12905. {
  12906. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12907. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12908. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12909. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12910. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12911. goto end;
  12912. }
  12913. }
  12914. }
  12915. }
  12916. // Profile purpose info check
  12917. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12918. {
  12919. FILE *fp;
  12920. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12921. if(SetProfileReq.ConnectorId != 0)
  12922. {
  12923. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12924. DEBUG_WARN("Profile connector id is not 0.\n");
  12925. goto end;
  12926. }
  12927. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12928. if (!fp)
  12929. {
  12930. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12931. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12932. }
  12933. else
  12934. {
  12935. char *line = NULL;
  12936. size_t len = 0;
  12937. while(getline(&line, &len, fp) != -1)
  12938. {
  12939. json_object *obj = NULL;
  12940. obj = json_tokener_parse(line);
  12941. if(is_error(obj))
  12942. {
  12943. DEBUG_ERROR("Parse txProfile from file error.\n");
  12944. }
  12945. else
  12946. {
  12947. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12948. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12949. {
  12950. profileQuantity += 1;
  12951. }
  12952. else
  12953. replaceableProfileCnt += 1;
  12954. }
  12955. }
  12956. }
  12957. fclose(fp);
  12958. }
  12959. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12960. {
  12961. FILE *fp;
  12962. char filename[128]={0};
  12963. int tmpProfileQuantity;
  12964. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12965. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12966. {
  12967. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12968. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12969. goto end;
  12970. }
  12971. if(SetProfileReq.ConnectorId == 0)
  12972. {
  12973. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12974. {
  12975. tmpProfileQuantity = 0;
  12976. memset(filename, 0, ARRAY_SIZE(filename));
  12977. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12978. fp = fopen(filename, "r");
  12979. if (!fp)
  12980. {
  12981. DEBUG_INFO("%s does not create.\n", filename);
  12982. fp = fopen(filename, "w+");
  12983. }
  12984. else
  12985. {
  12986. char *line = NULL;
  12987. size_t len = 0;
  12988. while(getline(&line, &len, fp) != -1)
  12989. {
  12990. json_object *obj = NULL;
  12991. obj = json_tokener_parse(line);
  12992. if(is_error(obj))
  12993. {
  12994. DEBUG_ERROR("Parse txProfile from file error.\n");
  12995. }
  12996. else
  12997. {
  12998. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12999. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13000. {
  13001. tmpProfileQuantity += 1;
  13002. }
  13003. else
  13004. replaceableProfileCnt += 1;
  13005. }
  13006. }
  13007. }
  13008. fclose(fp);
  13009. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  13010. }
  13011. }
  13012. else
  13013. {
  13014. memset(filename, 0, ARRAY_SIZE(filename));
  13015. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13016. fp = fopen(filename, "r");
  13017. if (!fp)
  13018. {
  13019. DEBUG_INFO("%s does not create.\n", filename);
  13020. fp = fopen(filename, "w+");
  13021. }
  13022. else
  13023. {
  13024. char *line = NULL;
  13025. size_t len = 0;
  13026. while(getline(&line, &len, fp) != -1)
  13027. {
  13028. json_object *obj = NULL;
  13029. obj = json_tokener_parse(line);
  13030. if(is_error(obj))
  13031. {
  13032. DEBUG_ERROR("Parse txProfile from file error.\n");
  13033. }
  13034. else
  13035. {
  13036. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13037. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13038. {
  13039. profileQuantity += 1;
  13040. }
  13041. else
  13042. replaceableProfileCnt += 1;
  13043. }
  13044. }
  13045. }
  13046. fclose(fp);
  13047. }
  13048. }
  13049. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13050. {
  13051. int isMatchTransactiodId= FALSE;
  13052. FILE *fp;
  13053. char filename[128]={0};
  13054. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13055. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13056. if(SetProfileReq.ConnectorId == 0)
  13057. {
  13058. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13059. DEBUG_WARN("Profile connector id is 0.\n");
  13060. goto end;
  13061. }
  13062. int tempIndex = 0;
  13063. //check Transaction active
  13064. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13065. {
  13066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13067. {
  13068. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13069. }
  13070. else
  13071. {
  13072. tempIndex = SetProfileReq.ConnectorId -1;
  13073. }
  13074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13075. {
  13076. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13077. {
  13078. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13079. {
  13080. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13081. {
  13082. isMatchTransactiodId = TRUE;
  13083. break;
  13084. }
  13085. }
  13086. }
  13087. }
  13088. }
  13089. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13090. {
  13091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13092. {
  13093. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13094. }
  13095. else
  13096. {
  13097. tempIndex = SetProfileReq.ConnectorId -1;
  13098. }
  13099. for (int index = 0; index < CCS_QUANTITY; index++)
  13100. {
  13101. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13102. {
  13103. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13104. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13105. {
  13106. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13107. {
  13108. isMatchTransactiodId = TRUE;
  13109. break;
  13110. }
  13111. }
  13112. }
  13113. }
  13114. }
  13115. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13116. {
  13117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13118. {
  13119. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13120. }
  13121. else
  13122. {
  13123. tempIndex = SetProfileReq.ConnectorId -1;
  13124. }
  13125. for (int index = 0; index < GB_QUANTITY; index++)
  13126. {
  13127. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13128. {
  13129. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13130. {
  13131. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13132. {
  13133. isMatchTransactiodId = TRUE;
  13134. break;
  13135. }
  13136. }
  13137. }
  13138. }
  13139. }
  13140. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13141. {
  13142. tempIndex = SetProfileReq.ConnectorId -1;
  13143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13144. {
  13145. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13146. {
  13147. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13148. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13149. {
  13150. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13151. {
  13152. isMatchTransactiodId = TRUE;
  13153. break;
  13154. }
  13155. }
  13156. }
  13157. }
  13158. }
  13159. else
  13160. {
  13161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13162. {
  13163. tempIndex = 2;
  13164. }
  13165. else
  13166. {
  13167. tempIndex = (SetProfileReq.ConnectorId -1);
  13168. }
  13169. for (int index = 0; index < AC_QUANTITY; index++)
  13170. {
  13171. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13172. {
  13173. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13174. {
  13175. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13176. {
  13177. isMatchTransactiodId = TRUE;
  13178. break;
  13179. }
  13180. }
  13181. }
  13182. }
  13183. }
  13184. //check Transaction active
  13185. if(isMatchTransactiodId == FALSE)
  13186. {
  13187. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13188. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13189. goto end;
  13190. }
  13191. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13192. {
  13193. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13194. DEBUG_WARN("Connector id is over max gun number.\n");
  13195. goto end;
  13196. }
  13197. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13198. fp = fopen(filename, "r");
  13199. if (!fp)
  13200. {
  13201. DEBUG_INFO("%s does not create.\n", filename);
  13202. fp = fopen(filename, "w+");
  13203. }
  13204. else
  13205. {
  13206. char *line = NULL;
  13207. size_t len = 0;
  13208. while(getline(&line, &len, fp) != -1)
  13209. {
  13210. json_object *obj = NULL;
  13211. obj = json_tokener_parse(line);
  13212. if(is_error(obj))
  13213. {
  13214. DEBUG_ERROR("Parse txProfile from file error.\n");
  13215. }
  13216. else
  13217. {
  13218. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13219. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13220. {
  13221. profileQuantity += 1;
  13222. }
  13223. else
  13224. replaceableProfileCnt += 1;
  13225. }
  13226. }
  13227. }
  13228. fclose(fp);
  13229. }
  13230. // Check ChargeProfileMaxStackLevel
  13231. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13232. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13233. {
  13234. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13235. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13236. goto end;
  13237. }
  13238. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13239. {
  13240. FILE *fp;
  13241. char dataLine[4096]={0};
  13242. char fnametemp[128]={0};
  13243. int tmpProfileQuantity;
  13244. //Check ChargePointMaxProfile.json exit
  13245. profileQuantity = 0;
  13246. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13247. {
  13248. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13249. //Check Charging Profile Count
  13250. tmpProfileQuantity = 0;
  13251. while(fscanf(fp, "%s", dataLine) != EOF)
  13252. {
  13253. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13254. {
  13255. profileQuantity += 1;
  13256. tmpProfileQuantity += 1;
  13257. }
  13258. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13259. }
  13260. fclose(fp);
  13261. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13262. }
  13263. //Check TxDefaultProfile_%d.json
  13264. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13265. {
  13266. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13267. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13268. if((access(fnametemp,F_OK))!=-1)
  13269. {
  13270. fp = fopen(fnametemp, "r");
  13271. //Check Charging Profile Count
  13272. tmpProfileQuantity = 0;
  13273. while(fscanf(fp, "%s", dataLine) != EOF)
  13274. {
  13275. //DEBUG_INFO("word=%s\n",word);
  13276. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13277. {
  13278. profileQuantity += 1;
  13279. tmpProfileQuantity += 1;
  13280. }
  13281. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13282. }
  13283. fclose(fp);
  13284. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13285. }
  13286. }
  13287. //Check TxProfile_%d.json
  13288. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13289. {
  13290. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13291. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13292. if((access(fnametemp,F_OK))!=-1)
  13293. {
  13294. fp = fopen(fnametemp, "r");
  13295. //Check Charging Profile Count
  13296. tmpProfileQuantity = 0;
  13297. while(fscanf(fp, "%s", dataLine) != EOF)
  13298. {
  13299. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13300. {
  13301. profileQuantity += 1;
  13302. tmpProfileQuantity += 1;
  13303. }
  13304. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13305. }
  13306. fclose(fp);
  13307. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13308. }
  13309. }
  13310. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13311. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13312. // To check total Profile quantity
  13313. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13314. {
  13315. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13316. {
  13317. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13318. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13319. goto end;
  13320. }
  13321. }
  13322. else
  13323. {
  13324. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13325. {
  13326. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13327. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13328. goto end;
  13329. }
  13330. }
  13331. }
  13332. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13333. //**********************************Write to File********************************************************/
  13334. {
  13335. FILE *infile;
  13336. FILE *outfile;
  13337. char dataLine[4096]={0};
  13338. char filename[128]={0};
  13339. int chkChar=0;
  13340. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13341. {
  13342. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13343. {
  13344. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13345. }
  13346. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13347. {
  13348. if(SetProfileReq.ConnectorId==0)
  13349. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13350. else
  13351. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13352. }
  13353. else
  13354. {
  13355. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13356. }
  13357. infile = fopen (filename, "r");
  13358. outfile = fopen (tempfile, "w");
  13359. chkChar = fgetc(infile);
  13360. rewind(infile);
  13361. if(chkChar == EOF)
  13362. {
  13363. // Profile is empty
  13364. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13365. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13366. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13367. fclose(infile);
  13368. fclose(outfile);
  13369. sprintf(rmFileCmd,"rm -f %s",filename);
  13370. system(rmFileCmd);
  13371. rename(tempfile, filename);
  13372. }
  13373. else
  13374. {
  13375. // Profile is not empty
  13376. int ChargingProfileAdded = FALSE;
  13377. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13378. {
  13379. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13380. json_object *tmpChargingProfile;
  13381. tmpChargingProfile = json_tokener_parse(dataLine);
  13382. if(!is_error(SetChargingProfile))
  13383. {
  13384. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13385. {
  13386. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13387. {
  13388. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13389. }
  13390. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13391. {
  13392. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13393. }
  13394. }
  13395. }
  13396. json_object_put(tmpChargingProfile);
  13397. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13398. {
  13399. if(ChargingProfileAdded == FALSE)
  13400. {
  13401. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13402. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13403. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13404. ChargingProfileAdded = TRUE;
  13405. }
  13406. }
  13407. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13408. {
  13409. if(ChargingProfileAdded == FALSE)
  13410. {
  13411. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13412. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13413. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13414. ChargingProfileAdded = TRUE;
  13415. }
  13416. }
  13417. else
  13418. {
  13419. fprintf(outfile,"%s\n",dataLine);
  13420. if(ChargingProfileAdded == FALSE)
  13421. {
  13422. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13423. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13424. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13425. ChargingProfileAdded = TRUE;
  13426. }
  13427. }
  13428. } // end of while loop
  13429. fclose(infile);
  13430. fclose(outfile);
  13431. sprintf(rmFileCmd,"rm -f %s",filename);
  13432. system(rmFileCmd);
  13433. rename(tempfile, filename);
  13434. }
  13435. }
  13436. sleep(1);
  13437. result = TRUE;
  13438. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13439. }
  13440. end:
  13441. json_object_put(SetChargingProfile);
  13442. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13443. {
  13444. if(SetProfileReq.ConnectorId == 0)
  13445. {
  13446. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13447. {
  13448. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13449. }
  13450. }
  13451. else
  13452. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13453. }
  13454. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13455. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13456. return result;
  13457. }
  13458. int handleTriggerMessageRequest(char *uuid, char *payload)
  13459. {
  13460. mtrace();
  13461. int result = FAIL;
  13462. int connectorIdIsNULL = FALSE;
  13463. int connectorIdInt =0;
  13464. char sstr[40]={0},sstrtemp[100]={ 0 };
  13465. char requestedMessagestr[40]={0};
  13466. char comfirmstr[20]={0};
  13467. int c = 0;
  13468. char *loc;
  13469. DEBUG_INFO("handleTriggerMessageRequest\n");
  13470. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13471. strcpy(sstrtemp, stringtrimspace(payload));
  13472. c = 0;
  13473. loc = strstr(sstrtemp, "requestedMessage");
  13474. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13475. {
  13476. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13477. c++;
  13478. }
  13479. sstr[c] = '\0';
  13480. strcpy(requestedMessagestr, sstr);
  13481. c = 0;
  13482. loc = strstr(sstrtemp, "connectorId");
  13483. if(loc == NULL)
  13484. {
  13485. connectorIdIsNULL = TRUE;
  13486. }
  13487. else
  13488. {
  13489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13490. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13491. {
  13492. sstr[c] = loc[strlen("connectorId")+2+c];
  13493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13494. c++;
  13495. }
  13496. sstr[c] = '\0';
  13497. connectorIdInt = atoi(sstr);
  13498. }
  13499. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13500. {
  13501. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13502. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13503. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13504. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13505. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13506. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13507. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13508. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13509. {
  13510. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13511. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13512. return TRUE;
  13513. }
  13514. else
  13515. {
  13516. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13517. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13518. }
  13519. }
  13520. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13521. {
  13522. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13523. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13524. return TRUE;
  13525. }
  13526. //==========================
  13527. // Trigger message
  13528. //==========================
  13529. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13530. {
  13531. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13532. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13533. {
  13534. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13535. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13536. }
  13537. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13538. }
  13539. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13540. {
  13541. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13542. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13543. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13544. }
  13545. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13546. {
  13547. //sendBootNotificationRequest();
  13548. server_sign = FALSE;
  13549. }
  13550. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13551. {
  13552. refreshStartTimer(&clientTime.Heartbeat);
  13553. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13554. }
  13555. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13556. {
  13557. if(connectorIdIsNULL == FALSE)
  13558. {
  13559. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13560. {
  13561. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13562. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13563. }
  13564. }
  13565. else
  13566. {
  13567. for(int idx=0;idx< gunTotalNumber;idx++)
  13568. {
  13569. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13570. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13571. }
  13572. }
  13573. }
  13574. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13575. {
  13576. if(connectorIdIsNULL == FALSE)
  13577. {
  13578. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13579. {
  13580. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13581. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13582. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13583. }
  13584. }
  13585. else
  13586. {
  13587. for(int idx=0;idx< gunTotalNumber;idx++)
  13588. {
  13589. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13590. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13591. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13592. }
  13593. }
  13594. }
  13595. return result;
  13596. }
  13597. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13598. {
  13599. mtrace();
  13600. int result = FAIL;
  13601. int connectorIdInt =0;
  13602. char comfirmstr[20]={0};
  13603. int tempIndex = 0;
  13604. json_object *UnlockConnector;
  13605. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13606. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13607. UnlockConnector = json_tokener_parse(payload);
  13608. if(!is_error(UnlockConnector))
  13609. {
  13610. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13611. {
  13612. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13613. }
  13614. }
  13615. json_object_put(UnlockConnector);
  13616. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13617. if(gunTotalNumber == 0)
  13618. {
  13619. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13620. goto end;
  13621. }
  13622. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13623. {
  13624. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13625. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13626. goto end;
  13627. }
  13628. else
  13629. {
  13630. //check Transaction active
  13631. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13632. {
  13633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13634. {
  13635. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13636. }
  13637. else
  13638. {
  13639. tempIndex = connectorIdInt -1;
  13640. }
  13641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13642. {
  13643. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13644. {
  13645. //stop Transaction
  13646. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13647. }
  13648. }
  13649. }
  13650. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13651. {
  13652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13653. {
  13654. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13655. }
  13656. else
  13657. {
  13658. tempIndex = connectorIdInt -1;
  13659. }
  13660. for (int index = 0; index < CCS_QUANTITY; index++)
  13661. {
  13662. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13663. {
  13664. //stop Transaction
  13665. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13666. }
  13667. }
  13668. }
  13669. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13670. {
  13671. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13672. {
  13673. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13674. }
  13675. else
  13676. {
  13677. tempIndex = connectorIdInt -1;
  13678. }
  13679. for (int index = 0; index < GB_QUANTITY; index++)
  13680. {
  13681. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13682. {
  13683. //stop Transaction
  13684. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13685. }
  13686. }
  13687. }
  13688. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13689. {
  13690. tempIndex = connectorIdInt -1;
  13691. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13692. {
  13693. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13694. {
  13695. //stop Transaction
  13696. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13697. }
  13698. }
  13699. }
  13700. else
  13701. {
  13702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13703. {
  13704. tempIndex = 2;
  13705. }
  13706. else
  13707. {
  13708. tempIndex = connectorIdInt-1;
  13709. }
  13710. for (int index = 0; index < AC_QUANTITY; index++)
  13711. {
  13712. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13713. {
  13714. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13715. }
  13716. }
  13717. }
  13718. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13719. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13720. result = TRUE;
  13721. return result;
  13722. }
  13723. end:
  13724. //json_object_put(obj); --- remove temporally
  13725. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13726. return result;
  13727. }
  13728. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13729. {
  13730. mtrace();
  13731. int result = FAIL;
  13732. pthread_t t;
  13733. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13734. sendUpdateFirmwareConfirmation(uuid);
  13735. if(!interLock.isUpdateFirmwareGoing)
  13736. {
  13737. interLock.isUpdateFirmwareGoing = 1;
  13738. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13739. sleep(1);
  13740. }
  13741. else
  13742. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13743. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13744. return result;
  13745. }
  13746. void *UpdateFirmwareProcess(void *data)
  13747. {
  13748. pthread_detach(pthread_self());
  13749. mtrace();
  13750. int retriesInt =0, retryIntervalInt=0;
  13751. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13752. int port=0;
  13753. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13754. int isSuccess = 0;
  13755. char ftpbuf[1024];
  13756. char temp[1024];
  13757. char * pch;
  13758. json_object *UpdateFirmware;
  13759. UpdateFirmware = json_tokener_parse(data);
  13760. if(!is_error(UpdateFirmware))
  13761. {
  13762. // Required data
  13763. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13764. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13765. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13766. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13767. // Optional data
  13768. if(json_object_object_get(UpdateFirmware, "retries"))
  13769. {
  13770. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13771. }
  13772. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13773. {
  13774. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13775. }
  13776. }
  13777. json_object_put(UpdateFirmware);
  13778. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13779. memset(path, 0, ARRAY_SIZE(path));
  13780. // Wait retrieveData
  13781. if(strlen(retrieveDatestr) > 10)
  13782. {
  13783. do
  13784. {
  13785. sleep(1);
  13786. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13787. }
  13788. // Ready to download
  13789. system("rm -f /mnt/*");
  13790. if(strncmp(locationstr,"http", 4) == 0)
  13791. {
  13792. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13793. sprintf(ftppath,"/%s", path);
  13794. DEBUG_INFO("locationstr: %s\n", locationstr);
  13795. DEBUG_INFO("protocol: %s\n",protocol);
  13796. DEBUG_INFO("host: %s\n",host);
  13797. DEBUG_INFO("path: %s\n",path);
  13798. DEBUG_INFO("ftppath: %s\n",ftppath);
  13799. int ftppathlen=strlen(ftppath);
  13800. int i=1;
  13801. char filenametemp[50];
  13802. while(i < ftppathlen)
  13803. {
  13804. int len=ftppathlen-i;
  13805. if(ftppath[len]== 47) // '/' ascll code: 47
  13806. {
  13807. DEBUG_INFO("compare '/' all right\n");
  13808. break;
  13809. }
  13810. i=i+1;
  13811. }
  13812. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13813. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13814. filenametemp[i+1] = 0;
  13815. do
  13816. {
  13817. sleep(1);
  13818. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13819. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13820. sleep(1);
  13821. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13822. if(!isSuccess)
  13823. {
  13824. sleep(1);
  13825. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13826. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13827. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13828. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13829. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13830. }
  13831. else
  13832. {
  13833. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13834. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13835. }
  13836. retriesInt--;
  13837. }while((isSuccess == 0)&&(retriesInt >= 0));
  13838. }
  13839. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13840. {
  13841. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13842. memset(temp, 0, ARRAY_SIZE(temp));
  13843. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13844. strcpy(ftpbuf, locationstr);
  13845. int ftppathlen=strlen(ftpbuf);
  13846. int i=1;
  13847. char filenametemp[50];
  13848. while(i < ftppathlen)
  13849. {
  13850. int len=ftppathlen-i;
  13851. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13852. {
  13853. DEBUG_INFO(" compare '/' all right\n");
  13854. break;
  13855. }
  13856. i=i+1;
  13857. }
  13858. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13859. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13860. filenametemp[i+1] = 0;
  13861. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13862. pch=strchr(temp,'@');
  13863. if(pch==NULL)
  13864. {
  13865. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13866. protocol, host, &port, path);
  13867. strcpy(user,"anonymous");
  13868. strcpy(password,"");
  13869. }
  13870. else
  13871. {
  13872. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13873. protocol, user, host, &port, path);
  13874. }
  13875. sscanf(host,"%[^/]%s",host1, path1);
  13876. sprintf(ftppath,"%s:/%s", host,path);
  13877. if(port == 0)
  13878. {
  13879. port = 21;
  13880. }
  13881. do
  13882. {
  13883. sleep(1);
  13884. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13885. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13886. sleep(1);
  13887. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13888. if(!isSuccess)
  13889. {
  13890. //BulldogUtil.sleepMs(interval*1000);
  13891. DEBUG_INFO("Update firmware request and download file fail.\n");
  13892. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13893. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13894. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13895. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13896. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13897. }
  13898. else
  13899. {
  13900. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13901. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13902. }
  13903. retriesInt--;
  13904. }while((!isSuccess)&&(retriesInt >= 0));
  13905. }
  13906. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13907. {
  13908. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13909. memset(temp, 0, ARRAY_SIZE(temp));
  13910. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13911. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13912. int ftppathlen=strlen(ftpbuf);
  13913. int i=1;
  13914. char filenametemp[50];
  13915. while(i < ftppathlen)
  13916. {
  13917. int len=ftppathlen-i;
  13918. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13919. {
  13920. DEBUG_INFO(" compare '/' all right\n");
  13921. break;
  13922. }
  13923. i=i+1;
  13924. }
  13925. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13926. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13927. filenametemp[i+1] = 0;
  13928. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13929. pch=strchr(temp,'@');
  13930. if(pch==NULL)
  13931. {
  13932. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13933. protocol, host, &port, path);
  13934. strcpy(user,"anonymous");
  13935. strcpy(password,"");
  13936. }
  13937. else
  13938. {
  13939. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13940. protocol, user, password, host, &port, path);
  13941. }
  13942. sscanf(host,"%[^/]%s",host1, path1);
  13943. sprintf(ftppath,"%s", path1);
  13944. //DEBUG_INFO("protocol =%s\n",protocol);
  13945. //DEBUG_INFO("user =%s\n",user);
  13946. //DEBUG_INFO("password =%s\n",password);
  13947. //DEBUG_INFO("host1 =%s\n",host1);
  13948. //DEBUG_INFO("port =%d\n",port);
  13949. //DEBUG_INFO("path1 =%s\n",path1);
  13950. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13951. //ftpFile(host, user, password, port, ftppath, fname);
  13952. //download firmware pthred
  13953. if(port == 0)
  13954. {
  13955. port = 21;
  13956. }
  13957. do
  13958. {
  13959. sleep(1);
  13960. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13961. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13962. sleep(1);
  13963. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13964. if(!isSuccess)
  13965. {
  13966. //BulldogUtil.sleepMs(interval*1000);
  13967. DEBUG_INFO("Update firmware request and download file fail.\n");
  13968. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13969. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13970. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13971. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13972. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13973. }
  13974. else
  13975. {
  13976. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13977. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13978. }
  13979. retriesInt--;
  13980. }while((!isSuccess)&&(retriesInt >= 0));
  13981. }
  13982. else
  13983. {
  13984. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13985. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13986. sleep(1);
  13987. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13988. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13989. }
  13990. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13991. {
  13992. sleep(3);
  13993. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13994. }
  13995. interLock.isUpdateFirmwareGoing = 0;
  13996. pthread_exit(NULL);
  13997. }
  13998. int handleCertificateSignedRequest(char *uuid, char *payload)
  13999. {
  14000. mtrace();
  14001. int result = PASS;
  14002. json_object *CertificateSigned;
  14003. DEBUG_INFO("handleCertificateSignedRequest...\n");
  14004. CertificateSigned = json_tokener_parse(payload);
  14005. if(!is_error(CertificateSigned))
  14006. {
  14007. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  14008. }
  14009. json_object_put(CertificateSigned);
  14010. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  14011. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  14012. fclose(fp);
  14013. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14014. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  14015. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  14016. {
  14017. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  14018. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  14019. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  14020. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  14021. }
  14022. else
  14023. {
  14024. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  14025. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  14026. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14027. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14028. }
  14029. sendCertificateSignedConfirmation(uuid);
  14030. return result;
  14031. }
  14032. int handleDeleteCertificateRequest(char *uuid, char *payload)
  14033. {
  14034. mtrace();
  14035. int result = PASS;
  14036. json_object *DeleteCertificate;
  14037. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  14038. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14039. DeleteCertificate = json_tokener_parse(payload);
  14040. if(!is_error(DeleteCertificate))
  14041. {
  14042. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14043. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14044. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14045. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14046. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14047. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14048. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14049. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14050. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  14051. {
  14052. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  14053. }
  14054. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  14055. {
  14056. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  14057. }
  14058. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  14059. {
  14060. ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  14061. }
  14062. char temp[256] = {0};
  14063. char compareData[256] = {0};
  14064. int isMatch = TRUE;
  14065. // Check CentralSystemRootCertificate
  14066. if(access(ROOTCA_CS,F_OK) != -1)
  14067. {
  14068. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14069. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14070. for(int i = 0; compareData[i]; i++)
  14071. {
  14072. compareData[i] = tolower(compareData[i]);
  14073. }
  14074. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14075. isMatch = FALSE;
  14076. if(isMatch == TRUE)
  14077. {
  14078. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14079. for(int i = 0; compareData[i]; i++)
  14080. {
  14081. compareData[i] = tolower(compareData[i]);
  14082. }
  14083. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14084. isMatch = FALSE;
  14085. }
  14086. if(isMatch == TRUE)
  14087. {
  14088. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14089. for(int i = 0; compareData[i]; i++)
  14090. {
  14091. compareData[i] = tolower(compareData[i]);
  14092. }
  14093. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14094. isMatch = FALSE;
  14095. }
  14096. if(isMatch == TRUE)
  14097. {
  14098. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  14099. sprintf(temp, "rm -f %s", ROOTCA_CS);
  14100. system(temp);
  14101. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14102. goto End;
  14103. }
  14104. }
  14105. // Check ManufacturerRootCertificate
  14106. if(access(ROOTCA_MF,F_OK) != -1)
  14107. {
  14108. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  14109. isMatch = TRUE;
  14110. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  14111. for(int i = 0; compareData[i]; i++)
  14112. {
  14113. compareData[i] = tolower(compareData[i]);
  14114. }
  14115. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14116. isMatch = FALSE;
  14117. if(isMatch == TRUE)
  14118. {
  14119. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  14120. for(int i = 0; compareData[i]; i++)
  14121. {
  14122. compareData[i] = tolower(compareData[i]);
  14123. }
  14124. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14125. isMatch = FALSE;
  14126. }
  14127. if(isMatch == TRUE)
  14128. {
  14129. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  14130. for(int i = 0; compareData[i]; i++)
  14131. {
  14132. compareData[i] = tolower(compareData[i]);
  14133. }
  14134. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14135. isMatch = FALSE;
  14136. }
  14137. if(isMatch == TRUE)
  14138. {
  14139. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  14140. sprintf(temp, "rm -f %s", ROOTCA_MF);
  14141. system(temp);
  14142. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14143. goto End;
  14144. }
  14145. }
  14146. // Check certCP
  14147. if(access(CERTIFICATE_CP,F_OK) != -1)
  14148. {
  14149. DEBUG_INFO("Checking certCP...\n");
  14150. isMatch = TRUE;
  14151. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  14152. for(int i = 0; compareData[i]; i++)
  14153. {
  14154. compareData[i] = tolower(compareData[i]);
  14155. }
  14156. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14157. isMatch = FALSE;
  14158. if(isMatch == TRUE)
  14159. {
  14160. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  14161. for(int i = 0; compareData[i]; i++)
  14162. {
  14163. compareData[i] = tolower(compareData[i]);
  14164. }
  14165. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14166. isMatch = FALSE;
  14167. }
  14168. if(isMatch == TRUE)
  14169. {
  14170. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  14171. for(int i = 0; compareData[i]; i++)
  14172. {
  14173. compareData[i] = tolower(compareData[i]);
  14174. }
  14175. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14176. isMatch = FALSE;
  14177. }
  14178. if(isMatch == TRUE)
  14179. {
  14180. DEBUG_INFO("Deleting certCP...\n");
  14181. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14182. system(temp);
  14183. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14184. goto End;
  14185. }
  14186. }
  14187. }
  14188. End:
  14189. json_object_put(DeleteCertificate);
  14190. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14191. sendDeleteCertificateConfirmation(uuid);
  14192. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14193. return result;
  14194. }
  14195. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14196. {
  14197. mtrace();
  14198. int result = PASS;
  14199. json_object *ExtendedTriggerMessage;
  14200. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14201. ExtendedTriggerMessage = json_tokener_parse(payload);
  14202. if(!is_error(ExtendedTriggerMessage))
  14203. {
  14204. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14205. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14206. {
  14207. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14208. }
  14209. else
  14210. {
  14211. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14212. }
  14213. }
  14214. json_object_put(ExtendedTriggerMessage);
  14215. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14216. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14217. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14218. {
  14219. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14220. }
  14221. else
  14222. {
  14223. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14224. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14225. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14226. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14227. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14228. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14229. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14230. {
  14231. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14232. }
  14233. else
  14234. {
  14235. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14236. }
  14237. }
  14238. sendExtendedTriggerMessageConfirmation(uuid);
  14239. //==========================
  14240. // Trigger message
  14241. //==========================
  14242. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14243. {
  14244. //sendBootNotificationRequest();
  14245. server_sign = FALSE;
  14246. }
  14247. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14248. {
  14249. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14250. }
  14251. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14252. {
  14253. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14254. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14255. {
  14256. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14257. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14258. }
  14259. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14260. }
  14261. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14262. {
  14263. refreshStartTimer(&clientTime.Heartbeat);
  14264. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14265. }
  14266. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14267. {
  14268. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14269. {
  14270. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14271. }
  14272. else
  14273. {
  14274. for(int idx=0;idx< gunTotalNumber;idx++)
  14275. {
  14276. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14277. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14278. }
  14279. }
  14280. }
  14281. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14282. {
  14283. char cmdBuf[1024]={0};
  14284. 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);
  14285. system(cmdBuf);
  14286. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14287. }
  14288. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14289. {
  14290. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14291. {
  14292. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14293. }
  14294. else
  14295. {
  14296. for(int idx=0;idx< gunTotalNumber;idx++)
  14297. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14298. }
  14299. }
  14300. return result;
  14301. }
  14302. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14303. {
  14304. mtrace();
  14305. int result = PASS;
  14306. json_object *GetInstalledCertificateIds;
  14307. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14308. GetInstalledCertificateIds = json_tokener_parse(payload);
  14309. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14310. if(!is_error(GetInstalledCertificateIds))
  14311. {
  14312. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14313. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14314. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14315. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  14316. // Check CentralSystemRootCertificate
  14317. if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL)
  14318. {
  14319. if(access(ROOTCA_CS,F_OK) != -1)
  14320. {
  14321. char parseData[512] = {0};
  14322. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14323. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14324. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  14325. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14326. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14327. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14328. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14329. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14330. }
  14331. else
  14332. {
  14333. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  14334. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14335. }
  14336. }
  14337. // Check ManufacturerRootCertificate
  14338. else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
  14339. {
  14340. if(access(ROOTCA_MF,F_OK) != -1)
  14341. {
  14342. char parseData[512] = {0};
  14343. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14344. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14345. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  14346. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14347. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14348. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14349. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14350. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14351. }
  14352. else
  14353. {
  14354. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  14355. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14356. }
  14357. }
  14358. else
  14359. {
  14360. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14361. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14362. }
  14363. }
  14364. json_object_put(GetInstalledCertificateIds);
  14365. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14366. sendGetInstalledCertificateIdsConfirmation(uuid);
  14367. return result;
  14368. }
  14369. void* GetLogProcess(void* data)
  14370. {
  14371. pthread_detach(pthread_self());
  14372. mtrace();
  14373. 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};
  14374. int port=0;
  14375. int isSuccess = FALSE;
  14376. char cmdBuf[2048];
  14377. struct tm *tmNow;
  14378. time_t CurrentTime;
  14379. struct tm tmStart;
  14380. struct tm tmStop;
  14381. CurrentTime = time(NULL);
  14382. tmNow=localtime(&CurrentTime);
  14383. uint16_t targetYear, targetMonth;
  14384. json_object *GetLog;
  14385. DEBUG_INFO("GetLogProcess...\n");
  14386. GetLog = json_tokener_parse(data);
  14387. if(!is_error(GetLog))
  14388. {
  14389. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14390. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14391. if(json_object_object_get(GetLog, "retries") != NULL)
  14392. {
  14393. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14394. }
  14395. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14396. {
  14397. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14398. }
  14399. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14400. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14401. {
  14402. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14403. }
  14404. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14405. {
  14406. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14407. }
  14408. }
  14409. json_object_put(GetLog);
  14410. // Pack log to compress file
  14411. 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) &&
  14412. (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))
  14413. {
  14414. // Pack system log
  14415. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14416. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14417. targetYear = tmStart.tm_year;
  14418. targetMonth = tmStart.tm_mon;
  14419. do
  14420. {
  14421. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14422. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14423. if(targetMonth+1>=13)
  14424. {
  14425. targetYear += 1;
  14426. targetMonth = 1;
  14427. }
  14428. else
  14429. {
  14430. targetMonth += 1;
  14431. }
  14432. }while((targetYear < (tmNow->tm_year+1900)) ||
  14433. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14434. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14435. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14436. system(cmdBuf);
  14437. // Pack charging & event log
  14438. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14439. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14440. targetYear = tmStart.tm_year;
  14441. targetMonth = tmStart.tm_mon;
  14442. do
  14443. {
  14444. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14445. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14446. if(targetMonth+1>=13)
  14447. {
  14448. targetYear += 1;
  14449. targetMonth = 1;
  14450. }
  14451. else
  14452. {
  14453. targetMonth += 1;
  14454. }
  14455. }while((targetYear < (tmNow->tm_year+1900)) ||
  14456. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14457. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14458. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14459. system(cmdBuf);
  14460. // Combine log file
  14461. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14462. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14463. }
  14464. else
  14465. {
  14466. system("exec /root/logPackTools 'log' 6");
  14467. }
  14468. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14469. system(cmdBuf);
  14470. checkUploadLog();
  14471. //****************location*******************/
  14472. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14473. {
  14474. DEBUG_INFO("location is <Empty>!\n");
  14475. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14476. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14477. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14478. goto end;
  14479. }
  14480. memset(protocol, 0, ARRAY_SIZE(protocol));
  14481. memset(user, 0, ARRAY_SIZE(user) );
  14482. memset(password, 0, ARRAY_SIZE(password));
  14483. memset(host, 0, ARRAY_SIZE(host));
  14484. memset(path, 0, ARRAY_SIZE(path));
  14485. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14486. memset(host1, 0, ARRAY_SIZE(host1));
  14487. memset(path1, 0, ARRAY_SIZE(path1));
  14488. /*location: ftp://user:password@host:port/path*/
  14489. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14490. if((access(fnamePlusPath,F_OK))!=-1)
  14491. {
  14492. DEBUG_INFO("fnamePlusPath exist.\n");
  14493. }
  14494. else
  14495. {
  14496. DEBUG_INFO("fnamePlusPath not exist!\n");
  14497. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14498. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14499. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14500. goto end;
  14501. }
  14502. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14503. {
  14504. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14505. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14506. protocol, host, &port, path);
  14507. strcpy(user,"anonymous");
  14508. strcpy(password,"");
  14509. }
  14510. else
  14511. {
  14512. //DEBUG_INFO("pch=%s\n", pch);
  14513. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14514. protocol, user, password, host, &port, path);
  14515. }
  14516. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14517. {
  14518. DEBUG_INFO("protocol is not ftp/http ! \n");
  14519. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14520. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14521. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14522. goto end;
  14523. }
  14524. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14525. {
  14526. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14527. sprintf(ftppath,"/%s", path);
  14528. do
  14529. {
  14530. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14531. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14532. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14533. sleep(3);
  14534. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14535. if(!isSuccess)
  14536. {
  14537. DEBUG_INFO("Diagnostics fail.\n");
  14538. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14539. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14540. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14541. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14542. }
  14543. else
  14544. {
  14545. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14546. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14547. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14548. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14549. }
  14550. ShmOCPP16Data->GetLog.retries--;
  14551. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14552. }
  14553. else
  14554. {
  14555. sscanf(host,"%[^/]%s",host1, path1);
  14556. if(strlen(path) > 0)
  14557. sprintf(ftppath,"/%s", path);
  14558. else
  14559. sprintf(ftppath,"/%s", path1);
  14560. int ftppathlen=strlen(ftppath);
  14561. int i=1;
  14562. char filenametemp[50];
  14563. while(i < ftppathlen)
  14564. {
  14565. int len=ftppathlen-i;
  14566. if(ftppath[len]== 47) // '/' ascll code: 47
  14567. {
  14568. DEBUG_INFO("find '/' all right\n");
  14569. break;
  14570. }
  14571. i=i+1;
  14572. }
  14573. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14574. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14575. filenametemp[i+1] = 0;
  14576. if(port == 0)
  14577. port = 21;
  14578. do
  14579. {
  14580. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14581. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14582. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14583. sleep(3);
  14584. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14585. if(!isSuccess)
  14586. {
  14587. DEBUG_INFO("Diagnostics fail.\n");
  14588. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14589. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14590. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14591. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14592. }
  14593. else
  14594. {
  14595. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14596. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14597. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14598. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14599. }
  14600. ShmOCPP16Data->GetLog.retries--;
  14601. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14602. }
  14603. end:
  14604. system("rm -f /mnt/*");
  14605. sleep(5);
  14606. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14607. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14608. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14609. interLock.isGetDiagnosticGoing = 0;
  14610. pthread_exit(NULL);
  14611. }
  14612. int handleGetLogRequest(char *uuid, char *payload)
  14613. {
  14614. mtrace();
  14615. int result = PASS;
  14616. time_t CurrentTime;
  14617. struct tm *tm;
  14618. DEBUG_INFO("handleGetLogRequest...\n");
  14619. pthread_t th_Status;
  14620. CurrentTime = time(NULL);
  14621. tm = localtime(&CurrentTime);
  14622. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14623. 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);
  14624. if(!interLock.isGetDiagnosticGoing)
  14625. {
  14626. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14627. interLock.isGetDiagnosticGoing = 1;
  14628. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14629. sleep(1);
  14630. }
  14631. else
  14632. {
  14633. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14634. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14635. }
  14636. sendGetLogConfirmation(uuid);
  14637. return result;
  14638. }
  14639. int handleInstallCertificateRequest(char *uuid, char *payload)
  14640. {
  14641. mtrace();
  14642. int result = PASS;
  14643. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14644. json_object *InstallCertificate;
  14645. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14646. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14647. InstallCertificate = json_tokener_parse(payload);
  14648. if(!is_error(InstallCertificate))
  14649. {
  14650. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14651. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14652. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14653. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14654. char temp[1024];
  14655. FILE *fp = fopen(tempCert, "w");
  14656. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14657. fclose(fp);
  14658. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14659. char strExpDate[30];
  14660. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14661. fp = popen(temp, "r");
  14662. if(fp)
  14663. {
  14664. while(fgets(temp, sizeof(temp), fp) != NULL)
  14665. {
  14666. if(strstr(temp, "notAfter=") != NULL)
  14667. {
  14668. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14669. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14670. break;
  14671. }
  14672. }
  14673. }
  14674. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14675. struct tm tmExpDate;
  14676. struct timeb tbExpDate;
  14677. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14678. tbExpDate.time = mktime(&tmExpDate);
  14679. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14680. {
  14681. DEBUG_INFO("The enddate is already expired...\n");
  14682. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14683. goto End;
  14684. }
  14685. // Verify certificate with rootCA
  14686. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14687. fp = popen(temp, "r");
  14688. if(fp)
  14689. {
  14690. while(fgets(temp, sizeof(temp), fp) != NULL)
  14691. {
  14692. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14693. {
  14694. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14695. break;
  14696. }
  14697. else
  14698. {
  14699. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14700. }
  14701. }
  14702. }
  14703. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14704. {
  14705. //=====================================================
  14706. // Verify if the certificate is valid or not. (OCSP?)
  14707. //=====================================================
  14708. /*
  14709. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14710. // Get ocsp url
  14711. char ocspUrl[512];
  14712. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14713. fp = popen(temp, "r");
  14714. if(fp)
  14715. {
  14716. while(fgets(temp, sizeof(temp), fp) != NULL)
  14717. {
  14718. if(strstr(temp, "://") != NULL)
  14719. {
  14720. strcpy(ocspUrl, temp);
  14721. break;
  14722. }
  14723. }
  14724. }
  14725. // Get certificate chain for issuer
  14726. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14727. *
  14728. // Execute OCSP
  14729. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14730. fp = popen(temp, "r");
  14731. if(fp)
  14732. {
  14733. while(fgets(temp, sizeof(temp), fp) != NULL)
  14734. {
  14735. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14736. {
  14737. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14738. break;
  14739. }
  14740. }
  14741. }
  14742. system("rm -f /Storage/OCPP/tempChain.pem");
  14743. pclose(fp);
  14744. */
  14745. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14746. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14747. {
  14748. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14749. goto End;
  14750. }
  14751. else
  14752. DEBUG_INFO("OCSP verifying...PASS.\n");
  14753. }
  14754. else
  14755. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14756. }
  14757. End:
  14758. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14759. {
  14760. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14761. {
  14762. if(access(ROOTCA_CS,F_OK) != -1)
  14763. {
  14764. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14765. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14766. rename(tempCert, ROOTCA_CS);
  14767. }
  14768. else
  14769. {
  14770. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14771. rename(tempCert, ROOTCA_CS);
  14772. }
  14773. }
  14774. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14775. {
  14776. if(access(ROOTCA_MF,F_OK) != -1)
  14777. {
  14778. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14779. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14780. rename(tempCert, ROOTCA_MF);
  14781. }
  14782. else
  14783. {
  14784. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14785. rename(tempCert, ROOTCA_MF);
  14786. }
  14787. }
  14788. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14789. }
  14790. sendInstallCertificateConfirmation(uuid);
  14791. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14792. {
  14793. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14794. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14795. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14796. }
  14797. json_object_put(InstallCertificate);
  14798. return result;
  14799. }
  14800. void *SignedUpdateFirmwareProcess(void *data)
  14801. {
  14802. pthread_detach(pthread_self());
  14803. mtrace();
  14804. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14805. int port=0;
  14806. int isSuccess = 0;
  14807. char ftpbuf[1024];
  14808. char temp[1024];
  14809. char * pch;
  14810. char firmwareFileName[50];
  14811. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14812. json_object *SignedUpdateFirmware;
  14813. SignedUpdateFirmware = json_tokener_parse(data);
  14814. if(!is_error(SignedUpdateFirmware))
  14815. {
  14816. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14817. {
  14818. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14819. }
  14820. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14821. {
  14822. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14823. }
  14824. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14825. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14826. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14827. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14828. {
  14829. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14830. }
  14831. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14832. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14833. }
  14834. json_object_put(SignedUpdateFirmware);
  14835. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14836. memset(path, 0, ARRAY_SIZE(path));
  14837. // Wait retrieveData
  14838. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14839. {
  14840. do
  14841. {
  14842. sleep(1);
  14843. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14844. }
  14845. // Ready to download
  14846. system("rm -f /mnt/*");
  14847. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14848. {
  14849. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14850. sprintf(ftppath,"/%s", path);
  14851. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14852. DEBUG_INFO("protocol: %s\n",protocol);
  14853. DEBUG_INFO("host: %s\n",host);
  14854. DEBUG_INFO("path: %s\n",path);
  14855. DEBUG_INFO("ftppath: %s\n",ftppath);
  14856. int ftppathlen=strlen(ftppath);
  14857. int i=1;
  14858. while(i < ftppathlen)
  14859. {
  14860. int len=ftppathlen-i;
  14861. if(ftppath[len]== 47) // '/' ascll code: 47
  14862. {
  14863. DEBUG_INFO("compare '/' all right\n");
  14864. break;
  14865. }
  14866. i=i+1;
  14867. }
  14868. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14869. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14870. firmwareFileName[i+1] = 0;
  14871. do
  14872. {
  14873. sleep(1);
  14874. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14875. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14876. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14877. sleep(1);
  14878. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14879. if(!isSuccess)
  14880. {
  14881. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14882. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14883. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14884. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14885. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14886. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14887. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14888. }
  14889. else
  14890. {
  14891. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14892. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14893. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14894. }
  14895. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14896. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14897. }
  14898. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14899. {
  14900. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14901. memset(temp, 0, ARRAY_SIZE(temp));
  14902. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14903. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14904. int ftppathlen=strlen(ftpbuf);
  14905. int i=1;
  14906. while(i < ftppathlen)
  14907. {
  14908. int len=ftppathlen-i;
  14909. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14910. {
  14911. DEBUG_INFO(" compare '/' all right\n");
  14912. break;
  14913. }
  14914. i=i+1;
  14915. }
  14916. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14917. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14918. firmwareFileName[i+1] = 0;
  14919. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14920. pch=strchr(temp,'@');
  14921. if(pch==NULL)
  14922. {
  14923. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14924. protocol, host, &port, path);
  14925. strcpy(user,"anonymous");
  14926. strcpy(password,"");
  14927. }
  14928. else
  14929. {
  14930. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14931. protocol, user, host, &port, path);
  14932. }
  14933. sscanf(host,"%[^/]%s",host1, path1);
  14934. sprintf(ftppath,"%s:/%s", host,path);
  14935. if(port == 0)
  14936. {
  14937. port = 21;
  14938. }
  14939. do
  14940. {
  14941. sleep(1);
  14942. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14943. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14944. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14945. sleep(1);
  14946. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14947. if(!isSuccess)
  14948. {
  14949. sleep(1);
  14950. DEBUG_INFO("Update firmware request and download file fail.\n");
  14951. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14952. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14953. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14954. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14955. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14956. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14957. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14958. }
  14959. else
  14960. {
  14961. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14962. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14963. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14964. }
  14965. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14966. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14967. }
  14968. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14969. {
  14970. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14971. memset(temp, 0, ARRAY_SIZE(temp));
  14972. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14973. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14974. int ftppathlen=strlen(ftpbuf);
  14975. int i=1;
  14976. while(i < ftppathlen)
  14977. {
  14978. int len=ftppathlen-i;
  14979. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14980. {
  14981. DEBUG_INFO(" compare '/' all right\n");
  14982. break;
  14983. }
  14984. i=i+1;
  14985. }
  14986. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14987. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14988. firmwareFileName[i+1] = 0;
  14989. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14990. pch=strchr(temp,'@');
  14991. if(pch==NULL)
  14992. {
  14993. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14994. protocol, host, &port, path);
  14995. strcpy(user,"anonymous");
  14996. strcpy(password,"");
  14997. }
  14998. else
  14999. {
  15000. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  15001. protocol, user, password, host, &port, path);
  15002. }
  15003. sscanf(host,"%[^/]%s",host1, path1);
  15004. sprintf(ftppath,"%s", path1);
  15005. //DEBUG_INFO("protocol =%s\n",protocol);
  15006. //DEBUG_INFO("user =%s\n",user);
  15007. //DEBUG_INFO("password =%s\n",password);
  15008. //DEBUG_INFO("host1 =%s\n",host1);
  15009. //DEBUG_INFO("port =%d\n",port);
  15010. //DEBUG_INFO("path1 =%s\n",path1);
  15011. //DEBUG_INFO("ftppath=%s\n",ftppath);
  15012. //ftpFile(host, user, password, port, ftppath, fname);
  15013. //download firmware pthred
  15014. if(port == 0)
  15015. {
  15016. port = 21;
  15017. }
  15018. do
  15019. {
  15020. sleep(1);
  15021. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15022. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15023. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15024. sleep(1);
  15025. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15026. if(!isSuccess)
  15027. {
  15028. //BulldogUtil.sleepMs(interval*1000);
  15029. DEBUG_INFO("Update firmware request and download file fail.\n");
  15030. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15031. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15032. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15033. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15034. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15035. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15036. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15037. }
  15038. else
  15039. {
  15040. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15041. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15042. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15043. }
  15044. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15045. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15046. }
  15047. else
  15048. {
  15049. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15050. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15051. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15052. sleep(1);
  15053. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15054. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15055. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15056. }
  15057. // Verify firmware image signature
  15058. struct stat st;
  15059. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15060. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15061. fclose(fp);
  15062. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15063. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15064. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15065. fclose(fp);
  15066. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15067. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15068. if(st.st_size == 0)
  15069. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15070. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15071. {
  15072. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15073. fp = popen(temp, "r");
  15074. if(fp)
  15075. {
  15076. while(fgets(temp, sizeof(temp), fp) != NULL)
  15077. {
  15078. if(strstr(temp, "Verified OK") != NULL)
  15079. {
  15080. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15081. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15082. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15083. }
  15084. else
  15085. {
  15086. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15087. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15088. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15089. sleep(1);
  15090. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15091. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15092. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15093. sleep(1);
  15094. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15095. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15096. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15097. }
  15098. break;
  15099. }
  15100. }
  15101. pclose(fp);
  15102. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15103. }
  15104. interLock.isUpdateFirmwareGoing = 0;
  15105. pthread_exit(NULL);
  15106. }
  15107. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15108. {
  15109. mtrace();
  15110. int result = PASS;
  15111. pthread_t t;
  15112. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15113. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15114. sendSignedUpdateFirmwareConfirmation(uuid);
  15115. if(!interLock.isUpdateFirmwareGoing)
  15116. {
  15117. interLock.isUpdateFirmwareGoing = 1;
  15118. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15119. sleep(1);
  15120. }
  15121. else
  15122. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15123. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15124. return result;
  15125. }
  15126. int handleUnknownRequest(char *uuid, char *payload)
  15127. {
  15128. mtrace();
  15129. int result = PASS;
  15130. DEBUG_INFO("handleUnknownRequest...\n");
  15131. sendUnknownConfirmation(uuid);
  15132. return result;
  15133. }
  15134. //==========================================
  15135. // Handle server response routine
  15136. //==========================================
  15137. void handleAuthorizeResponse(char *payload, int gun_index)
  15138. {
  15139. mtrace();
  15140. char expiryDatestr[36]={0};
  15141. char parentIdTagstr[21]={0};
  15142. char statusstr[20]={0};
  15143. int expiryDateISNULL=FALSE;
  15144. int parentIdTagISNULL=FALSE;
  15145. DEBUG_INFO("handleAuthorizeResponse...\n");
  15146. json_object *Authorize;
  15147. Authorize = json_tokener_parse(payload);
  15148. if(!is_error(Authorize))
  15149. {
  15150. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15151. {
  15152. // Required data
  15153. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15154. // Optional data
  15155. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15156. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15157. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15158. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15159. }
  15160. }
  15161. json_object_put(Authorize);
  15162. if(expiryDateISNULL == FALSE)
  15163. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15164. if(parentIdTagISNULL == FALSE)
  15165. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15166. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15167. //Update idTag information to authorization cache if supproted
  15168. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15169. {
  15170. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15171. }
  15172. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15173. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15174. authorizeRetryTimes = 0;
  15175. }
  15176. void handleBootNotificationResponse(char *payload, int gun_index)
  15177. {
  15178. mtrace();
  15179. char statusStr[12]={0};
  15180. char currentTimeStr[30]={0};
  15181. int intervalInt = 0;
  15182. DEBUG_INFO("handleBootNotificationResponse...\n");
  15183. json_object *BootNotification;
  15184. BootNotification = json_tokener_parse(payload);
  15185. if(!is_error(BootNotification))
  15186. {
  15187. // Required data
  15188. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15189. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15190. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15191. }
  15192. json_object_put(BootNotification);
  15193. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15194. BootNotificationInterval = intervalInt;
  15195. //write back to ShmOCPP16Data->BootNotification
  15196. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15197. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15198. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15199. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15200. {
  15201. BootNotificationInterval = 0;
  15202. if((intervalInt == 0) || (intervalInt >= 10))
  15203. {
  15204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15205. HeartBeatWaitTime = intervalInt;
  15206. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15207. }
  15208. server_sign = TRUE;
  15209. server_pending =FALSE;
  15210. }
  15211. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15212. {
  15213. server_pending = TRUE;
  15214. }
  15215. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15216. srand(time(NULL));
  15217. refreshStartTimer(&clientTime.Heartbeat);
  15218. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15219. SetOcppConnStatus(TRUE);
  15220. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15221. }
  15222. void handleDataTransferResponse(char *payload, int gun_index)
  15223. {
  15224. json_object *DataTransfer = json_tokener_parse(payload);
  15225. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15226. if(!is_error(DataTransfer))
  15227. {
  15228. // Required data
  15229. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15230. // Optional data
  15231. if(json_object_object_get(DataTransfer, "data") != NULL)
  15232. {
  15233. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15234. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15235. if(!is_error(Data))
  15236. {
  15237. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15238. {
  15239. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15240. {
  15241. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15242. }
  15243. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15244. {
  15245. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15246. {
  15247. 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")));
  15248. }
  15249. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15250. {
  15251. 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")));
  15252. }
  15253. }
  15254. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15255. }
  15256. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15257. {
  15258. if(json_object_object_get(Data, "status") != NULL)
  15259. {
  15260. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15261. }
  15262. if(json_object_object_get(Data, "exiResponse") != NULL)
  15263. {
  15264. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15265. }
  15266. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15267. }
  15268. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15269. {
  15270. if(json_object_object_get(Data, "status") != NULL)
  15271. {
  15272. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15273. }
  15274. if(json_object_object_get(Data, "ocspResult") != NULL)
  15275. {
  15276. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15277. }
  15278. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15279. }
  15280. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15281. {
  15282. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15283. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15284. }
  15285. else
  15286. {
  15287. if(json_object_object_get(Data, "msgId") != NULL)
  15288. {
  15289. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15290. {
  15291. 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")));
  15292. }
  15293. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15294. {
  15295. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15296. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15297. }
  15298. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyFeeAct") != NULL)
  15299. {
  15300. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15301. {
  15302. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15303. if(json_object_object_get(Data, "occupancySN") != NULL)
  15304. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancySN, "%s", json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15305. if(json_object_object_get(Data, "startTime") != NULL)
  15306. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_startTime, "%s", json_object_get_string(json_object_object_get(Data, "startTime")));
  15307. if(json_object_object_get(Data, "duration") != NULL)
  15308. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_duration = json_object_get_int(json_object_object_get(Data, "duration"));
  15309. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15310. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancyFee = json_object_get_double(json_object_object_get(Data, "occupancyFee"));
  15311. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].OccupancyFeeActReq = 0;
  15312. }
  15313. else
  15314. {
  15315. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15316. {
  15317. if(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq)
  15318. {
  15319. strcpy((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].response_status, "Rejected");
  15320. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq = 0;
  15321. }
  15322. }
  15323. }
  15324. }
  15325. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15326. {
  15327. if(json_object_object_get(Data, "occupancySN") != NULL)
  15328. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15329. }
  15330. }
  15331. }
  15332. }
  15333. json_object_put(Data);
  15334. }
  15335. }
  15336. json_object_put(DataTransfer);
  15337. }
  15338. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15339. {
  15340. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15341. //struct json_object *obj;
  15342. // obj = json_tokener_parse(payload);
  15343. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15344. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15345. //No fields are defined.
  15346. }
  15347. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15348. {
  15349. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15350. //struct json_object *obj;
  15351. // obj = json_tokener_parse(payload);
  15352. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15353. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15354. //No fields are defined.
  15355. }
  15356. void handleHeartbeatResponse(char *payload, int gun_index)
  15357. {
  15358. mtrace();
  15359. DEBUG_INFO("handleHeartbeatResponse...\n");
  15360. json_object *Heartbeat;
  15361. Heartbeat = json_tokener_parse(payload);
  15362. if(!is_error(Heartbeat))
  15363. {
  15364. // Required data
  15365. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15366. }
  15367. json_object_put(Heartbeat);
  15368. if(FirstHeartBeat == 0)
  15369. {
  15370. FirstHeartBeat = 1;
  15371. DEBUG_INFO("FirstHeartBeat \n");
  15372. }
  15373. HeartBeatWithNOResponse = 0;
  15374. refreshStartTimer(&clientTime.Heartbeat);
  15375. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15376. }
  15377. void handleMeterValuesResponse(char *payload, int gun_index)
  15378. {
  15379. mtrace();
  15380. DEBUG_INFO("handleMeterValuesResponse...\n");
  15381. isQueueSendable = 1;
  15382. }
  15383. void handleStartTransactionResponse(char *payload, int gun_index)
  15384. {
  15385. mtrace();
  15386. //int transactionIdInt = 0;
  15387. FILE *outfile;
  15388. char data[100]={0};
  15389. DEBUG_INFO("handleStartTransactionResponse...\n");
  15390. json_object *StartTransaction;
  15391. StartTransaction = json_tokener_parse(payload);
  15392. if(!is_error(StartTransaction))
  15393. {
  15394. // Required data
  15395. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15396. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15397. // Optional data
  15398. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15399. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15400. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15401. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15402. }
  15403. json_object_put(StartTransaction);
  15404. OCPP_updatePeriodEnergy(gun_index);
  15405. //-----------Start : write to the Queue TransactionId file -----------------//
  15406. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15407. {}
  15408. else
  15409. {
  15410. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15411. if(log == NULL)
  15412. {
  15413. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15414. return ;
  15415. }
  15416. else
  15417. {
  15418. fclose(log);
  15419. }
  15420. }
  15421. // open file for writing
  15422. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15423. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15424. {
  15425. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15426. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15427. fputs(data, outfile);
  15428. fclose (outfile);
  15429. DEBUG_INFO("Update QueueTransactionId done...\n");
  15430. }
  15431. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15432. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15433. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15434. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15435. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15436. isQueueSendable = 1;
  15437. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15438. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15439. }
  15440. void handleStatusNotificationResponse(char *payload, int gun_index)
  15441. {
  15442. mtrace();
  15443. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15444. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15445. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15446. if(gun_index != 99)
  15447. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15448. }
  15449. void handleStopTransactionnResponse(char *payload, int gun_index)
  15450. {
  15451. mtrace();
  15452. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15453. json_object *StopTransaction;
  15454. StopTransaction = json_tokener_parse(payload);
  15455. if(!is_error(StopTransaction))
  15456. {
  15457. // Optional data
  15458. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15459. {
  15460. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15461. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15462. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15463. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15464. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15465. }
  15466. }
  15467. json_object_put(StopTransaction);
  15468. isQueueSendable = 1;
  15469. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15470. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15471. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15472. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15473. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15474. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15475. }
  15476. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15477. {
  15478. mtrace();
  15479. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15480. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15481. }
  15482. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15483. {
  15484. mtrace();
  15485. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15486. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15487. }
  15488. void handleSignCertificateResponse(char *payload, int gun_index)
  15489. {
  15490. mtrace();
  15491. DEBUG_INFO("handleSignCertificateResponse...\n");
  15492. json_object *SignCertificate;
  15493. SignCertificate = json_tokener_parse(payload);
  15494. if(!is_error(SignCertificate))
  15495. {
  15496. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15497. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15498. }
  15499. json_object_put(SignCertificate);
  15500. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15501. }
  15502. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15503. {
  15504. mtrace();
  15505. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15506. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15507. }
  15508. //==========================================
  15509. // Handle Error routine
  15510. //==========================================
  15511. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15512. {
  15513. mtrace();
  15514. #ifdef SystemLogMessage
  15515. DEBUG_INFO("errorCode: %s\n", errorCode);
  15516. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15517. DEBUG_INFO("errorDetails: %s\n", payload);
  15518. #endif
  15519. }
  15520. //===============================================
  15521. // Common routine
  15522. //===============================================
  15523. int initialConfigurationTable(void)
  15524. {
  15525. //clock_t start_t, end_t, total_t;
  15526. FILE *fp;
  15527. FILE *outfile;
  15528. char str[512]={0};
  15529. char sstr[256]={0};
  15530. int c = 0;
  15531. char *loc;
  15532. int confVersion = 23;
  15533. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15534. //start_t = clock();
  15535. //printf("Starting of the program, start_t = %ld\n", start_t);
  15536. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15537. // Check configuration file size is correct
  15538. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15539. {
  15540. struct stat st;
  15541. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15542. if(st.st_size < 3100)
  15543. {
  15544. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15545. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15546. }
  15547. }
  15548. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15549. {
  15550. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15551. if(outfile == NULL)
  15552. {
  15553. DEBUG_INFO("Error opening file\n");
  15554. return FALSE;
  15555. }
  15556. /*Core Profile*/
  15557. //AllowOfflineTxForUnknownId
  15558. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15562. //AuthorizationCacheEnabled
  15563. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15567. //AuthorizeRemoteTxRequests
  15568. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15572. //BlinkRepeat
  15573. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15577. //ClockAlignedDataInterval
  15578. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15582. //ConnectionTimeOut
  15583. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15585. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15587. else
  15588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15590. //GetConfigurationMaxKeys
  15591. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15595. // HeartbeatInterval
  15596. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15600. // LightIntensity
  15601. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15605. // LocalAuthorizeOffline
  15606. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15610. // LocalPreAuthorize
  15611. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15615. // MaxEnergyOnInvalidId
  15616. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15620. // MeterValuesAlignedData
  15621. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15623. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15624. 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" );
  15625. else
  15626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15628. // MeterValuesAlignedDataMaxLength
  15629. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15633. else
  15634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15636. // MeterValuesSampledData
  15637. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15640. 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" );
  15641. else
  15642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15644. // MeterValuesSampledDataMaxLength
  15645. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15649. else
  15650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15652. // MeterValueSampleInterval
  15653. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15657. // MinimumStatusDuration
  15658. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15661. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15663. // NumberOfConnectors
  15664. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15667. {
  15668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15669. }
  15670. else
  15671. {
  15672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15673. }
  15674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15675. // ResetRetries
  15676. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15680. // ConnectorPhaseRotation
  15681. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15685. // ConnectorPhaseRotationMaxLength
  15686. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15690. // StopTransactionOnEVSideDisconnect
  15691. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15695. // StopTransactionOnInvalidId
  15696. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15700. // StopTxnAlignedData
  15701. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15705. // StopTxnAlignedDataMaxLength
  15706. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15708. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15709. {
  15710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 8);
  15711. }
  15712. else
  15713. {
  15714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 10);
  15715. }
  15716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15717. // StopTxnSampledData
  15718. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15722. // StopTxnSampledDataMaxLength
  15723. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15725. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15726. {
  15727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 8);
  15728. }
  15729. else
  15730. {
  15731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 10);
  15732. }
  15733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15734. // SupportedFeatureProfiles
  15735. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15739. // SupportedFeatureProfilesMaxLength
  15740. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15744. // TransactionMessageAttempts
  15745. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15748. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15750. // TransactionMessageRetryInterval
  15751. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15754. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15756. // UnlockConnectorOnEVSideDisconnect
  15757. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15761. // WebSocketPingInterval
  15762. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15766. // QueueOffLineMeterValues
  15767. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15771. // AuthorizationKey
  15772. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15776. // SecurityProfile
  15777. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15781. // DefaultPrice
  15782. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15786. // CustomDisplayCostAndPrice
  15787. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15791. // CustomIdleFeeAfterStop
  15792. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15796. // TimeOffset
  15797. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15801. // NextTimeOffsetTransitionDateTime
  15802. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15806. // TimeOffsetNextTransition
  15807. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15811. // SystemUptimeSec
  15812. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15816. // FreeVend
  15817. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15821. // FreeVendIdtag
  15822. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15826. // OcppServer
  15827. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15829. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15831. // MaintainServer
  15832. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15834. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15836. // StatusNotificationPeriodically
  15837. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15841. // StatusNotificationInterval
  15842. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15846. // PreAuthAmount
  15847. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15851. // isEnableLocalPowerSharing
  15852. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15856. // PowerSharingServerIP
  15857. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15859. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15861. // EVCCID_PREFIX
  15862. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15866. // OffLineMaxChargingPower
  15867. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15871. // Configuration Version
  15872. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15876. // Charging profile refresh interval
  15877. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15881. // CpoName
  15882. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15886. // Ocpp Software certificated version
  15887. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15891. //* Local Auth List Management Profile*/
  15892. #if 0
  15893. //For OCTT Test Case
  15894. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15897. #endif
  15898. #if 1
  15899. //LocalAuthListEnabled
  15900. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15904. #endif
  15905. //LocalAuthListMaxLength
  15906. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15910. //SendLocalListMaxLength
  15911. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15915. //ReserveConnectorZeroSupported
  15916. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15920. //* Smart Charging Profile */
  15921. //ChargeProfileMaxStackLevel
  15922. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15926. // ChargingScheduleAllowedChargingRateUnit
  15927. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15931. // ChargingScheduleMaxPeriods
  15932. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15936. // ConnectorSwitch3to1PhaseSupported
  15937. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15941. // MaxChargingProfilesInstalled
  15942. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15946. fclose(outfile);
  15947. }
  15948. else
  15949. {
  15950. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15951. char keystr[60]={0};
  15952. char readonlystr[10]={0};
  15953. char valuestr[256]={0};
  15954. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15955. if(fp == NULL) {
  15956. DEBUG_INFO("Error opening file");
  15957. return FALSE;
  15958. }
  15959. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15960. {
  15961. //DEBUG_INFO("Get Configuration \n");
  15962. if(strlen(str) > 0)
  15963. {
  15964. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15965. //*************************key*********************************/
  15966. if(strstr(str, "key") != NULL)
  15967. {
  15968. loc = strstr(str, "key");
  15969. c = 0;
  15970. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15971. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15972. {
  15973. sstr[c] = loc[strlen("key")+3+c];
  15974. c++;
  15975. }
  15976. sstr[c] = '\0';
  15977. strcpy(keystr,sstr);
  15978. }
  15979. //*************************readonly*********************************/
  15980. if(strstr(str, "readonly") != NULL)
  15981. {
  15982. loc = strstr(str, "readonly");
  15983. c = 0;
  15984. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15985. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  15986. {
  15987. sstr[c] = loc[strlen("readonly")+2+c];
  15988. c++;
  15989. }
  15990. sstr[c] = '\0';
  15991. strcpy(readonlystr,sstr);
  15992. }
  15993. //*************************value*********************************/
  15994. if(strstr(str, "value") != NULL)
  15995. {
  15996. loc = strstr(str, "value");
  15997. c = 0;
  15998. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15999. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  16000. {
  16001. sstr[c] = loc[strlen("value")+3+c];
  16002. c++;
  16003. }
  16004. sstr[c] = '\0';
  16005. strcpy(valuestr,sstr);
  16006. }
  16007. // DEBUG_INFO("keystr=%s\n",keystr);
  16008. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  16009. // DEBUG_INFO("valuestr=%s\n",valuestr);
  16010. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  16011. {
  16012. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16013. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  16015. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16016. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16017. }
  16018. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  16019. {
  16020. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16021. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  16023. }
  16024. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  16025. {
  16026. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  16028. }
  16029. if(strcmp(keystr, "BlinkRepeat") == 0)
  16030. {
  16031. //Charger.BlinkRepeat = Integer.parseInt(value);
  16032. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  16034. }
  16035. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  16036. {
  16037. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  16039. }
  16040. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16041. {
  16042. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16044. }
  16045. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16046. {
  16047. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16049. }
  16050. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16051. {
  16052. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16054. HeartBeatWaitTime = atoi(valuestr);
  16055. }
  16056. if(strcmp(keystr, "LightIntensity") == 0)
  16057. {
  16058. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16060. }
  16061. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16062. {
  16063. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16065. }
  16066. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16067. {
  16068. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16070. }
  16071. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16072. {
  16073. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16075. }
  16076. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16077. {
  16078. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16080. }
  16081. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16082. {
  16083. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16085. }
  16086. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16087. {
  16088. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16090. }
  16091. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16092. {
  16093. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16095. }
  16096. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16097. {
  16098. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16100. }
  16101. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16102. {
  16103. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16105. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16106. }
  16107. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16108. {
  16109. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16111. }
  16112. if(strcmp(keystr, "ResetRetries") == 0)
  16113. {
  16114. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16116. }
  16117. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16118. {
  16119. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16121. }
  16122. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16123. {
  16124. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16126. }
  16127. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16128. {
  16129. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16131. }
  16132. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16133. {
  16134. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16136. }
  16137. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16138. {
  16139. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16141. }
  16142. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16143. {
  16144. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16146. }
  16147. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16148. {
  16149. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16151. }
  16152. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16153. {
  16154. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16156. }
  16157. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16158. {
  16159. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16161. }
  16162. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16163. {
  16164. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16166. }
  16167. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16168. {
  16169. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16171. TransactionMessageAttemptsValue = atoi(valuestr);
  16172. }
  16173. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16174. {
  16175. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16177. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16178. }
  16179. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16180. {
  16181. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16183. }
  16184. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16185. {
  16186. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16188. }
  16189. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16190. {
  16191. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16193. }
  16194. if(strcmp(keystr, "AuthorizationKey") == 0)
  16195. {
  16196. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16197. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16199. }
  16200. if(strcmp(keystr, "SecurityProfile") == 0)
  16201. {
  16202. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16204. }
  16205. if(strcmp(keystr, "DefaultPrice") == 0)
  16206. {
  16207. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16209. }
  16210. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16211. {
  16212. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16214. }
  16215. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16216. {
  16217. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16219. }
  16220. if(strcmp(keystr, "TimeOffset") == 0)
  16221. {
  16222. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16224. }
  16225. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16226. {
  16227. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16229. }
  16230. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16231. {
  16232. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16234. }
  16235. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16236. {
  16237. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16239. }
  16240. if(strcmp(keystr, "FreeVend") == 0)
  16241. {
  16242. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16244. }
  16245. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16246. {
  16247. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16249. }
  16250. if(strcmp(keystr, "OcppServer") == 0)
  16251. {
  16252. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16253. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16254. }
  16255. if(strcmp(keystr, "MaintainServer") == 0)
  16256. {
  16257. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16258. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16259. }
  16260. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16261. {
  16262. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16264. }
  16265. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16266. {
  16267. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16269. }
  16270. if(strcmp(keystr, "PreAuthAmount") == 0)
  16271. {
  16272. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16274. }
  16275. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16276. {
  16277. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16279. }
  16280. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16281. {
  16282. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16283. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16284. }
  16285. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16286. {
  16287. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16289. }
  16290. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16291. {
  16292. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16294. }
  16295. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16296. {
  16297. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16299. }
  16300. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16301. {
  16302. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16304. }
  16305. if(strcmp(keystr, "CpoName") == 0)
  16306. {
  16307. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16309. }
  16310. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16311. {
  16312. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16314. }
  16315. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16316. {
  16317. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16319. }
  16320. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16321. {
  16322. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16324. }
  16325. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16326. {
  16327. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16329. }
  16330. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16331. {
  16332. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16334. }
  16335. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16336. {
  16337. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16339. }
  16340. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16341. {
  16342. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16344. }
  16345. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16346. {
  16347. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16349. }
  16350. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16351. {
  16352. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16354. }
  16355. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16356. {
  16357. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16359. }
  16360. }
  16361. }
  16362. fclose(fp);
  16363. }
  16364. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16365. {
  16366. return PASS;
  16367. }
  16368. else
  16369. {
  16370. return FAIL;
  16371. }
  16372. }
  16373. void StoreConfigurationTable(void)
  16374. {
  16375. FILE *outfile;
  16376. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16377. if(outfile == NULL)
  16378. {
  16379. DEBUG_INFO("Error opening file");
  16380. return ;
  16381. }
  16382. /*Core Profile*/
  16383. //AllowOfflineTxForUnknownId
  16384. /*
  16385. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16386. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16389. */
  16390. //DEBUG_INFO("data=%s\n",data);
  16391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16392. //AuthorizationCacheEnabled
  16393. /*
  16394. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16397. */
  16398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16399. //AuthorizeRemoteTxRequests
  16400. /*
  16401. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16404. */
  16405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16406. //BlinkRepeat
  16407. /*
  16408. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16411. */
  16412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16413. //ClockAlignedDataInterval
  16414. /*
  16415. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16418. */
  16419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16420. //ConnectionTimeOut
  16421. /*
  16422. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16425. */
  16426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16427. //GetConfigurationMaxKeys
  16428. /*
  16429. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16432. */
  16433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16434. // HeartbeatInterval
  16435. /*
  16436. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16439. */
  16440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16441. // LightIntensity
  16442. /*
  16443. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16446. */
  16447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16448. // LocalAuthorizeOffline
  16449. /*
  16450. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16453. */
  16454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16455. // LocalPreAuthorize
  16456. /*
  16457. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16460. */
  16461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16462. // MaxEnergyOnInvalidId
  16463. /*
  16464. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16467. */
  16468. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16470. // MeterValuesAlignedData
  16471. /*
  16472. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16475. */
  16476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16477. // MeterValuesAlignedDataMaxLength
  16478. /*
  16479. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16482. */
  16483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16484. // MeterValuesSampledData
  16485. /*
  16486. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16489. */
  16490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16491. // MeterValuesSampledDataMaxLength
  16492. /*
  16493. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16496. */
  16497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16498. // MeterValueSampleInterval
  16499. /*
  16500. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16503. */
  16504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16505. // MinimumStatusDuration
  16506. /*
  16507. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16510. */
  16511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16512. // NumberOfConnectors
  16513. /*
  16514. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16517. {
  16518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16519. }
  16520. else
  16521. {
  16522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16523. }
  16524. */
  16525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16526. // ResetRetries
  16527. /*
  16528. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16531. */
  16532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16533. // ConnectorPhaseRotation
  16534. /*
  16535. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16538. */
  16539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16540. // ConnectorPhaseRotationMaxLength
  16541. /*
  16542. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16545. */
  16546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16547. // StopTransactionOnEVSideDisconnect
  16548. /*
  16549. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16552. */
  16553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16554. // StopTransactionOnInvalidId
  16555. /*
  16556. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16559. */
  16560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16561. // StopTxnAlignedData
  16562. /*
  16563. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16566. */
  16567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16568. // StopTxnAlignedDataMaxLength
  16569. /*
  16570. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16573. */
  16574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16575. // StopTxnSampledData
  16576. /*
  16577. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16580. */
  16581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16582. // StopTxnSampledDataMaxLength
  16583. /*
  16584. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16587. */
  16588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16589. // SupportedFeatureProfiles
  16590. /*
  16591. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16594. */
  16595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16596. // SupportedFeatureProfilesMaxLength
  16597. /*
  16598. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16601. */
  16602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16603. // TransactionMessageAttempts
  16604. /*
  16605. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16608. */
  16609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16610. // TransactionMessageRetryInterval
  16611. /*
  16612. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16615. */
  16616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16617. // UnlockConnectorOnEVSideDisconnect
  16618. /*
  16619. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16622. */
  16623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16624. // WebSocketPingInterval
  16625. /*
  16626. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16629. */
  16630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16631. // QueueOffLineMeterValues
  16632. /*
  16633. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16636. */
  16637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16638. // AuthorizationKey
  16639. /*
  16640. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16643. */
  16644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16645. // SecurityProfile
  16646. /*
  16647. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16650. */
  16651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16652. // DefaultPrice
  16653. /*
  16654. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16657. */
  16658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16659. // CustomDisplayCostAndPrice
  16660. /*
  16661. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16664. */
  16665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16666. // CustomIdleFeeAfterStop
  16667. /*
  16668. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16671. */
  16672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16673. // TimeOffset
  16674. /*
  16675. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16678. */
  16679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16680. // NextTimeOffsetTransitionDateTime
  16681. /*
  16682. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16685. */
  16686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16687. // TimeOffsetNextTransition
  16688. /*
  16689. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16692. */
  16693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16694. // SystemUptimeSec
  16695. /*
  16696. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16699. */
  16700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16701. // FreeVend
  16702. /*
  16703. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16706. */
  16707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16708. // FreeVendIdtag
  16709. /*
  16710. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16713. */
  16714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16715. // OcppServer
  16716. /*
  16717. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16720. */
  16721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16722. // MaintainServer
  16723. /*
  16724. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16727. */
  16728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16729. // StatusNotificationPeriodically
  16730. /*
  16731. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16734. */
  16735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16736. // StatusNotificationInterval
  16737. /*
  16738. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16741. */
  16742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16743. // PreAuthAmount
  16744. /*
  16745. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16748. */
  16749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16750. // isEnableLocalPowerSharing
  16751. /*
  16752. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16755. */
  16756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16757. // PowerSharingServerIP
  16758. /*
  16759. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16762. */
  16763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16764. // EVCCID_PREFIX
  16765. /*
  16766. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16769. */
  16770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16771. // OffLineMaxChargingPower
  16772. /*
  16773. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16776. */
  16777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16778. // ConfigurationVersion
  16779. /*
  16780. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16783. */
  16784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16785. // CharingProfileRefreshInterval
  16786. /*
  16787. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16790. */
  16791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16792. // CpoName
  16793. /*
  16794. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16797. */
  16798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16799. // OcppSoftwareVersion
  16800. /*
  16801. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16804. */
  16805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16806. //* Local Auth List Management Profile*/
  16807. //LocalAuthListEnabled
  16808. /*
  16809. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16812. */
  16813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16814. //LocalAuthListMaxLength
  16815. /*
  16816. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16819. */
  16820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16821. //SendLocalListMaxLength
  16822. /*
  16823. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16826. */
  16827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16828. //ReserveConnectorZeroSupported
  16829. /*
  16830. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16833. */
  16834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16835. //* Smart Charging Profile */
  16836. //ChargeProfileMaxStackLevel
  16837. /*
  16838. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16841. */
  16842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16843. // ChargingScheduleAllowedChargingRateUnit
  16844. /*
  16845. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16848. */
  16849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16850. // ChargingScheduleMaxPeriods
  16851. /*
  16852. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16855. */
  16856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16857. // ConnectorSwitch3to1PhaseSupported
  16858. /*
  16859. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16862. */
  16863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16864. // MaxChargingProfilesInstalled
  16865. /*
  16866. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16869. */
  16870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16871. fclose(outfile);
  16872. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16873. }
  16874. void getKeyValue(char *keyReq)
  16875. {
  16876. int isEmpty = FALSE;
  16877. int isKnowKey = FALSE;
  16878. DEBUG_INFO("keyReq = %s\n", keyReq);
  16879. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16880. isEmpty = TRUE;
  16881. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16882. {
  16883. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16885. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16886. {
  16887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16888. }
  16889. else
  16890. {
  16891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16892. }
  16893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16894. isKnowKey = TRUE;
  16895. }
  16896. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16897. {
  16898. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16900. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16901. {
  16902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16903. }
  16904. else
  16905. {
  16906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16907. }
  16908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16909. isKnowKey = TRUE;
  16910. }
  16911. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16912. {
  16913. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16916. {
  16917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16918. }
  16919. else
  16920. {
  16921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16922. }
  16923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16924. isKnowKey = TRUE;
  16925. }
  16926. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16927. {
  16928. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16930. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16931. {
  16932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16933. }
  16934. else
  16935. {
  16936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16937. }
  16938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16939. isKnowKey = TRUE;
  16940. }
  16941. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16942. {
  16943. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16946. {
  16947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16948. }
  16949. else
  16950. {
  16951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16952. }
  16953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16954. isKnowKey = TRUE;
  16955. }
  16956. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16957. {
  16958. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16961. {
  16962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  16963. }
  16964. else
  16965. {
  16966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  16967. }
  16968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  16969. isKnowKey = TRUE;
  16970. }
  16971. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  16972. {
  16973. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  16974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  16975. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16976. {
  16977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  16978. }
  16979. else
  16980. {
  16981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  16982. }
  16983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  16984. isKnowKey = TRUE;
  16985. }
  16986. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  16987. {
  16988. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  16989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  16990. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16991. {
  16992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  16993. }
  16994. else
  16995. {
  16996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  16997. }
  16998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  16999. isKnowKey = TRUE;
  17000. }
  17001. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  17002. {
  17003. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  17004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  17005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17006. {
  17007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  17008. }
  17009. else
  17010. {
  17011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  17012. }
  17013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  17014. isKnowKey = TRUE;
  17015. }
  17016. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  17017. {
  17018. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  17019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  17020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17021. {
  17022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  17023. }
  17024. else
  17025. {
  17026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  17027. }
  17028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  17029. isKnowKey = TRUE;
  17030. }
  17031. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  17032. {
  17033. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  17034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  17035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17036. {
  17037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  17038. }
  17039. else
  17040. {
  17041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17042. }
  17043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17044. isKnowKey = TRUE;
  17045. }
  17046. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17047. {
  17048. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17050. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17051. {
  17052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17053. }
  17054. else
  17055. {
  17056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17057. }
  17058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17059. isKnowKey = TRUE;
  17060. }
  17061. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17062. {
  17063. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17066. {
  17067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17068. }
  17069. else
  17070. {
  17071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17072. }
  17073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17074. isKnowKey = TRUE;
  17075. }
  17076. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17077. {
  17078. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17081. {
  17082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17083. }
  17084. else
  17085. {
  17086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17087. }
  17088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17089. isKnowKey = TRUE;
  17090. }
  17091. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17092. {
  17093. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17096. {
  17097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17098. }
  17099. else
  17100. {
  17101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17102. }
  17103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17104. isKnowKey = TRUE;
  17105. }
  17106. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17107. {
  17108. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17111. {
  17112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17113. }
  17114. else
  17115. {
  17116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17117. }
  17118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17119. isKnowKey = TRUE;
  17120. }
  17121. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17122. {
  17123. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17126. {
  17127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17128. }
  17129. else
  17130. {
  17131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17132. }
  17133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17134. isKnowKey = TRUE;
  17135. }
  17136. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17137. {
  17138. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17141. {
  17142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17143. }
  17144. else
  17145. {
  17146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17147. }
  17148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17149. isKnowKey = TRUE;
  17150. }
  17151. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17152. {
  17153. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17156. {
  17157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17158. }
  17159. else
  17160. {
  17161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17162. }
  17163. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17165. isKnowKey = TRUE;
  17166. }
  17167. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17168. {
  17169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17172. {
  17173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17174. }
  17175. else
  17176. {
  17177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17178. }
  17179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17180. isKnowKey = TRUE;
  17181. }
  17182. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17183. {
  17184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17187. {
  17188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17189. }
  17190. else
  17191. {
  17192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17193. }
  17194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17195. isKnowKey = TRUE;
  17196. }
  17197. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17198. {
  17199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17202. {
  17203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17204. }
  17205. else
  17206. {
  17207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17208. }
  17209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17210. isKnowKey = TRUE;
  17211. }
  17212. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17213. {
  17214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17217. {
  17218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17219. }
  17220. else
  17221. {
  17222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17223. }
  17224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17225. isKnowKey = TRUE;
  17226. }
  17227. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17228. {
  17229. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17232. {
  17233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17234. }
  17235. else
  17236. {
  17237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17238. }
  17239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17240. isKnowKey = TRUE;
  17241. }
  17242. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17243. {
  17244. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17247. {
  17248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17249. }
  17250. else
  17251. {
  17252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17253. }
  17254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17255. isKnowKey = TRUE;
  17256. }
  17257. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17258. {
  17259. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17262. {
  17263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17264. }
  17265. else
  17266. {
  17267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17268. }
  17269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17270. isKnowKey = TRUE;
  17271. }
  17272. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17273. {
  17274. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17277. {
  17278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17279. }
  17280. else
  17281. {
  17282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17283. }
  17284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17285. isKnowKey = TRUE;
  17286. }
  17287. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17288. {
  17289. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17292. {
  17293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17294. }
  17295. else
  17296. {
  17297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17298. }
  17299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17300. isKnowKey = TRUE;
  17301. }
  17302. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17303. {
  17304. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17307. {
  17308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17309. }
  17310. else
  17311. {
  17312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17313. }
  17314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17315. isKnowKey = TRUE;
  17316. }
  17317. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17318. {
  17319. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17322. {
  17323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17324. }
  17325. else
  17326. {
  17327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17328. }
  17329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17330. isKnowKey = TRUE;
  17331. }
  17332. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17333. {
  17334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17337. {
  17338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17339. }
  17340. else
  17341. {
  17342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17343. }
  17344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17345. isKnowKey = TRUE;
  17346. }
  17347. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17348. {
  17349. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17352. {
  17353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17354. }
  17355. else
  17356. {
  17357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17358. }
  17359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17360. isKnowKey = TRUE;
  17361. }
  17362. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17363. {
  17364. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17367. {
  17368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17369. }
  17370. else
  17371. {
  17372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17373. }
  17374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17375. isKnowKey = TRUE;
  17376. }
  17377. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17378. {
  17379. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17382. {
  17383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17384. }
  17385. else
  17386. {
  17387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17388. }
  17389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17390. isKnowKey = TRUE;
  17391. }
  17392. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17393. {
  17394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17397. {
  17398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17399. }
  17400. else
  17401. {
  17402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17403. }
  17404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17405. isKnowKey = TRUE;
  17406. }
  17407. /*
  17408. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17409. {
  17410. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17413. {
  17414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17415. }
  17416. else
  17417. {
  17418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17419. }
  17420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17421. isKnowKey = TRUE;
  17422. }*/
  17423. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17424. {
  17425. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17428. {
  17429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17430. }
  17431. else
  17432. {
  17433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17434. }
  17435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17436. isKnowKey = TRUE;
  17437. }
  17438. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17439. {
  17440. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17443. {
  17444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17445. }
  17446. else
  17447. {
  17448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17449. }
  17450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17451. isKnowKey = TRUE;
  17452. }
  17453. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17454. {
  17455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17458. {
  17459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17460. }
  17461. else
  17462. {
  17463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17464. }
  17465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17466. isKnowKey = TRUE;
  17467. }
  17468. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17469. {
  17470. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17473. {
  17474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17475. }
  17476. else
  17477. {
  17478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17479. }
  17480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17481. isKnowKey = TRUE;
  17482. }
  17483. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17484. {
  17485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17488. {
  17489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17490. }
  17491. else
  17492. {
  17493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17494. }
  17495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17496. isKnowKey = TRUE;
  17497. }
  17498. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17499. {
  17500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17503. {
  17504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17505. }
  17506. else
  17507. {
  17508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17509. }
  17510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17511. isKnowKey = TRUE;
  17512. }
  17513. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17514. {
  17515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17518. {
  17519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17520. }
  17521. else
  17522. {
  17523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17524. }
  17525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17526. isKnowKey = TRUE;
  17527. }
  17528. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17529. {
  17530. struct sysinfo s_info;
  17531. int error = sysinfo(&s_info);
  17532. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17534. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17535. {
  17536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17537. }
  17538. else
  17539. {
  17540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17541. }
  17542. if(error != 0)
  17543. {
  17544. DEBUG_WARN("System uptime get error: %d\n", error);
  17545. }
  17546. else
  17547. {
  17548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17549. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17550. }
  17551. isKnowKey = TRUE;
  17552. }
  17553. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17554. {
  17555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17558. {
  17559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17560. }
  17561. else
  17562. {
  17563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17564. }
  17565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17566. isKnowKey = TRUE;
  17567. }
  17568. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17569. {
  17570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17573. {
  17574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17575. }
  17576. else
  17577. {
  17578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17579. }
  17580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17581. isKnowKey = TRUE;
  17582. }
  17583. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17584. {
  17585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17588. {
  17589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17590. }
  17591. else
  17592. {
  17593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17594. }
  17595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17596. isKnowKey = TRUE;
  17597. }
  17598. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17599. {
  17600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17603. {
  17604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17605. }
  17606. else
  17607. {
  17608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17609. }
  17610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17611. isKnowKey = TRUE;
  17612. }
  17613. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17614. {
  17615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17618. {
  17619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17620. }
  17621. else
  17622. {
  17623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17624. }
  17625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17626. isKnowKey = TRUE;
  17627. }
  17628. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17629. {
  17630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17633. {
  17634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17635. }
  17636. else
  17637. {
  17638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17639. }
  17640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17641. isKnowKey = TRUE;
  17642. }
  17643. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17644. {
  17645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17648. {
  17649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17650. }
  17651. else
  17652. {
  17653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17654. }
  17655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17656. isKnowKey = TRUE;
  17657. }
  17658. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17659. {
  17660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17663. {
  17664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17665. }
  17666. else
  17667. {
  17668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17669. }
  17670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17671. isKnowKey = TRUE;
  17672. }
  17673. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17674. {
  17675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17678. {
  17679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17680. }
  17681. else
  17682. {
  17683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17684. }
  17685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17686. isKnowKey = TRUE;
  17687. }
  17688. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17689. {
  17690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17693. {
  17694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17695. }
  17696. else
  17697. {
  17698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17699. }
  17700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17701. isKnowKey = TRUE;
  17702. }
  17703. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17704. {
  17705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17708. {
  17709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17710. }
  17711. else
  17712. {
  17713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17714. }
  17715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17716. isKnowKey = TRUE;
  17717. }
  17718. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17719. {
  17720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17723. {
  17724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17725. }
  17726. else
  17727. {
  17728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17729. }
  17730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17731. isKnowKey = TRUE;
  17732. }
  17733. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17734. {
  17735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17738. {
  17739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17740. }
  17741. else
  17742. {
  17743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17744. }
  17745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17746. isKnowKey = TRUE;
  17747. }
  17748. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17749. {
  17750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17753. {
  17754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17755. }
  17756. else
  17757. {
  17758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17759. }
  17760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17761. isKnowKey = TRUE;
  17762. }
  17763. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17764. {
  17765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17768. {
  17769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17770. }
  17771. else
  17772. {
  17773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17774. }
  17775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17776. isKnowKey = TRUE;
  17777. }
  17778. #if 1
  17779. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17780. {
  17781. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17783. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17784. {
  17785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17786. }
  17787. else
  17788. {
  17789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17790. }
  17791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17792. isKnowKey = TRUE;
  17793. }
  17794. #endif
  17795. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17796. {
  17797. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17799. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17800. {
  17801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17802. }
  17803. else
  17804. {
  17805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17806. }
  17807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17808. isKnowKey = TRUE;
  17809. }
  17810. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17811. {
  17812. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17814. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17815. {
  17816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17817. }
  17818. else
  17819. {
  17820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17821. }
  17822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17823. isKnowKey = TRUE;
  17824. }
  17825. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17826. {
  17827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17829. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17830. {
  17831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17832. }
  17833. else
  17834. {
  17835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17836. }
  17837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17838. isKnowKey = TRUE;
  17839. }
  17840. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17841. {
  17842. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17844. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17845. {
  17846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17847. }
  17848. else
  17849. {
  17850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17851. }
  17852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17853. isKnowKey = TRUE;
  17854. }
  17855. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17856. {
  17857. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17859. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17860. {
  17861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17862. }
  17863. else
  17864. {
  17865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17866. }
  17867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17868. isKnowKey = TRUE;
  17869. }
  17870. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17871. {
  17872. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17874. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17875. {
  17876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17877. }
  17878. else
  17879. {
  17880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17881. }
  17882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17883. isKnowKey = TRUE;
  17884. }
  17885. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17886. {
  17887. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17889. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17890. {
  17891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17892. }
  17893. else
  17894. {
  17895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17896. }
  17897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17898. isKnowKey = TRUE;
  17899. }
  17900. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17901. {
  17902. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17904. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17905. {
  17906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17907. }
  17908. else
  17909. {
  17910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17911. }
  17912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17913. isKnowKey = TRUE;
  17914. }
  17915. //=========================================================
  17916. if(!isEmpty && !isKnowKey)
  17917. {
  17918. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17919. strcpy(unknownkey[UnknownKeynum], keyReq);
  17920. UnknownKeynum = UnknownKeynum + 1;
  17921. }
  17922. }
  17923. void processUnkownKey(void)
  17924. {
  17925. DEBUG_INFO("processUnkownKey...\n");
  17926. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17927. for(int index=0; index < UnknownKeynum; index++)
  17928. {
  17929. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17930. {
  17931. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17932. }
  17933. }
  17934. }
  17935. int setKeyValue(char *key, char *value)
  17936. {
  17937. int isSuccess = NotSupported;
  17938. int check_ascii=0;
  17939. char str[501]={0};
  17940. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17941. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17942. {
  17943. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17945. {
  17946. strcpy(str, (const char*)value);
  17947. for(int i = 0; str[i]; i++){
  17948. str[i] = tolower(str[i]);
  17949. }
  17950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17951. isSuccess = ConfigurationStatus_Accepted;
  17952. }
  17953. else
  17954. {
  17955. isSuccess = ConfigurationStatus_Rejected;
  17956. }
  17957. }
  17958. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  17959. {
  17960. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  17961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17962. {
  17963. strcpy(str, (const char*)value);
  17964. for(int i = 0; str[i]; i++){
  17965. str[i] = tolower(str[i]);
  17966. }
  17967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17968. isSuccess = ConfigurationStatus_Accepted;
  17969. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  17970. }
  17971. else
  17972. {
  17973. isSuccess = ConfigurationStatus_Rejected;
  17974. }
  17975. }
  17976. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  17977. {
  17978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17979. {
  17980. strcpy(str, (const char*)value);
  17981. for(int i = 0; str[i]; i++)
  17982. {
  17983. str[i] = tolower(str[i]);
  17984. }
  17985. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  17986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17987. isSuccess = ConfigurationStatus_Accepted;
  17988. }
  17989. else
  17990. {
  17991. isSuccess = ConfigurationStatus_Rejected;
  17992. }
  17993. }
  17994. if(strcmp(key, "BlinkRepeat") == 0)
  17995. {
  17996. //Charger.BlinkRepeat = Integer.parseInt(value);
  17997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17998. {
  17999. check_ascii = value[0];
  18000. if( (check_ascii < 48) || (check_ascii > 57) )
  18001. {
  18002. isSuccess = ConfigurationStatus_Rejected;
  18003. }
  18004. else
  18005. {
  18006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  18007. isSuccess = ConfigurationStatus_Accepted;
  18008. }
  18009. }
  18010. else
  18011. {
  18012. isSuccess = ConfigurationStatus_Rejected;
  18013. }
  18014. }
  18015. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  18016. {
  18017. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  18018. {
  18019. check_ascii = value[0];
  18020. if( (check_ascii < 48) || (check_ascii > 57) )
  18021. {
  18022. isSuccess = ConfigurationStatus_Rejected;
  18023. }
  18024. else
  18025. {
  18026. if((atoi(value) == 0) || (atoi(value) >= 5))
  18027. {
  18028. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  18030. isSuccess = ConfigurationStatus_Accepted;
  18031. }
  18032. else
  18033. isSuccess = ConfigurationStatus_Rejected;
  18034. }
  18035. }
  18036. else
  18037. {
  18038. isSuccess = ConfigurationStatus_Rejected;
  18039. }
  18040. }
  18041. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18042. {
  18043. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18044. {
  18045. check_ascii = value[0];
  18046. if( (check_ascii < 48) || (check_ascii > 57) )
  18047. {
  18048. isSuccess = ConfigurationStatus_Rejected;
  18049. }
  18050. else
  18051. {
  18052. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18054. isSuccess = ConfigurationStatus_Accepted;
  18055. }
  18056. }
  18057. else
  18058. {
  18059. isSuccess = ConfigurationStatus_Rejected;
  18060. }
  18061. }
  18062. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18063. {
  18064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].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.HeartbeatInterval = Integer.parseInt(value)*1000;
  18074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18075. isSuccess = ConfigurationStatus_Accepted;
  18076. }
  18077. }
  18078. else
  18079. {
  18080. isSuccess = ConfigurationStatus_Rejected;
  18081. }
  18082. }
  18083. if(strcmp(key, "HeartbeatInterval") == 0)
  18084. {
  18085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18086. {
  18087. check_ascii = value[0];
  18088. if( (check_ascii < 48) || (check_ascii > 57) )
  18089. {
  18090. isSuccess = ConfigurationStatus_Rejected;
  18091. }
  18092. else
  18093. {
  18094. if((atoi(value) == 0) || (atoi(value) >= 10))
  18095. {
  18096. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18098. HeartBeatWaitTime = atoi(value);
  18099. isSuccess = ConfigurationStatus_Accepted;
  18100. }
  18101. else
  18102. {
  18103. isSuccess = ConfigurationStatus_Rejected;
  18104. }
  18105. }
  18106. }
  18107. else
  18108. {
  18109. isSuccess = ConfigurationStatus_Rejected;
  18110. }
  18111. }
  18112. if(strcmp(key, "LightIntensity") == 0)
  18113. {
  18114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18115. {
  18116. check_ascii = value[0];
  18117. if( (check_ascii < 48) || (check_ascii > 57) )
  18118. {
  18119. isSuccess = ConfigurationStatus_Rejected;
  18120. }
  18121. else
  18122. {
  18123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18124. isSuccess = ConfigurationStatus_Accepted;
  18125. }
  18126. }
  18127. else
  18128. {
  18129. isSuccess = ConfigurationStatus_Rejected;
  18130. }
  18131. }
  18132. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18133. {
  18134. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18135. {
  18136. strcpy(str, (const char*)value);
  18137. for(int i = 0; str[i]; i++)
  18138. {
  18139. str[i] = tolower(str[i]);
  18140. }
  18141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18142. isSuccess = ConfigurationStatus_Accepted;
  18143. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18144. }
  18145. else
  18146. {
  18147. isSuccess = ConfigurationStatus_Rejected;
  18148. }
  18149. }
  18150. if(strcmp(key, "LocalPreAuthorize") == 0)
  18151. {
  18152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18153. {
  18154. strcpy(str, (const char*)value);
  18155. for(int i = 0; str[i]; i++)
  18156. {
  18157. str[i] = tolower(str[i]);
  18158. }
  18159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18160. isSuccess = ConfigurationStatus_Accepted;
  18161. }
  18162. else
  18163. {
  18164. isSuccess = ConfigurationStatus_Rejected;
  18165. }
  18166. }
  18167. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18168. {
  18169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18170. {
  18171. check_ascii = value[0];
  18172. if( (check_ascii < 48) || (check_ascii > 57) )
  18173. {
  18174. isSuccess = ConfigurationStatus_Rejected;
  18175. }
  18176. else
  18177. {
  18178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18179. isSuccess = ConfigurationStatus_Accepted;
  18180. }
  18181. }
  18182. else
  18183. {
  18184. isSuccess = ConfigurationStatus_Rejected;
  18185. }
  18186. }
  18187. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18188. {
  18189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18190. {
  18191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18192. isSuccess = ConfigurationStatus_Accepted;
  18193. }
  18194. else
  18195. {
  18196. isSuccess = ConfigurationStatus_Rejected;
  18197. }
  18198. }
  18199. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18200. {
  18201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18202. {
  18203. check_ascii = value[0];
  18204. if( (check_ascii < 48) || (check_ascii > 57) )
  18205. {
  18206. isSuccess = ConfigurationStatus_Rejected;
  18207. }
  18208. else
  18209. {
  18210. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18212. isSuccess = ConfigurationStatus_Accepted;
  18213. }
  18214. }
  18215. else
  18216. {
  18217. isSuccess = ConfigurationStatus_Rejected;
  18218. }
  18219. }
  18220. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18221. {
  18222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18223. {
  18224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18225. isSuccess = ConfigurationStatus_Accepted;
  18226. }
  18227. else
  18228. {
  18229. isSuccess = ConfigurationStatus_Rejected;
  18230. }
  18231. }
  18232. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18233. {
  18234. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18235. {
  18236. check_ascii = value[0];
  18237. if( (check_ascii < 48) || (check_ascii > 57) )
  18238. {
  18239. isSuccess = ConfigurationStatus_Rejected;
  18240. }
  18241. else
  18242. {
  18243. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18245. isSuccess = ConfigurationStatus_Accepted;
  18246. }
  18247. }
  18248. else
  18249. {
  18250. isSuccess = ConfigurationStatus_Rejected;
  18251. }
  18252. }
  18253. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18254. {
  18255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18256. {
  18257. check_ascii = value[0];
  18258. if( (check_ascii < 48) || (check_ascii > 57) )
  18259. {
  18260. isSuccess = ConfigurationStatus_Rejected;
  18261. }
  18262. else
  18263. {
  18264. if((atoi(value) == 0) || (atoi(value) >= 3))
  18265. {
  18266. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18268. isSuccess = ConfigurationStatus_Accepted;
  18269. }
  18270. else
  18271. {
  18272. isSuccess = ConfigurationStatus_Rejected;
  18273. }
  18274. }
  18275. }
  18276. else
  18277. {
  18278. isSuccess = ConfigurationStatus_Rejected;
  18279. }
  18280. }
  18281. if(strcmp(key, "MinimumStatusDuration") == 0)
  18282. {
  18283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18284. {
  18285. check_ascii = value[0];
  18286. if( (check_ascii < 48) || (check_ascii > 57) )
  18287. {
  18288. isSuccess = ConfigurationStatus_Rejected;
  18289. }
  18290. else
  18291. {
  18292. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18293. {
  18294. isSuccess = ConfigurationStatus_Rejected;
  18295. }
  18296. else
  18297. {
  18298. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18300. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18301. isSuccess = ConfigurationStatus_Accepted;
  18302. }
  18303. }
  18304. }
  18305. else
  18306. {
  18307. isSuccess = ConfigurationStatus_Rejected;
  18308. }
  18309. }
  18310. if(strcmp(key, "NumberOfConnectors") == 0)
  18311. {
  18312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18313. {
  18314. check_ascii = value[0];
  18315. if( (check_ascii < 48) || (check_ascii > 57) )
  18316. {
  18317. isSuccess = ConfigurationStatus_Rejected;
  18318. }
  18319. else
  18320. {
  18321. //Charger.ResetRetries = Integer.parseInt(value);
  18322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18323. isSuccess = ConfigurationStatus_Accepted;
  18324. }
  18325. }
  18326. else
  18327. {
  18328. isSuccess = ConfigurationStatus_Rejected;
  18329. }
  18330. }
  18331. if(strcmp(key, "ResetRetries") == 0)
  18332. {
  18333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18334. {
  18335. check_ascii = value[0];
  18336. if( (check_ascii < 48) || (check_ascii > 57) )
  18337. {
  18338. isSuccess = ConfigurationStatus_Rejected;
  18339. }
  18340. else
  18341. {
  18342. //Charger.ResetRetries = Integer.parseInt(value);
  18343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18344. isSuccess = ConfigurationStatus_Accepted;
  18345. }
  18346. }
  18347. else
  18348. {
  18349. isSuccess = ConfigurationStatus_Rejected;
  18350. }
  18351. }
  18352. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18353. {
  18354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18355. {
  18356. strcpy(str, (const char*)value);
  18357. for(int i = 0; str[i]; i++)
  18358. {
  18359. str[i] = tolower(str[i]);
  18360. }
  18361. if(strcmp(str, "notapplicable")== 0)
  18362. {
  18363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18364. isSuccess = ConfigurationStatus_Accepted;
  18365. }
  18366. else if(strcmp(str, "unknown")== 0)
  18367. {
  18368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18369. isSuccess = ConfigurationStatus_Accepted;
  18370. }
  18371. else if(strcmp(str, "rst")== 0)
  18372. {
  18373. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18374. isSuccess = ConfigurationStatus_Accepted;
  18375. }
  18376. else if(strcmp(str, "rts")== 0)
  18377. {
  18378. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18379. isSuccess = ConfigurationStatus_Accepted;
  18380. }
  18381. else if(strcmp(str, "srt")== 0)
  18382. {
  18383. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18384. isSuccess = ConfigurationStatus_Accepted;
  18385. }
  18386. else if(strcmp(str, "str")== 0)
  18387. {
  18388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18389. isSuccess = ConfigurationStatus_Accepted;
  18390. }
  18391. else if(strcmp(str, "trs")== 0)
  18392. {
  18393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18394. isSuccess = ConfigurationStatus_Accepted;
  18395. }
  18396. else if(strcmp(str, "tsr")== 0)
  18397. {
  18398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18399. isSuccess = ConfigurationStatus_Accepted;
  18400. }
  18401. else
  18402. {
  18403. isSuccess = ConfigurationStatus_Rejected;
  18404. }
  18405. }
  18406. else
  18407. {
  18408. isSuccess = ConfigurationStatus_Rejected;
  18409. }
  18410. }
  18411. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18412. {
  18413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18414. {
  18415. check_ascii = value[0];
  18416. if( (check_ascii < 48) || (check_ascii > 57) )
  18417. {
  18418. isSuccess = ConfigurationStatus_Rejected;
  18419. }
  18420. else
  18421. {
  18422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18423. isSuccess = ConfigurationStatus_Accepted;
  18424. }
  18425. }
  18426. else
  18427. {
  18428. isSuccess = ConfigurationStatus_Rejected;
  18429. }
  18430. }
  18431. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18432. {
  18433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18434. {
  18435. strcpy(str, (const char*)value);
  18436. for(int i = 0; str[i]; i++)
  18437. {
  18438. str[i] = tolower(str[i]);
  18439. }
  18440. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18442. isSuccess = ConfigurationStatus_Accepted;
  18443. }
  18444. else
  18445. {
  18446. isSuccess = ConfigurationStatus_Rejected;
  18447. }
  18448. }
  18449. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18450. {
  18451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18452. {
  18453. strcpy(str, (const char*)value);
  18454. for(int i = 0; str[i]; i++)
  18455. {
  18456. str[i] = tolower(str[i]);
  18457. }
  18458. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18460. isSuccess = ConfigurationStatus_Accepted;
  18461. }
  18462. else
  18463. {
  18464. isSuccess = ConfigurationStatus_Rejected;
  18465. }
  18466. }
  18467. if(strcmp(key, "StopTxnAlignedData") == 0)
  18468. {
  18469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18470. {
  18471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18472. isSuccess = ConfigurationStatus_Accepted;
  18473. }
  18474. else
  18475. {
  18476. isSuccess = ConfigurationStatus_Rejected;
  18477. }
  18478. }
  18479. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18480. {
  18481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18482. {
  18483. check_ascii = value[0];
  18484. if( (check_ascii < 48) || (check_ascii > 57) )
  18485. {
  18486. isSuccess = ConfigurationStatus_Rejected;
  18487. }
  18488. else
  18489. {
  18490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18491. isSuccess = ConfigurationStatus_Accepted;
  18492. }
  18493. }
  18494. else
  18495. {
  18496. isSuccess = ConfigurationStatus_Rejected;
  18497. }
  18498. }
  18499. if(strcmp(key, "StopTxnSampledData") == 0)
  18500. {
  18501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18502. {
  18503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18504. isSuccess = ConfigurationStatus_Accepted;
  18505. }
  18506. else
  18507. {
  18508. isSuccess = ConfigurationStatus_Rejected;
  18509. }
  18510. }
  18511. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18512. {
  18513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18514. {
  18515. check_ascii = value[0];
  18516. if( (check_ascii < 48) || (check_ascii > 57) )
  18517. {
  18518. isSuccess = ConfigurationStatus_Rejected;
  18519. }
  18520. else
  18521. {
  18522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18523. isSuccess = ConfigurationStatus_Accepted;
  18524. }
  18525. }
  18526. else
  18527. {
  18528. isSuccess = ConfigurationStatus_Rejected;
  18529. }
  18530. }
  18531. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18532. {
  18533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18534. {
  18535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18536. isSuccess = ConfigurationStatus_Accepted;
  18537. }
  18538. else
  18539. {
  18540. isSuccess = ConfigurationStatus_Rejected;
  18541. }
  18542. }
  18543. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18544. {
  18545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18546. {
  18547. check_ascii = value[0];
  18548. if( (check_ascii < 48) || (check_ascii > 57) )
  18549. {
  18550. isSuccess = ConfigurationStatus_Rejected;
  18551. }
  18552. else
  18553. {
  18554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18555. isSuccess = ConfigurationStatus_Accepted;
  18556. }
  18557. }
  18558. else
  18559. {
  18560. isSuccess = ConfigurationStatus_Rejected;
  18561. }
  18562. }
  18563. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18564. {
  18565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18566. {
  18567. check_ascii = value[0];
  18568. if( (check_ascii < 48) || (check_ascii > 57) )
  18569. {
  18570. isSuccess = ConfigurationStatus_Rejected;
  18571. }
  18572. else
  18573. {
  18574. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18576. TransactionMessageAttemptsValue = atoi(value);
  18577. isSuccess = ConfigurationStatus_Accepted;
  18578. }
  18579. }
  18580. else
  18581. {
  18582. isSuccess = ConfigurationStatus_Rejected;
  18583. }
  18584. }
  18585. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18586. {
  18587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18588. {
  18589. check_ascii = value[0];
  18590. if( (check_ascii < 48) || (check_ascii > 57) )
  18591. {
  18592. isSuccess = ConfigurationStatus_Rejected;
  18593. }
  18594. else
  18595. {
  18596. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18598. TransactionMessageRetryIntervalValue = atoi(value);
  18599. isSuccess = ConfigurationStatus_Accepted;
  18600. }
  18601. }
  18602. else
  18603. {
  18604. isSuccess = ConfigurationStatus_Rejected;
  18605. }
  18606. }
  18607. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18608. {
  18609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].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. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18618. isSuccess = ConfigurationStatus_Accepted;
  18619. }
  18620. else
  18621. {
  18622. isSuccess = ConfigurationStatus_Rejected;
  18623. }
  18624. }
  18625. if(strcmp(key, "WebSocketPingInterval") == 0)
  18626. {
  18627. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18628. {
  18629. check_ascii = value[0];
  18630. if( (check_ascii < 48) || (check_ascii > 57) )
  18631. {
  18632. isSuccess = ConfigurationStatus_Rejected;
  18633. }
  18634. else
  18635. {
  18636. if((atoi(value) == 0) || (atoi(value) >= 10))
  18637. {
  18638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18639. isSuccess = ConfigurationStatus_Accepted;
  18640. }
  18641. else
  18642. isSuccess = ConfigurationStatus_Rejected;
  18643. }
  18644. }
  18645. else
  18646. {
  18647. isSuccess = ConfigurationStatus_Rejected;
  18648. }
  18649. }
  18650. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18651. {
  18652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18653. {
  18654. strcpy(str, (const char*)value);
  18655. for(int i = 0; str[i]; i++)
  18656. {
  18657. str[i] = tolower(str[i]);
  18658. }
  18659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18660. isSuccess = ConfigurationStatus_Accepted;
  18661. }
  18662. else
  18663. {
  18664. isSuccess = ConfigurationStatus_Rejected;
  18665. }
  18666. }
  18667. if(strcmp(key, "AuthorizationKey") == 0)
  18668. {
  18669. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18670. {
  18671. strcpy(str, (const char*)value);
  18672. int strlength = strlen(str);
  18673. char capture[3];
  18674. char stackItem = 0;
  18675. char password[21] = {0};
  18676. printf("String length: %d\n", strlength);
  18677. for(int idx=0; idx<(strlength/2); idx++)
  18678. {
  18679. capture[0] = str[(idx*2)];
  18680. capture[1] = str[(idx*2)+1];
  18681. capture[2] = 0;
  18682. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18683. sprintf(password,"%s%c", password, stackItem);
  18684. }
  18685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  18686. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18687. isSuccess = ConfigurationStatus_Accepted;
  18688. }
  18689. else
  18690. {
  18691. isSuccess = ConfigurationStatus_Rejected;
  18692. }
  18693. }
  18694. if(strcmp(key, "SecurityProfile") == 0)
  18695. {
  18696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18697. {
  18698. check_ascii = value[0];
  18699. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18700. {
  18701. isSuccess = ConfigurationStatus_Rejected;
  18702. }
  18703. else if(check_ascii == 0x33)
  18704. {
  18705. isSuccess = NotSupported;
  18706. }
  18707. else
  18708. {
  18709. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18710. {
  18711. if(((check_ascii - 0x30) == 1) ||
  18712. ((check_ascii - 0x30) == 2) ||
  18713. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18714. {
  18715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18716. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18717. isSuccess = ConfigurationStatus_Accepted;
  18718. }
  18719. else
  18720. isSuccess = ConfigurationStatus_Rejected;
  18721. }
  18722. else
  18723. isSuccess = ConfigurationStatus_Rejected;
  18724. }
  18725. }
  18726. else
  18727. {
  18728. isSuccess = ConfigurationStatus_Rejected;
  18729. }
  18730. }
  18731. if(strcmp(key, "DefaultPrice") == 0)
  18732. {
  18733. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18734. {
  18735. strcpy(str, (const char*)value);
  18736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18737. isSuccess = ConfigurationStatus_Accepted;
  18738. }
  18739. else
  18740. {
  18741. isSuccess = ConfigurationStatus_Rejected;
  18742. }
  18743. }
  18744. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18745. {
  18746. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18747. {
  18748. strcpy(str, (const char*)value);
  18749. for(int i = 0; str[i]; i++)
  18750. {
  18751. str[i] = tolower(str[i]);
  18752. }
  18753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18754. isSuccess = ConfigurationStatus_Accepted;
  18755. }
  18756. else
  18757. {
  18758. isSuccess = ConfigurationStatus_Rejected;
  18759. }
  18760. }
  18761. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18762. {
  18763. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18764. {
  18765. strcpy(str, (const char*)value);
  18766. for(int i = 0; str[i]; i++)
  18767. {
  18768. str[i] = tolower(str[i]);
  18769. }
  18770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18771. isSuccess = ConfigurationStatus_Accepted;
  18772. }
  18773. else
  18774. {
  18775. isSuccess = ConfigurationStatus_Rejected;
  18776. }
  18777. }
  18778. if(strcmp(key, "TimeOffset") == 0)
  18779. {
  18780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18781. {
  18782. strcpy(str, (const char*)value);
  18783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18784. isSuccess = ConfigurationStatus_Accepted;
  18785. }
  18786. else
  18787. {
  18788. isSuccess = ConfigurationStatus_Rejected;
  18789. }
  18790. }
  18791. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18792. {
  18793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18794. {
  18795. strcpy(str, (const char*)value);
  18796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18797. isSuccess = ConfigurationStatus_Accepted;
  18798. }
  18799. else
  18800. {
  18801. isSuccess = ConfigurationStatus_Rejected;
  18802. }
  18803. }
  18804. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18805. {
  18806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18807. {
  18808. strcpy(str, (const char*)value);
  18809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18810. isSuccess = ConfigurationStatus_Accepted;
  18811. }
  18812. else
  18813. {
  18814. isSuccess = ConfigurationStatus_Rejected;
  18815. }
  18816. }
  18817. if(strcmp(key, "SystemUptimeSec") == 0)
  18818. {
  18819. isSuccess = NotSupported;
  18820. }
  18821. if(strcmp(key, "FreeVend") == 0)
  18822. {
  18823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18824. {
  18825. strcpy(str, (const char*)value);
  18826. for(int i = 0; str[i]; i++)
  18827. {
  18828. str[i] = tolower(str[i]);
  18829. }
  18830. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18832. isSuccess = ConfigurationStatus_Accepted;
  18833. }
  18834. else
  18835. {
  18836. isSuccess = ConfigurationStatus_Rejected;
  18837. }
  18838. }
  18839. if(strcmp(key, "FreeVendIdtag") == 0)
  18840. {
  18841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18842. {
  18843. strcpy(str, (const char*)value);
  18844. if(strlen(str) <= 20)
  18845. {
  18846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18847. isSuccess = ConfigurationStatus_Accepted;
  18848. }
  18849. else
  18850. {
  18851. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18852. isSuccess = ConfigurationStatus_Rejected;
  18853. }
  18854. }
  18855. else
  18856. {
  18857. isSuccess = ConfigurationStatus_Rejected;
  18858. }
  18859. }
  18860. if(strcmp(key, "OcppServer") == 0)
  18861. {
  18862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18863. {
  18864. strcpy(str, (const char*)value);
  18865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18866. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18867. isSuccess = ConfigurationStatus_Accepted;
  18868. }
  18869. else
  18870. {
  18871. isSuccess = ConfigurationStatus_Rejected;
  18872. }
  18873. }
  18874. if(strcmp(key, "MaintainServer") == 0)
  18875. {
  18876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18877. {
  18878. strcpy(str, (const char*)value);
  18879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18880. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18881. isSuccess = ConfigurationStatus_Accepted;
  18882. }
  18883. else
  18884. {
  18885. isSuccess = ConfigurationStatus_Rejected;
  18886. }
  18887. }
  18888. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18889. {
  18890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18891. {
  18892. strcpy(str, (const char*)value);
  18893. for(int i = 0; str[i]; i++)
  18894. {
  18895. str[i] = tolower(str[i]);
  18896. }
  18897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18898. isSuccess = ConfigurationStatus_Accepted;
  18899. }
  18900. else
  18901. {
  18902. isSuccess = ConfigurationStatus_Rejected;
  18903. }
  18904. }
  18905. if(strcmp(key, "StatusNotificationInterval") == 0)
  18906. {
  18907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18908. {
  18909. check_ascii = value[0];
  18910. if( (check_ascii < 48) || (check_ascii > 57) )
  18911. {
  18912. isSuccess = ConfigurationStatus_Rejected;
  18913. }
  18914. else
  18915. {
  18916. if((atoi(value) == 0) || (atoi(value) >= 10))
  18917. {
  18918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18919. isSuccess = ConfigurationStatus_Accepted;
  18920. }
  18921. else
  18922. isSuccess = ConfigurationStatus_Rejected;
  18923. }
  18924. }
  18925. else
  18926. {
  18927. isSuccess = ConfigurationStatus_Rejected;
  18928. }
  18929. }
  18930. if(strcmp(key, "PreAuthAmount") == 0)
  18931. {
  18932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18933. {
  18934. check_ascii = value[0];
  18935. if( (check_ascii < 48) || (check_ascii > 57) )
  18936. {
  18937. isSuccess = ConfigurationStatus_Rejected;
  18938. }
  18939. else
  18940. {
  18941. if(atof(value) >= 0)
  18942. {
  18943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18944. isSuccess = ConfigurationStatus_Accepted;
  18945. }
  18946. else
  18947. isSuccess = ConfigurationStatus_Rejected;
  18948. }
  18949. }
  18950. else
  18951. {
  18952. isSuccess = ConfigurationStatus_Rejected;
  18953. }
  18954. }
  18955. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  18956. {
  18957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  18958. {
  18959. check_ascii = value[0];
  18960. if( (check_ascii < 48) || (check_ascii > 57) )
  18961. {
  18962. isSuccess = ConfigurationStatus_Rejected;
  18963. }
  18964. else
  18965. {
  18966. if(atoi(value) >= 0)
  18967. {
  18968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  18969. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  18970. isSuccess = ConfigurationStatus_Accepted;
  18971. }
  18972. else
  18973. isSuccess = ConfigurationStatus_Rejected;
  18974. }
  18975. }
  18976. else
  18977. {
  18978. isSuccess = ConfigurationStatus_Rejected;
  18979. }
  18980. }
  18981. if(strcmp(key, "PowerSharingServerIP") == 0)
  18982. {
  18983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  18984. {
  18985. strcpy(str, (const char*)value);
  18986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  18987. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  18988. isSuccess = ConfigurationStatus_Accepted;
  18989. }
  18990. else
  18991. {
  18992. isSuccess = ConfigurationStatus_Rejected;
  18993. }
  18994. }
  18995. if(strcmp(key, "EVCCID_PREFIX") == 0)
  18996. {
  18997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  18998. {
  18999. strcpy(str, (const char*)value);
  19000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  19001. isSuccess = ConfigurationStatus_Accepted;
  19002. }
  19003. else
  19004. {
  19005. isSuccess = ConfigurationStatus_Rejected;
  19006. }
  19007. }
  19008. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  19009. {
  19010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  19011. {
  19012. if(atoi(value) > modelnameInfo.ratedPower)
  19013. {
  19014. isSuccess = ConfigurationStatus_Rejected;
  19015. }
  19016. else{
  19017. strcpy(str, (const char*)value);
  19018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  19019. isSuccess = ConfigurationStatus_Accepted;
  19020. }
  19021. }
  19022. else
  19023. {
  19024. isSuccess = ConfigurationStatus_Rejected;
  19025. }
  19026. }
  19027. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  19028. {
  19029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19030. {
  19031. if((atoi(value) != 0) && (atoi(value) < 5))
  19032. {
  19033. isSuccess = ConfigurationStatus_Rejected;
  19034. }
  19035. else{
  19036. strcpy(str, (const char*)value);
  19037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  19038. isSuccess = ConfigurationStatus_Accepted;
  19039. }
  19040. }
  19041. else
  19042. {
  19043. isSuccess = ConfigurationStatus_Rejected;
  19044. }
  19045. }
  19046. if(strcmp(key, "CpoName") == 0)
  19047. {
  19048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19049. {
  19050. strcpy(str, (const char*)value);
  19051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19052. isSuccess = ConfigurationStatus_Accepted;
  19053. }
  19054. else
  19055. {
  19056. isSuccess = ConfigurationStatus_Rejected;
  19057. }
  19058. }
  19059. #if 0
  19060. //For OCPP Test Case
  19061. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19062. {
  19063. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19064. {
  19065. strcpy(str, (const char*)value);
  19066. for(int i = 0; str[i]; i++)
  19067. {
  19068. str[i] = tolower(str[i]);
  19069. }
  19070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19071. isSuccess = ConfigurationStatus_Accepted;
  19072. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19073. }
  19074. else
  19075. {
  19076. isSuccess = ConfigurationStatus_Rejected;
  19077. }
  19078. }
  19079. #endif
  19080. #if 1
  19081. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19082. {
  19083. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19084. {
  19085. strcpy(str, (const char*)value);
  19086. for(int i = 0; str[i]; i++)
  19087. {
  19088. str[i] = tolower(str[i]);
  19089. }
  19090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19091. isSuccess = ConfigurationStatus_Accepted;
  19092. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19093. }
  19094. else
  19095. {
  19096. isSuccess = ConfigurationStatus_Rejected;
  19097. }
  19098. }
  19099. #endif
  19100. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19101. {
  19102. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19103. {
  19104. check_ascii = value[0];
  19105. if( (check_ascii < 48) || (check_ascii > 57) )
  19106. {
  19107. isSuccess = ConfigurationStatus_Rejected;
  19108. }
  19109. else
  19110. {
  19111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19112. isSuccess = ConfigurationStatus_Accepted;
  19113. }
  19114. }
  19115. else
  19116. {
  19117. isSuccess = ConfigurationStatus_Rejected;
  19118. }
  19119. }
  19120. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19121. {
  19122. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19123. {
  19124. check_ascii = value[0];
  19125. if( (check_ascii < 48) || (check_ascii > 57) )
  19126. {
  19127. isSuccess = ConfigurationStatus_Rejected;
  19128. }
  19129. else
  19130. {
  19131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19132. isSuccess = ConfigurationStatus_Accepted;
  19133. }
  19134. }
  19135. else
  19136. {
  19137. isSuccess = ConfigurationStatus_Rejected;
  19138. }
  19139. }
  19140. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19141. {
  19142. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19143. {
  19144. strcpy(str, (const char*)value);
  19145. for(int i = 0; str[i]; i++)
  19146. {
  19147. str[i] = tolower(str[i]);
  19148. }
  19149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19150. isSuccess = ConfigurationStatus_Accepted;
  19151. }
  19152. else
  19153. {
  19154. isSuccess = ConfigurationStatus_Rejected;
  19155. }
  19156. }
  19157. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19158. {
  19159. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19160. {
  19161. check_ascii = value[0];
  19162. if( (check_ascii < 48) || (check_ascii > 57) )
  19163. {
  19164. isSuccess = ConfigurationStatus_Rejected;
  19165. }
  19166. else
  19167. {
  19168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19169. isSuccess = ConfigurationStatus_Accepted;
  19170. }
  19171. }
  19172. else
  19173. {
  19174. isSuccess = ConfigurationStatus_Rejected;
  19175. }
  19176. }
  19177. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19178. {
  19179. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19180. {
  19181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19182. isSuccess = ConfigurationStatus_Accepted;
  19183. }
  19184. else
  19185. {
  19186. isSuccess = ConfigurationStatus_Rejected;
  19187. }
  19188. }
  19189. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19190. {
  19191. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19192. {
  19193. check_ascii = value[0];
  19194. if( (check_ascii < 48) || (check_ascii > 57) )
  19195. {
  19196. isSuccess = ConfigurationStatus_Rejected;
  19197. }
  19198. else
  19199. {
  19200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19201. isSuccess = ConfigurationStatus_Accepted;
  19202. }
  19203. }
  19204. else
  19205. {
  19206. isSuccess = ConfigurationStatus_Rejected;
  19207. }
  19208. }
  19209. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19210. {
  19211. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19212. {
  19213. strcpy(str, (const char*)value);
  19214. for(int i = 0; str[i]; i++)
  19215. {
  19216. str[i] = tolower(str[i]);
  19217. }
  19218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19219. isSuccess = ConfigurationStatus_Accepted;
  19220. }
  19221. else
  19222. {
  19223. isSuccess = ConfigurationStatus_Rejected;
  19224. }
  19225. }
  19226. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19227. {
  19228. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19229. {
  19230. check_ascii = value[0];
  19231. if( (check_ascii < 48) || (check_ascii > 57) )
  19232. {
  19233. isSuccess = ConfigurationStatus_Rejected;
  19234. }
  19235. else
  19236. {
  19237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19238. isSuccess = ConfigurationStatus_Accepted;
  19239. }
  19240. }
  19241. else
  19242. {
  19243. isSuccess = ConfigurationStatus_Rejected;
  19244. }
  19245. }
  19246. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19247. return isSuccess;
  19248. }
  19249. int TransactionMessageAttemptsGet(void)
  19250. {
  19251. return TransactionMessageAttemptsValue;
  19252. }
  19253. int FirstHeartBeatResponse(void)
  19254. {
  19255. return FirstHeartBeat;
  19256. }
  19257. int TransactionMessageRetryIntervalGet(void)
  19258. {
  19259. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19260. }
  19261. int ReadHttpStatus(int sock)
  19262. {
  19263. //char c;
  19264. char buff[1024]="",*ptr=buff+1;
  19265. int bytes_received, status;
  19266. DEBUG_INFO("Begin Response ..\n");
  19267. while((bytes_received = recv(sock, ptr, 1, 0))){
  19268. if(bytes_received==-1){
  19269. perror("ReadHttpStatus");
  19270. exit(1);
  19271. }
  19272. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19273. ptr++;
  19274. }
  19275. *ptr=0;
  19276. ptr=buff+1;
  19277. sscanf(ptr,"%*s %d ", &status);
  19278. DEBUG_INFO("%s\n",ptr);
  19279. DEBUG_INFO("status=%d\n",status);
  19280. DEBUG_INFO("End Response ..\n");
  19281. return (bytes_received>0)?status:0;
  19282. }
  19283. //the only filed that it parsed is 'Content-Length'
  19284. int ParseHeader(int sock)
  19285. {
  19286. //char c;
  19287. char buff[1024]="",*ptr=buff+4;
  19288. int bytes_received;
  19289. DEBUG_INFO("Begin HEADER ..\n");
  19290. while((bytes_received = recv(sock, ptr, 1, 0))){
  19291. if(bytes_received==-1){
  19292. perror("Parse Header");
  19293. exit(1);
  19294. }
  19295. if(
  19296. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19297. (ptr[-1]=='\r') && (*ptr=='\n' )
  19298. ) break;
  19299. ptr++;
  19300. }
  19301. *ptr=0;
  19302. ptr=buff+4;
  19303. //printf("%s",ptr);
  19304. if(bytes_received){
  19305. ptr=strstr(ptr,"Content-Length:");
  19306. if(ptr){
  19307. sscanf(ptr,"%*s %d",&bytes_received);
  19308. }else
  19309. bytes_received=-1; //unknown size
  19310. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19311. }
  19312. DEBUG_INFO("End HEADER ..\n");
  19313. return bytes_received ;
  19314. }
  19315. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19316. {
  19317. int result = TRUE;
  19318. char rmFileCmd[100]={0};
  19319. char FilePath[100]={0};
  19320. char ftpbuf[200];
  19321. int systemresult;
  19322. sprintf(FilePath,"/mnt/%s",filename);
  19323. system("ping 8.8.8.8 &");
  19324. if((access(FilePath,F_OK))!=-1)
  19325. {
  19326. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19327. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19328. system(rmFileCmd);
  19329. }
  19330. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19331. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19332. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19333. systemresult = system(ftpbuf);
  19334. if(systemresult != 0)
  19335. {
  19336. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19337. result = FALSE;
  19338. }
  19339. system("pkill ping");
  19340. return result;
  19341. }
  19342. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19343. {
  19344. int result = TRUE;
  19345. char rmFileCmd[100]={0};
  19346. char FilePath[100]={0};
  19347. char ftpbuf[200];
  19348. int systemresult;
  19349. sprintf(FilePath,"/mnt/%s",filename);
  19350. system("ping 8.8.8.8 &");
  19351. if((access(FilePath,F_OK))!=-1)
  19352. {
  19353. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19354. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19355. system(rmFileCmd);
  19356. }
  19357. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19358. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19359. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19360. systemresult = system(ftpbuf);
  19361. if(systemresult != 0)
  19362. {
  19363. DEBUG_WARN("scp error!\n");
  19364. result = FALSE;
  19365. }
  19366. system("pkill ping");
  19367. return result;
  19368. }
  19369. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19370. {
  19371. int result = TRUE;
  19372. char rmFileCmd[100]={0};
  19373. char FilePath[100]={0};
  19374. char ftpbuf[200];
  19375. int systemresult;
  19376. sprintf(FilePath,"/mnt/%s",filename);
  19377. system("ping 8.8.8.8 &");
  19378. if((access(FilePath,F_OK))!=-1)
  19379. {
  19380. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19381. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19382. system(rmFileCmd);
  19383. }
  19384. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19385. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  19386. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19387. systemresult = system(ftpbuf);
  19388. if(systemresult != 0)
  19389. {
  19390. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  19391. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19392. systemresult = system(ftpbuf);
  19393. if(systemresult != 0)
  19394. {
  19395. DEBUG_WARN("FTP download fail!\n");
  19396. result = FALSE;
  19397. }
  19398. }
  19399. system("pkill ping");
  19400. return result;
  19401. }
  19402. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19403. {
  19404. char rmFileCmd[100]={0};
  19405. char FilePath[100]={0};
  19406. char buf[512];
  19407. int systemresult = 0;
  19408. //DEBUG_INFO("filename=%s\n",filename);
  19409. //DEBUG_INFO("url=%s\n",url);
  19410. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19411. if((access(FilePath,F_OK))!=-1)
  19412. {
  19413. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19414. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19415. system(rmFileCmd);
  19416. }
  19417. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19418. if(fp == NULL)
  19419. {
  19420. DEBUG_INFO("log is NULL\n");
  19421. return FALSE;
  19422. }
  19423. else
  19424. {
  19425. fprintf(fp, "%s\n", url);
  19426. fprintf(fp, "%s\n", filename);
  19427. fclose(fp);
  19428. }
  19429. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19430. if(phpFP == NULL)
  19431. {
  19432. DEBUG_INFO("PHP upload fail.\n");
  19433. return FALSE;
  19434. }
  19435. else
  19436. {
  19437. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19438. {
  19439. if(strstr(buf, "result") != NULL)
  19440. {
  19441. sscanf(buf, "result: %d", &systemresult);
  19442. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19443. }
  19444. }
  19445. pclose(phpFP);
  19446. }
  19447. if(systemresult != 1)
  19448. {
  19449. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19450. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19451. if(phpFP == NULL)
  19452. {
  19453. DEBUG_WARN("PHP PUT upload fail.\n");
  19454. return FALSE;
  19455. }
  19456. else
  19457. {
  19458. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19459. {
  19460. if(strstr(buf, "result") != NULL)
  19461. {
  19462. sscanf(buf, "result: %d", &systemresult);
  19463. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19464. }
  19465. }
  19466. pclose(phpFP);
  19467. }
  19468. }
  19469. if(systemresult != 1)
  19470. {
  19471. DEBUG_WARN("PHP PUT upload fail.\n");
  19472. return FALSE;
  19473. }
  19474. return TRUE;
  19475. }
  19476. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19477. {
  19478. int result = FALSE;
  19479. char ftpbuf[200];
  19480. int systemresult;
  19481. /*
  19482. // Domaind name transfer to IP address
  19483. struct hostent* server;
  19484. char *IPbuffer;
  19485. server = gethostbyname(location);
  19486. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19487. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19488. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19489. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19490. systemresult = system(ftpbuf);
  19491. if(systemresult != 0)
  19492. {
  19493. DEBUG_INFO("ftpput error!\n");
  19494. }
  19495. else
  19496. {
  19497. result = TRUE;
  19498. DEBUG_INFO("ftpput OK!\n");
  19499. }
  19500. return result;
  19501. }
  19502. int GetOcppServerURL()
  19503. {
  19504. int result = FALSE;
  19505. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19506. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19507. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19508. struct yuarel url;
  19509. char urlStr[512];
  19510. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19511. {
  19512. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19513. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19514. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19515. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19516. if(yuarel_parse(&url, urlStr) != -1)
  19517. {
  19518. sprintf(OcppProtocol, "%s", url.scheme);
  19519. sprintf(OcppHost, "%s", url.host);
  19520. if(url.path == NULL)
  19521. OcppTempPath[0] = '\0';
  19522. else
  19523. {
  19524. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19525. {
  19526. sprintf(OcppTempPath, "%s/", url.path);
  19527. }
  19528. else
  19529. {
  19530. sprintf(OcppTempPath, "%s", url.path);
  19531. }
  19532. }
  19533. if(url.port == 0)
  19534. {
  19535. if(strcmp(OcppProtocol, "wss") == 0)
  19536. OcppPort = 443;
  19537. else
  19538. OcppPort = 80;
  19539. }
  19540. else
  19541. OcppPort = url.port;
  19542. result = TRUE;
  19543. }
  19544. }
  19545. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19546. {
  19547. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19548. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19549. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19550. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19551. if(yuarel_parse(&url, urlStr) != -1)
  19552. {
  19553. sprintf(OcppProtocol, "%s", url.scheme);
  19554. sprintf(OcppHost, "%s", url.host);
  19555. if(url.path == NULL)
  19556. OcppTempPath[0] = '\0';
  19557. else
  19558. sprintf(OcppTempPath, "%s", url.path);
  19559. if(url.port == 0)
  19560. {
  19561. if(strcmp(OcppProtocol, "wss") == 0)
  19562. OcppPort = 443;
  19563. else
  19564. OcppPort = 80;
  19565. }
  19566. else
  19567. OcppPort = url.port;
  19568. result = TRUE;
  19569. }
  19570. }
  19571. else
  19572. {
  19573. strcpy(OcppHost,"");
  19574. }
  19575. return result;
  19576. }
  19577. int GetOcppPath()
  19578. {
  19579. int result = FALSE;
  19580. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19581. {
  19582. if(OcppTempPath == NULL)
  19583. {
  19584. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19585. }
  19586. else
  19587. {
  19588. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19589. }
  19590. result = TRUE;
  19591. goto End;
  19592. }
  19593. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19594. {
  19595. if(OcppTempPath == NULL)
  19596. {
  19597. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19598. }
  19599. else
  19600. {
  19601. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19602. }
  19603. result = TRUE;
  19604. goto End;
  19605. }
  19606. else
  19607. {
  19608. strcpy(OcppPath,"");
  19609. }
  19610. End:
  19611. return result;
  19612. }
  19613. int GetOcppPort()
  19614. {
  19615. return OcppPort;
  19616. }
  19617. int GetOcppConnStatus(void)
  19618. {
  19619. return ShmOCPP16Data->OcppConnStatus;
  19620. }
  19621. void SetOcppConnStatus(uint8_t status)
  19622. {
  19623. ShmOCPP16Data->OcppConnStatus = status;
  19624. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19625. }
  19626. int GetHeartBeatWithNOResponse(void)
  19627. {
  19628. return HeartBeatWithNOResponse;
  19629. }
  19630. void SetHeartBeatWithNOResponse(void)
  19631. {
  19632. HeartBeatWithNOResponse = 0;
  19633. }
  19634. void GetStartTransactionIdTag(int gun_index)
  19635. {
  19636. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19637. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19638. }
  19639. int GetStartTransactionId(int gun_index)
  19640. {
  19641. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19642. }
  19643. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19644. {
  19645. char ch;
  19646. FILE *fptr1;
  19647. int temptransactionId;
  19648. char str[100]={0};
  19649. temptransactionId = 0;
  19650. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19651. {
  19652. DEBUG_INFO("IdTag is empty.\n");
  19653. return temptransactionId;
  19654. }
  19655. /*------ Read the file ----------------*/
  19656. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19657. if (!fptr1)
  19658. {
  19659. DEBUG_INFO("QueueTransactionId file open error.\n");
  19660. //printf(" File not found or unable to open the input file!!\n");
  19661. return temptransactionId;
  19662. }
  19663. ch=fgetc(fptr1);
  19664. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19665. rewind(fptr1);
  19666. if(ch!=EOF)
  19667. {
  19668. // printf("%c",ch);
  19669. while (fgets(str, 100, fptr1) != NULL)
  19670. {
  19671. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19672. if(str[0]=='\0')
  19673. {
  19674. break;
  19675. }
  19676. char *revbuf[8] = {0}; // Variable store string split
  19677. int num = 0;// Quantity after string split
  19678. DEBUG_INFO("Transaction queue data= %s\n", str);
  19679. splitstring(str,",",revbuf,&num); // String split
  19680. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19681. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19682. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19683. DEBUG_INFO("------------------------------\n");
  19684. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19685. {
  19686. if(isStopTransaction)
  19687. {
  19688. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19689. {
  19690. temptransactionId = atoi(revbuf[2]);
  19691. //break;
  19692. }
  19693. }
  19694. else
  19695. {
  19696. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19697. {
  19698. temptransactionId = atoi(revbuf[2]);
  19699. //break;
  19700. }
  19701. }
  19702. }
  19703. }
  19704. }
  19705. else
  19706. DEBUG_INFO("EOF\n");
  19707. fclose(fptr1);
  19708. /*------- End of reading ---------------*/
  19709. return temptransactionId;
  19710. }
  19711. void SetTransactionIdZero(int transactionId)
  19712. {
  19713. char ch;
  19714. FILE *fptr1, *fptr2;
  19715. int temptransactionId = 0;
  19716. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19717. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19718. if (!fptr1)
  19719. {
  19720. //printf(" File not found or unable to open the input file!!\n");
  19721. return ;
  19722. }
  19723. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19724. if (!fptr2)
  19725. {
  19726. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19727. fclose(fptr1);
  19728. return ;
  19729. }
  19730. ch=fgetc(fptr1);
  19731. rewind(fptr1);
  19732. if(ch!=EOF)
  19733. {
  19734. // copy all contents to the temporary file except the specific line
  19735. while (fgets(str, 100, fptr1) != NULL)
  19736. {
  19737. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19738. if(str[0]=='\0')
  19739. {
  19740. break;
  19741. }
  19742. char *revbuf[8] = {0};
  19743. int num = 0;
  19744. strcpy(strtemp, str);
  19745. splitstring(str,",",revbuf,&num);
  19746. if(revbuf[2][0] != '\0')
  19747. {
  19748. temptransactionId = atoi(revbuf[2]);
  19749. if(transactionId != temptransactionId)
  19750. {
  19751. fprintf(fptr2, "%s\n", strtemp);
  19752. }
  19753. }
  19754. }
  19755. }
  19756. fclose(fptr1);
  19757. fclose(fptr2);
  19758. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19759. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19760. /*------ Read the file ----------------*/
  19761. }
  19762. int InternetDisconnect(void)
  19763. {
  19764. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19765. }
  19766. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19767. void storeTempStopTransaction(int gun_index)
  19768. {
  19769. char guid[37]={0};
  19770. int tempIndex = 0;
  19771. char TempStopTransaction[256];
  19772. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19773. DEBUG_INFO("storeTempStopTransaction...\n");
  19774. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19775. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19776. //=========================== Stop Transaction Time ===============================================
  19777. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  19778. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19779. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19780. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19781. {
  19782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19783. {
  19784. tempIndex = ((gun_index==2) ? 1: 0);
  19785. }
  19786. else
  19787. {
  19788. tempIndex = gun_index;
  19789. }
  19790. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19791. {
  19792. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19793. {
  19794. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19795. }
  19796. }// END OF CHAdeMO_QUANTITY
  19797. }
  19798. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19799. {
  19800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19801. {
  19802. tempIndex = ((gun_index==2) ? 1: 0);
  19803. }
  19804. else
  19805. {
  19806. tempIndex = gun_index;
  19807. }
  19808. for (int index = 0; index < CCS_QUANTITY; index++)
  19809. {
  19810. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19811. {
  19812. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19813. }
  19814. }// END OF CCS_QUANTITY
  19815. }
  19816. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19817. {
  19818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19819. {
  19820. tempIndex = ((gun_index==2) ? 1: 0);
  19821. }
  19822. else
  19823. {
  19824. tempIndex = gun_index;
  19825. }
  19826. for (int index = 0; index < GB_QUANTITY; index++)
  19827. {
  19828. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19829. {
  19830. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19831. }
  19832. }// END OF GB_QUANTITY
  19833. }
  19834. else if(gunType[gun_index] == GUN_TYPE_DO)
  19835. {
  19836. tempIndex = gun_index;
  19837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19838. {
  19839. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19840. {
  19841. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19842. }
  19843. }
  19844. }
  19845. else
  19846. {
  19847. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19848. {
  19849. tempIndex = 2;
  19850. }
  19851. else
  19852. {
  19853. tempIndex = gun_index;
  19854. }
  19855. for (int index = 0; index < AC_QUANTITY; index++)
  19856. {
  19857. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19858. {
  19859. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19860. }
  19861. }// END OF AC_QUANTITY
  19862. }
  19863. //======================================== Message create ==============================================
  19864. json_object *StopTransaction = json_object_new_object();
  19865. json_object *transactionDatas = json_object_new_array();
  19866. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19867. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19868. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19869. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19870. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19871. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19872. meterValueBufferQuery(gun_index, transactionDatas);
  19873. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19874. random_uuid(guid);
  19875. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19876. ,MESSAGE_TYPE_CALL
  19877. ,guid
  19878. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19879. json_object_put(StopTransaction);
  19880. // Check File "TempStopTransaction" Exist
  19881. if((access(TempStopTransaction,F_OK))!=-1)
  19882. {
  19883. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19884. fclose(fopen(TempStopTransaction, "w"));
  19885. }
  19886. else
  19887. {
  19888. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19889. FILE *log = fopen(TempStopTransaction, "w+");
  19890. if(log == NULL)
  19891. {
  19892. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19893. return ;
  19894. }
  19895. else
  19896. {
  19897. fclose(log);
  19898. }
  19899. }
  19900. //Add TempStopTransaction | Update TempStopTransaction
  19901. // open file for writing
  19902. FILE *outfile;
  19903. outfile = fopen (TempStopTransaction, "a");
  19904. //DEBUG_INFO("data = %s\n", queuedata);
  19905. fputs(queuedata, outfile);
  19906. fputs("\n", outfile);
  19907. fclose (outfile);
  19908. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19909. OCPP_updatePeriodEnergy(gun_index);
  19910. }
  19911. void checkTempStopTransaction(int gun_index)
  19912. {
  19913. FILE *fptr1;
  19914. char ch;
  19915. char str[QUEUE_MESSAGE_LENGTH]={0};
  19916. char guid[37]={0};
  19917. char tempdata[65]={0};
  19918. char connectorStr[2]={0};
  19919. char TempStopTransaction[256];
  19920. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19921. fptr1 = fopen(TempStopTransaction, "r");
  19922. //TempStopTransaction格式: 槍號,StopTransaction封包
  19923. if (!fptr1)
  19924. {
  19925. //printf(" File not found or unable to open the input file!!\n");
  19926. return ;
  19927. }
  19928. ch=fgetc(fptr1);
  19929. //printf(" Now the content of the file %s is : \n",fname);
  19930. rewind(fptr1);
  19931. if(ch!=EOF)
  19932. {
  19933. // copy all contents to the temporary file except the specific line
  19934. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19935. {
  19936. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19937. if(str[0]=='\0')
  19938. {
  19939. break;
  19940. }
  19941. //TempStopTransaction格式: 槍號,StopTransaction封包
  19942. strncpy(connectorStr, str, 1);
  19943. if(atoi(connectorStr) != (gun_index+1))
  19944. {
  19945. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19946. fclose(fptr1);
  19947. return ;
  19948. }
  19949. //random_uuid(guid);
  19950. strncpy(guid, str+6, 36); //copy guid
  19951. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19952. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19953. {
  19954. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19955. }
  19956. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19957. OCPP_insert_transaction_msg(NO, str);
  19958. memset(str,0,ARRAY_SIZE(str));
  19959. }
  19960. }
  19961. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19962. fclose(fptr1);
  19963. remove(TempStopTransaction); // remove the original file
  19964. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19965. }
  19966. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19967. {
  19968. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19969. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19970. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19971. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19972. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19973. }
  19974. void FillTransactionId(int ConnectorId, int TransactionId)
  19975. {
  19976. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19977. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  19978. }
  19979. int GetWebSocketPingInterval(void)
  19980. {
  19981. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19982. }
  19983. int GetServerSign(void)
  19984. {
  19985. return server_sign;
  19986. }
  19987. uint8_t GetOcppSecurityProfile()
  19988. {
  19989. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19990. }
  19991. void MergeCertificates()
  19992. {
  19993. char cmdBuf[2048]={0};
  19994. if(access(ROOTCA_CS,F_OK) != -1)
  19995. {
  19996. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  19997. }
  19998. else
  19999. {
  20000. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  20001. }
  20002. system(cmdBuf);
  20003. }
  20004. void GetOcppChargerBoxId(uint8_t *data)
  20005. {
  20006. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20007. }
  20008. void GetOcppSecurityPassword(uint8_t *data)
  20009. {
  20010. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20011. }
  20012. void SetOcppVersion(uint8_t *version)
  20013. {
  20014. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20015. DEBUG_INFO("ocpp version: %s\n", version);
  20016. if(strstr((char*)version, "ocpp1.6") != NULL)
  20017. {
  20018. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20019. }
  20020. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20021. {
  20022. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20023. system("pkill OcppBackend");
  20024. }
  20025. }
  20026. void SetServerSign(int value)
  20027. {
  20028. server_sign = value;
  20029. }
  20030. int GetBootNotificationInterval(void)
  20031. {
  20032. return BootNotificationInterval;
  20033. }
  20034. int GetInternetConn(void)
  20035. {
  20036. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20037. }
  20038. int GetBackendConnectionTimeout(void)
  20039. {
  20040. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20041. }
  20042. int isConnectorInitMode(int gun_index)
  20043. {
  20044. int tempIndex = 0;
  20045. int result = TRUE;
  20046. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20047. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20048. {
  20049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20050. {
  20051. tempIndex = ((gun_index==2) ? 1: 0);
  20052. }
  20053. else
  20054. {
  20055. tempIndex = gun_index;
  20056. }
  20057. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20058. {
  20059. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20060. {
  20061. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20062. } //end of the same index
  20063. }//end of for CHAdeMO_QUANTITY
  20064. }
  20065. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20066. {
  20067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20068. {
  20069. tempIndex = ((gun_index==2) ? 1: 0);
  20070. }
  20071. else
  20072. {
  20073. tempIndex = gun_index;
  20074. }
  20075. for (int index = 0; index < CCS_QUANTITY; index++)
  20076. {
  20077. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20078. {
  20079. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20080. } //end of the same index
  20081. } // end of for CCS_QUANTITY
  20082. }
  20083. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20084. {
  20085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20086. {
  20087. tempIndex = ((gun_index==2) ? 1: 0);
  20088. }
  20089. else
  20090. {
  20091. tempIndex = gun_index;
  20092. }
  20093. for (int index = 0; index < GB_QUANTITY; index++)
  20094. {
  20095. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20096. {
  20097. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20098. } //end of the same index
  20099. } // end of for GB_QUANTITY
  20100. }
  20101. else if(gunType[gun_index] == GUN_TYPE_DO)
  20102. {
  20103. tempIndex = gun_index;
  20104. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20105. {
  20106. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20107. {
  20108. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20109. } //end of the same index
  20110. }
  20111. }
  20112. else
  20113. {
  20114. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20115. {
  20116. tempIndex = 2;
  20117. }
  20118. else
  20119. {
  20120. tempIndex = gun_index;
  20121. }
  20122. for (int index = 0; index < AC_QUANTITY; index++)
  20123. {
  20124. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20125. {
  20126. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20127. }//end of the same index
  20128. }//end of for AC_QUANTITY
  20129. }
  20130. return result;
  20131. }
  20132. void refreshProcDogTimer()
  20133. {
  20134. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20135. }
  20136. void InitialSystemValue(void)
  20137. {
  20138. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20139. locallistVersion=0;
  20140. BootNotificationInterval = 0;
  20141. authorizeRetryTimes = 0;
  20142. GunStatusInterval = 10;
  20143. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20144. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20145. //Hear Beat
  20146. HeartBeatWithNOResponse = 0;
  20147. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20148. FirstHeartBeat = 0;
  20149. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20150. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20151. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20152. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20153. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20154. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20155. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20156. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20157. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20158. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20159. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20160. //Status && ConnectorPlugIn Setting
  20161. Connector0PreviousSystemStatus = 99;
  20162. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20163. {
  20164. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20165. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20166. }
  20167. for (int index = 0; index < CCS_QUANTITY; index++)
  20168. {
  20169. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20170. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20171. }
  20172. for (int index = 0; index < GB_QUANTITY; index++)
  20173. {
  20174. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20175. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20176. }
  20177. for (int index = 0; index < AC_QUANTITY; index++)
  20178. {
  20179. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20180. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20181. }
  20182. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20183. {
  20184. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20185. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20186. }
  20187. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20188. {
  20189. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20190. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20191. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20192. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20193. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20194. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20195. }
  20196. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20197. refreshStartTimer(&clientTime.Heartbeat);
  20198. sleep(1);
  20199. }
  20200. void LWS_Send(char *str)
  20201. {
  20202. //=====================================================
  20203. // Check InternetConn 0: disconnected, 1: connected
  20204. //====================================================
  20205. if(GetOcppConnStatus() == 0)
  20206. {
  20207. DEBUG_INFO("offline now !!!\n");
  20208. return;
  20209. }
  20210. // Only disable isWebsocketSendable operation initiated by charger
  20211. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20212. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20213. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20214. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20215. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20216. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20217. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20218. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20219. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20220. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20221. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20222. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20223. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20224. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20225. {
  20226. isWebsocketSendable = 0;
  20227. }
  20228. pthread_mutex_lock(&lock_send);
  20229. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20230. sprintf((char *)SendBuffer, "%s", str);
  20231. SendBufLen = strlen(str);
  20232. pthread_mutex_unlock(&lock_send);
  20233. lws_callback_on_writable(wsi_client);
  20234. //lws_service(context, 0);
  20235. //sleep(1);
  20236. }
  20237. void LWS_SendNow(char *str)
  20238. {
  20239. //=====================================================
  20240. // Check InternetConn 0: disconnected, 1: connected
  20241. //====================================================
  20242. if(GetOcppConnStatus() == 0)
  20243. {
  20244. DEBUG_INFO("offline now !!!\n");
  20245. return;
  20246. }
  20247. // Only disable isWebsocketSendable operation initiated by charger
  20248. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20249. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20250. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20251. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20252. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20253. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20254. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20255. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20256. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20257. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20258. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20259. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20260. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20261. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20262. {
  20263. isWebsocketSendable = 0;
  20264. }
  20265. pthread_mutex_lock(&lock_send);
  20266. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20267. sprintf((char *)SendBuffer, "%s", str);
  20268. SendBufLen = strlen(str);
  20269. pthread_mutex_unlock(&lock_send);
  20270. lws_callback_on_writable(wsi_client);
  20271. lws_service(context, 0);
  20272. //sleep(1);
  20273. }