MessageHandler.c 993 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134
  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) && (HeartBeatWaitTime > 0) && (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(connectorIdInt > 0)
  9198. {
  9199. if(chargingProfilePurposeIsNULL == TRUE)
  9200. {
  9201. int m = 0;
  9202. memset(fname, 0, ARRAY_SIZE(fname));
  9203. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9204. if((access(fname,F_OK))!=-1)
  9205. {
  9206. strcpy(chargingProfiles[m], fname);
  9207. m = m + 1;
  9208. }
  9209. memset(fname, 0, ARRAY_SIZE(fname));
  9210. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9211. if((access(fname,F_OK))!=-1)
  9212. {
  9213. strcpy(chargingProfiles[m], fname);
  9214. m = m + 1;
  9215. }
  9216. ChargeProfileCount = m;
  9217. }
  9218. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9219. {
  9220. //strcpy(fname, TxDefaultProfile_1_JSON);
  9221. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  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,"TxProfile")==0))
  9229. {
  9230. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9231. if((access(fname,F_OK))!=-1)
  9232. {
  9233. strcpy(chargingProfiles[0], fname);
  9234. ChargeProfileCount = 1;
  9235. }
  9236. //strcpy(fname, TxProfile_1_JSON);
  9237. }
  9238. }
  9239. else // Check all Charging Profiles
  9240. {
  9241. int i = 0;
  9242. char fnametemp[200]={0};
  9243. ChargeProfileCount = 0;
  9244. //Check ChargePointMaxProfile.json exit
  9245. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9246. {
  9247. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9248. i = i + 1;
  9249. }
  9250. //Check TxDefaultProfile_0.json exit
  9251. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9252. {
  9253. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9254. i = i + 1;
  9255. }
  9256. //Check TxDefaultProfile_%d.json
  9257. for(int j=1; j <= gunTotalNumber; j++)
  9258. {
  9259. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9260. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9261. if((access(fnametemp,F_OK))!=-1)
  9262. {
  9263. strcpy(chargingProfiles[i], fnametemp);
  9264. i = i + 1;
  9265. }
  9266. }
  9267. //Check TxProfile_%d.json
  9268. for(int j=1; j <= gunTotalNumber; j++)
  9269. {
  9270. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9271. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9272. if((access(fnametemp,F_OK))!=-1)
  9273. {
  9274. strcpy(chargingProfiles[i], fnametemp);
  9275. i = i + 1;
  9276. }
  9277. }
  9278. ChargeProfileCount = i;
  9279. }// End connectorIsNULL is TRUE
  9280. if(ChargeProfileCount == 0)
  9281. {
  9282. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9283. goto end;
  9284. }
  9285. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9286. {
  9287. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9288. goto end;
  9289. }
  9290. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9291. {
  9292. memset(str, 0, ARRAY_SIZE(str));
  9293. // clear temp file
  9294. sprintf(str,"rm -f %s",temp);
  9295. system(str);
  9296. for(int k=0; k < ChargeProfileCount; k++)
  9297. {
  9298. memset(str, 0, ARRAY_SIZE(str));
  9299. //clear file in C
  9300. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9301. system(str);
  9302. }
  9303. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9304. goto end;
  9305. }
  9306. else if(connectorIsNULL == TRUE)
  9307. {
  9308. for(int k=0; k < ChargeProfileCount; k++)
  9309. {
  9310. fptr1 = fopen(chargingProfiles[k], "r");
  9311. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9312. //Check Charging Profile Count
  9313. while(fscanf(fptr1, "%s", word) != EOF)
  9314. {
  9315. //DEBUG_INFO("word=%s\n",word);
  9316. if(strstr(word, "chargingProfileId")!= NULL)
  9317. {
  9318. //DEBUG_INFO("test chargingProfileId \n");
  9319. n_chargingProfile = n_chargingProfile + 1;
  9320. //DEBUG_INFO("chargingProfileId Found\n");
  9321. }
  9322. }
  9323. rewind(fptr1);
  9324. //search Charging Profile Element
  9325. //int i= 0;
  9326. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9327. {
  9328. json_object *tmpProfilee;
  9329. tmpProfilee = json_tokener_parse(sLineWord);
  9330. if(!is_error(tmpProfilee))
  9331. {
  9332. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9333. {
  9334. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9335. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9336. }
  9337. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9338. {
  9339. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9340. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9341. }
  9342. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9343. {
  9344. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9345. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9346. }
  9347. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9348. {
  9349. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9350. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9351. }
  9352. }
  9353. json_object_put(tmpProfilee);
  9354. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9355. {
  9356. //------- not write to fptr2-------//
  9357. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9358. //clearflag = TRUE;
  9359. }
  9360. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9361. {
  9362. //------- not write to fptr2-------//
  9363. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9364. }
  9365. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9366. {
  9367. //------- not write to fptr2-------//
  9368. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9369. }
  9370. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9371. {
  9372. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9373. }
  9374. else
  9375. {
  9376. fprintf(fptr2, sLineWord);//writing data into file
  9377. }
  9378. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9379. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9380. if(clearflag == TRUE)
  9381. {
  9382. fclose(fptr1);
  9383. fclose(fptr2);
  9384. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9385. system(str);
  9386. // clear temp file
  9387. sprintf(str,"rm -f %s",temp);
  9388. system(str);
  9389. }
  9390. else
  9391. {
  9392. fclose(fptr1);
  9393. fclose(fptr2);
  9394. memset(str, 0, ARRAY_SIZE(str));
  9395. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9396. system(str);
  9397. resultRename = rename(temp, chargingProfiles[k]);
  9398. if(resultRename == 0)
  9399. {
  9400. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9401. }
  9402. else
  9403. {
  9404. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9405. }
  9406. if(comfirmstr[0]== 0)
  9407. {
  9408. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9409. }
  9410. //Check chargingProfile is empty file
  9411. /*------ Read the file ----------------*/
  9412. fptr1=fopen(chargingProfiles[k],"r");
  9413. ch=fgetc(fptr1);
  9414. rewind(fptr1);
  9415. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9416. if(ch!=EOF)
  9417. {
  9418. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9419. {
  9420. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9421. if(sLineWord[0]=='\0')
  9422. {
  9423. isEmptyFile = TRUE;
  9424. break;
  9425. }
  9426. else
  9427. {
  9428. isEmptyFile = FALSE;
  9429. break;
  9430. }
  9431. }
  9432. }
  9433. else
  9434. isEmptyFile = TRUE;
  9435. fclose(fptr1);
  9436. if(isEmptyFile == TRUE)
  9437. {
  9438. memset(str, 0, ARRAY_SIZE(str));
  9439. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9440. system(str);
  9441. }
  9442. }
  9443. }// End of while(int k=0; k < ChargePointCount; k++)
  9444. }
  9445. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9446. {
  9447. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9448. for(int k=0; k < ChargeProfileCount; k++)
  9449. {
  9450. fptr1 = fopen(chargingProfiles[k], "r");
  9451. fptr2 = fopen(temp, "w+");
  9452. //Check Charging Profile Count
  9453. while(fscanf(fptr1, "%s", word) != EOF)
  9454. {
  9455. //DEBUG_INFO("word=%s\n",word);
  9456. if(strstr(word, "chargingProfileId")!= NULL)
  9457. {
  9458. n_chargingProfile = n_chargingProfile + 1;
  9459. }
  9460. }
  9461. rewind(fptr1);
  9462. //search Charging Profile Element
  9463. //int i= 0;
  9464. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9465. {
  9466. json_object *tmpProfilee;
  9467. tmpProfilee = json_tokener_parse(sLineWord);
  9468. if(!is_error(tmpProfilee))
  9469. {
  9470. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9471. {
  9472. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9473. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9474. }
  9475. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9476. {
  9477. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9478. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9479. }
  9480. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9481. {
  9482. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9483. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9484. }
  9485. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9486. {
  9487. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9488. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9489. }
  9490. }
  9491. json_object_put(tmpProfilee);
  9492. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9493. {
  9494. //------- not write to fptr2-------//
  9495. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9496. //clearflag = TRUE;
  9497. }
  9498. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9499. {
  9500. //------- not write to fptr2-------//
  9501. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9502. }
  9503. else if(stackLevelIsNULL == TRUE)
  9504. {
  9505. //Clear Whole File
  9506. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9507. clearflag = TRUE;
  9508. break;
  9509. }
  9510. else
  9511. {
  9512. fprintf(fptr2, sLineWord);//writing data into file
  9513. }
  9514. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9515. }
  9516. if(clearflag == TRUE)
  9517. {
  9518. fclose(fptr1);
  9519. fclose(fptr2);
  9520. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9521. system(str);
  9522. // clear temp file
  9523. sprintf(str,"rm -f %s",temp);
  9524. system(str);
  9525. }
  9526. else
  9527. {
  9528. fclose(fptr1);
  9529. fclose(fptr2);
  9530. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9531. system(str);
  9532. resultRename = rename(temp, chargingProfiles[k]);
  9533. if(resultRename == 0)
  9534. {
  9535. DEBUG_INFO("File ChargingProfile renamed successfully");
  9536. }
  9537. else
  9538. {
  9539. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9540. }
  9541. if(comfirmstr[0]== 0)
  9542. {
  9543. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9544. }
  9545. //Check chargingProfile is empty file
  9546. /*------ Read the file ----------------*/
  9547. fptr1=fopen(chargingProfiles[k],"r");
  9548. ch=fgetc(fptr1);
  9549. rewind(fptr1);
  9550. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9551. if(ch!=EOF)
  9552. {
  9553. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9554. {
  9555. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9556. if(sLineWord[0]=='\0')
  9557. {
  9558. isEmptyFile = TRUE;
  9559. break;
  9560. }
  9561. else
  9562. {
  9563. isEmptyFile = FALSE;
  9564. break;
  9565. }
  9566. }
  9567. }
  9568. else
  9569. isEmptyFile = TRUE;
  9570. fclose(fptr1);
  9571. if(isEmptyFile == TRUE)
  9572. {
  9573. memset(str, 0, ARRAY_SIZE(str));
  9574. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9575. system(str);
  9576. }
  9577. /*------- End of reading ---------------*/
  9578. }
  9579. } // while(int k=0; k < ChargeProfileCount; k++)
  9580. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9581. end:
  9582. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9583. {
  9584. if(connectorIdInt == 0)
  9585. {
  9586. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9587. {
  9588. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9589. }
  9590. }
  9591. else
  9592. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9593. }
  9594. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9595. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9596. return result;
  9597. }
  9598. void createFirmwareVersionByDataTransfer(void)
  9599. {
  9600. json_object *FirmwareDataTransfer = json_object_new_object();
  9601. // AC & DC model
  9602. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9603. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9604. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9605. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9606. // DC model
  9607. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9608. {
  9609. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9610. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9611. (gunType[3] != GUN_TYPE_UNKNOWN))
  9612. {
  9613. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9614. }
  9615. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9616. {
  9617. // DS DM DW
  9618. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9619. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9620. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9621. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9622. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9623. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9624. }
  9625. else
  9626. {
  9627. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9628. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9629. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9630. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9631. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9632. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9633. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9634. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9635. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9636. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9637. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9638. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9639. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9640. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9641. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9642. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9643. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9644. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9645. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9646. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9647. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9648. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9649. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9650. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9651. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9652. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9653. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9654. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9655. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9656. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9657. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9658. }
  9659. }
  9660. // 4G model
  9661. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9662. {
  9663. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9664. }
  9665. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9666. json_object_put(FirmwareDataTransfer);
  9667. }
  9668. int handleDataTransferRequest(char *uuid, char *payload)
  9669. {
  9670. mtrace();
  9671. json_object *response = json_object_new_object();
  9672. int result = FAIL;
  9673. char tempvendorId[255]={0};
  9674. char tempmessageId[50]={0};
  9675. char tempdata[10240]={0};
  9676. char message[20480]={0};
  9677. DEBUG_INFO("handleDataTransferRequest...\n");
  9678. if((uuid != NULL) && (payload != NULL))
  9679. {
  9680. json_object *DataTransfer;
  9681. DataTransfer = json_tokener_parse(payload);
  9682. if(!is_error(DataTransfer))
  9683. {
  9684. // Required data
  9685. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9686. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9687. // Optional data
  9688. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9689. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9690. if(json_object_object_get(DataTransfer, "data") != NULL)
  9691. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9692. result = PASS;
  9693. }
  9694. json_object_put(DataTransfer);
  9695. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9696. {
  9697. // Send all moudle firmware version on EVSE
  9698. createFirmwareVersionByDataTransfer();
  9699. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9700. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9701. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9702. json_object_put(response);
  9703. }
  9704. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9705. {
  9706. system("/usr/bin/run_tmate_restart.sh &");
  9707. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9708. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9709. json_object_put(response);
  9710. }
  9711. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9712. {
  9713. json_object *data;
  9714. data = json_tokener_parse(tempdata);
  9715. if(!is_error(data))
  9716. {
  9717. 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))
  9718. {
  9719. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9720. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9721. if(json_object_object_get(data, "SOC") != NULL)
  9722. {
  9723. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9724. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9725. }
  9726. if(json_object_object_get(data, "Energy") != NULL)
  9727. {
  9728. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9729. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9730. }
  9731. if(json_object_object_get(data, "Duration") != NULL)
  9732. {
  9733. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9734. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9735. }
  9736. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9737. }
  9738. else
  9739. {
  9740. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9741. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9742. }
  9743. }
  9744. else
  9745. {
  9746. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9747. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9748. }
  9749. json_object_put(data);
  9750. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9751. json_object_put(response);
  9752. }
  9753. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9754. {
  9755. json_object *data;
  9756. data = json_tokener_parse(tempdata);
  9757. if(!is_error(data))
  9758. {
  9759. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9760. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9761. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9762. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9763. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9764. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9765. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9766. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9767. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9768. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9769. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9770. }
  9771. else
  9772. {
  9773. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9774. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9775. }
  9776. json_object_put(data);
  9777. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9778. json_object_put(response);
  9779. }
  9780. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9781. {
  9782. json_object *data;
  9783. data = json_tokener_parse(tempdata);
  9784. if(!is_error(data))
  9785. {
  9786. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9787. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9788. if(json_object_object_get(data, "idToken") != NULL)
  9789. {
  9790. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9791. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9792. }
  9793. else
  9794. {
  9795. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9796. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9797. }
  9798. if(json_object_object_get(data, "price") != NULL) //v1.0
  9799. {
  9800. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9801. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9802. }
  9803. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9804. {
  9805. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9806. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9807. }
  9808. else
  9809. {
  9810. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9811. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9812. }
  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, "RunningCost") != NULL)
  9824. {
  9825. json_object *data;
  9826. data = json_tokener_parse(tempdata);
  9827. if(!is_error(data))
  9828. {
  9829. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9830. if(json_object_object_get(data, "txId") != NULL)
  9831. {
  9832. // California pricing V1.0
  9833. DEBUG_INFO("California pricing V1.0\n");
  9834. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9835. sprintf((char*)dmsVersion, "1.0");
  9836. for(int idx = 0;idx<gunTotalNumber;idx++)
  9837. {
  9838. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9839. {
  9840. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9841. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9842. if(json_object_object_get(data, "description") != NULL)
  9843. {
  9844. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9845. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9846. }
  9847. else
  9848. {
  9849. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9850. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9851. }
  9852. }
  9853. }
  9854. }
  9855. else if(json_object_object_get(data, "transactionId") != NULL)
  9856. {
  9857. // California pricing V2.0
  9858. DEBUG_INFO("California pricing V2.0\n");
  9859. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9860. sprintf((char*)dmsVersion, "2.0");
  9861. for(int idx=0;idx<gunTotalNumber;idx++)
  9862. {
  9863. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9864. {
  9865. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9866. if(json_object_object_get(data, "timestamp") != NULL)
  9867. {
  9868. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9869. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9870. }
  9871. else
  9872. {
  9873. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9874. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9875. }
  9876. if(json_object_object_get(data, "meterValue") != NULL)
  9877. {
  9878. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9879. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9880. }
  9881. else
  9882. {
  9883. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9884. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9885. }
  9886. if(json_object_object_get(data, "cost") != NULL)
  9887. {
  9888. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9889. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9890. }
  9891. else
  9892. {
  9893. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9894. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9895. }
  9896. if(json_object_object_get(data, "state") != NULL)
  9897. {
  9898. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9899. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9900. }
  9901. else
  9902. {
  9903. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9904. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9905. }
  9906. if(json_object_object_get(data, "chargingPrice") != NULL)
  9907. {
  9908. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9909. {
  9910. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9911. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9912. }
  9913. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9914. {
  9915. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9916. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9917. }
  9918. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9919. {
  9920. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9921. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9922. }
  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("chargingPrice not found."));
  9928. }
  9929. if(json_object_object_get(data, "idlePrice") != NULL)
  9930. {
  9931. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9932. {
  9933. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9934. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9935. }
  9936. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9937. {
  9938. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9939. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9940. }
  9941. }
  9942. if(json_object_object_get(data, "nextPeriod") != NULL)
  9943. {
  9944. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9945. {
  9946. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9947. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9948. }
  9949. else
  9950. {
  9951. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9952. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9953. }
  9954. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9955. {
  9956. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9957. {
  9958. 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")));
  9959. 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"));
  9960. }
  9961. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9962. {
  9963. 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")));
  9964. 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"));
  9965. }
  9966. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9967. {
  9968. 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")));
  9969. 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"));
  9970. }
  9971. }
  9972. else
  9973. {
  9974. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9975. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9976. }
  9977. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9978. {
  9979. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9980. {
  9981. 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")));
  9982. 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"));
  9983. }
  9984. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9985. {
  9986. 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")));
  9987. 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"));
  9988. }
  9989. }
  9990. }
  9991. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9992. {
  9993. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9994. {
  9995. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9996. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9997. }
  9998. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9999. {
  10000. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10001. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10002. }
  10003. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10004. {
  10005. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10006. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10007. }
  10008. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10009. {
  10010. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10011. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10012. }
  10013. }
  10014. }
  10015. }
  10016. }
  10017. else
  10018. {
  10019. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10020. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10021. }
  10022. }
  10023. else
  10024. {
  10025. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10026. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10027. }
  10028. json_object_put(data);
  10029. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10030. json_object_put(response);
  10031. }
  10032. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10033. {
  10034. json_object *data;
  10035. data = json_tokener_parse(tempdata);
  10036. if(!is_error(data))
  10037. {
  10038. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10039. if(json_object_object_get(data, "txId") != NULL)
  10040. {
  10041. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10042. for(int idx = 0;idx<gunTotalNumber;idx++)
  10043. {
  10044. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10045. {
  10046. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10047. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10048. if(json_object_object_get(data, "description") != NULL)
  10049. {
  10050. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10051. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10052. }
  10053. else
  10054. {
  10055. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10056. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10057. }
  10058. }
  10059. }
  10060. }
  10061. else if(json_object_object_get(data, "transactionId") != NULL)
  10062. {
  10063. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10064. for(int idx = 0;idx<gunTotalNumber;idx++)
  10065. {
  10066. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10067. {
  10068. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10069. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10070. if(json_object_object_get(data, "cost") != NULL)
  10071. {
  10072. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10073. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10074. }
  10075. else
  10076. {
  10077. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10078. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10079. }
  10080. if(json_object_object_get(data, "priceText") != NULL)
  10081. {
  10082. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10083. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10084. }
  10085. else
  10086. {
  10087. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10088. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10089. }
  10090. if(json_object_object_get(data, "qrCodeText") != NULL)
  10091. {
  10092. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10093. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10094. }
  10095. }
  10096. }
  10097. }
  10098. else
  10099. {
  10100. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10101. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10102. }
  10103. }
  10104. else
  10105. {
  10106. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10107. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10108. }
  10109. json_object_put(data);
  10110. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10111. json_object_put(response);
  10112. }
  10113. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10114. {
  10115. json_object *data;
  10116. data = json_tokener_parse(tempdata);
  10117. if(!is_error(data))
  10118. {
  10119. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10120. if(json_object_object_get(data, "Content_Type") != NULL)
  10121. {
  10122. 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))
  10123. {
  10124. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10125. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10126. {
  10127. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10128. }
  10129. }
  10130. else
  10131. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10132. }
  10133. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10134. }
  10135. else
  10136. {
  10137. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10138. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10139. }
  10140. json_object_put(data);
  10141. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10142. json_object_put(response);
  10143. }
  10144. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10145. {
  10146. json_object *data;
  10147. data = json_tokener_parse(tempdata);
  10148. if(!is_error(data))
  10149. {
  10150. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10151. if(json_object_object_get(data, "ConnectorId") != NULL)
  10152. {
  10153. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10154. }
  10155. if(json_object_object_get(data, "SerialNo") != NULL)
  10156. {
  10157. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10158. }
  10159. if(json_object_object_get(data, "Page_Index") != NULL)
  10160. {
  10161. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10162. }
  10163. if(json_object_object_get(data, "Duration") != NULL)
  10164. {
  10165. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10166. }
  10167. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10168. }
  10169. else
  10170. {
  10171. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10172. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10173. }
  10174. json_object_put(data);
  10175. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10176. json_object_put(response);
  10177. }
  10178. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10179. {
  10180. json_object *data;
  10181. data = json_tokener_parse(tempdata);
  10182. if(!is_error(data))
  10183. {
  10184. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10185. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10186. {
  10187. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10188. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10189. else
  10190. {
  10191. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10192. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10193. }
  10194. }
  10195. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10196. {
  10197. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10198. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10199. else
  10200. {
  10201. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10202. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10203. }
  10204. }
  10205. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10206. {
  10207. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10208. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10209. else
  10210. {
  10211. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10212. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10213. }
  10214. }
  10215. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10216. {
  10217. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10218. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10219. else
  10220. {
  10221. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10222. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10223. }
  10224. }
  10225. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10226. {
  10227. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10228. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10229. else
  10230. {
  10231. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10232. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10233. }
  10234. }
  10235. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10236. {
  10237. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10238. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10239. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10240. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10241. else
  10242. {
  10243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10244. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10245. }
  10246. }
  10247. if(json_object_object_get(data, "isAuthentication") != NULL)
  10248. {
  10249. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10250. {
  10251. case 0:
  10252. case 1:
  10253. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10254. break;
  10255. default:
  10256. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10257. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10258. break;
  10259. }
  10260. }
  10261. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10262. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10263. }
  10264. else
  10265. {
  10266. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10267. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10268. }
  10269. json_object_put(data);
  10270. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10271. json_object_put(response);
  10272. }
  10273. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10274. {
  10275. json_object *data;
  10276. data = json_tokener_parse(tempdata);
  10277. if(!is_error(data))
  10278. {
  10279. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10280. {
  10281. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10282. {
  10283. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10284. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10285. }
  10286. else
  10287. {
  10288. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10289. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10290. }
  10291. }
  10292. else
  10293. {
  10294. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10295. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10296. }
  10297. }
  10298. else
  10299. {
  10300. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10301. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10302. }
  10303. json_object_put(data);
  10304. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10305. json_object_put(response);
  10306. }
  10307. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10308. {
  10309. json_object *data;
  10310. data = json_tokener_parse(tempdata);
  10311. if(!is_error(data))
  10312. {
  10313. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10314. if(json_object_object_get(data, "stationName") != NULL)
  10315. {
  10316. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10317. }
  10318. else
  10319. {
  10320. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10321. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10322. }
  10323. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10324. {
  10325. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10326. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10327. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10328. }
  10329. }
  10330. else
  10331. {
  10332. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10333. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10334. }
  10335. json_object_put(data);
  10336. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10337. json_object_put(response);
  10338. }
  10339. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10340. {
  10341. json_object *data;
  10342. data = json_tokener_parse(tempdata);
  10343. if(!is_error(data))
  10344. {
  10345. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10346. if(json_object_object_get(data, "weatherId") != NULL)
  10347. {
  10348. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10349. }
  10350. else
  10351. {
  10352. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10353. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10354. }
  10355. if(json_object_object_get(data, "Temperature") != NULL)
  10356. {
  10357. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10358. }
  10359. else
  10360. {
  10361. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10362. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10363. }
  10364. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10365. {
  10366. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10367. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10368. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10369. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10370. );
  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("weather_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_TriggerCreditReader") != 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_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10390. {
  10391. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10392. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10393. }
  10394. else
  10395. {
  10396. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10397. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10398. }
  10399. }
  10400. else
  10401. {
  10402. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10403. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10404. }
  10405. json_object_put(data);
  10406. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10407. json_object_put(response);
  10408. }
  10409. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10410. {
  10411. json_object *data;
  10412. data = json_tokener_parse(tempdata);
  10413. if(!is_error(data))
  10414. {
  10415. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10416. {
  10417. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10418. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10419. if(gun_index < gunTotalNumber)
  10420. {
  10421. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10422. {
  10423. json_object *responsedata = json_object_new_object();
  10424. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10425. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10426. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10427. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10428. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10429. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10430. }
  10431. else
  10432. {
  10433. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10434. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10435. }
  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 is invalid."));
  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("Configuration content something wrong."));
  10447. }
  10448. }
  10449. else
  10450. {
  10451. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10452. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10453. }
  10454. json_object_put(data);
  10455. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10456. json_object_put(response);
  10457. }
  10458. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10459. {
  10460. json_object *data;
  10461. data = json_tokener_parse(tempdata);
  10462. if(!is_error(data))
  10463. {
  10464. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10465. int gun_index = 0;
  10466. if(json_object_object_get(data, "ConnectorId") != NULL)
  10467. {
  10468. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10469. if(json_object_object_get(data, "occupancySN") != NULL)
  10470. {
  10471. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10472. }
  10473. else
  10474. {
  10475. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10476. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10477. }
  10478. if(json_object_object_get(data, "actionId") != NULL)
  10479. {
  10480. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10481. }
  10482. else
  10483. {
  10484. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10485. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10486. }
  10487. }
  10488. else
  10489. {
  10490. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10491. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  10492. }
  10493. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10494. {
  10495. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10496. }
  10497. }
  10498. else
  10499. {
  10500. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10501. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  10502. }
  10503. json_object_put(data);
  10504. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10505. json_object_put(response);
  10506. }
  10507. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10508. {
  10509. json_object *data;
  10510. data = json_tokener_parse(tempdata);
  10511. if(!is_error(data))
  10512. {
  10513. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10514. if(json_object_object_get(data, "price") != NULL)
  10515. {
  10516. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10517. }
  10518. else
  10519. {
  10520. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10521. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  10522. }
  10523. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10524. {
  10525. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10526. }
  10527. }
  10528. else
  10529. {
  10530. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10531. json_object_object_add(response, "data", json_object_new_string("SetOccupancyPrice content got something wrong."));
  10532. }
  10533. json_object_put(data);
  10534. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10535. json_object_put(response);
  10536. }
  10537. // Support ISO-15118 related message
  10538. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10539. {
  10540. char cmdBuf[1024]={0};
  10541. 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);
  10542. system(cmdBuf);
  10543. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10544. json_object *responsedata = json_object_new_object();
  10545. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10546. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10547. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10548. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10549. json_object_put(response);
  10550. }
  10551. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10552. {
  10553. json_object *data;
  10554. data = json_tokener_parse(tempdata);
  10555. if(!is_error(data))
  10556. {
  10557. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10558. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10559. fclose(fp);
  10560. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10561. json_object *responsedata = json_object_new_object();
  10562. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10563. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10564. else
  10565. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10566. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10567. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10568. }
  10569. else
  10570. {
  10571. json_object *responsedata = json_object_new_object();
  10572. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10573. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10574. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  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. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10581. {
  10582. json_object *data;
  10583. data = json_tokener_parse(tempdata);
  10584. DEBUG_INFO("DeleteCertificate processing...\n");
  10585. if(!is_error(data))
  10586. {
  10587. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10588. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10589. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10590. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10591. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10592. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10593. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10594. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10595. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10596. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10597. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10598. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10599. char temp[256] = {0};
  10600. char compareData[256] = {0};
  10601. int isMatch = TRUE;
  10602. // Check certV2G
  10603. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10604. {
  10605. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10606. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10607. isMatch = FALSE;
  10608. if(isMatch == TRUE)
  10609. {
  10610. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10611. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10612. isMatch = FALSE;
  10613. }
  10614. if(isMatch == TRUE)
  10615. {
  10616. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10617. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10618. isMatch = FALSE;
  10619. }
  10620. if(isMatch == TRUE)
  10621. {
  10622. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10623. system(temp);
  10624. json_object *responsedata = json_object_new_object();
  10625. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10626. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10627. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10628. }
  10629. else
  10630. {
  10631. json_object *responsedata = json_object_new_object();
  10632. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10633. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10634. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10635. }
  10636. }
  10637. else
  10638. {
  10639. json_object *responsedata = json_object_new_object();
  10640. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10641. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10642. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10643. }
  10644. }
  10645. else
  10646. {
  10647. json_object *responsedata = json_object_new_object();
  10648. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10649. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10650. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10651. }
  10652. json_object_put(data);
  10653. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10654. json_object_put(response);
  10655. }
  10656. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10657. {
  10658. json_object *data;
  10659. data = json_tokener_parse(tempdata);
  10660. if(!is_error(data))
  10661. {
  10662. /*
  10663. * TODO:
  10664. * 1. Query certificate to response
  10665. */
  10666. json_object *responsedata = json_object_new_object();
  10667. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10668. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10669. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10670. }
  10671. else
  10672. {
  10673. json_object *responsedata = json_object_new_object();
  10674. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10675. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10676. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10677. }
  10678. json_object_put(data);
  10679. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10680. json_object_put(response);
  10681. }
  10682. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10683. {
  10684. json_object *data;
  10685. data = json_tokener_parse(tempdata);
  10686. if(!is_error(data))
  10687. {
  10688. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10689. if(json_object_object_get(data, "certificateType") != NULL)
  10690. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10691. if(json_object_object_get(data, "certificate") != NULL)
  10692. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10693. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10694. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10695. char temp[1024];
  10696. FILE *fp = fopen(tempCert, "w");
  10697. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10698. fclose(fp);
  10699. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10700. char strExpDate[30];
  10701. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10702. fp = popen(temp, "r");
  10703. if(fp)
  10704. {
  10705. while(fgets(temp, sizeof(temp), fp) != NULL)
  10706. {
  10707. if(strstr(temp, "notAfter=") != NULL)
  10708. {
  10709. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10710. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10711. break;
  10712. }
  10713. }
  10714. }
  10715. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10716. struct tm tmExpDate;
  10717. struct timeb tbExpDate;
  10718. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10719. tbExpDate.time = mktime(&tmExpDate);
  10720. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10721. {
  10722. DEBUG_INFO("The enddate is already expired...\n");
  10723. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10724. }
  10725. else
  10726. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10727. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10728. {
  10729. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10730. {
  10731. if(access(ROOTCA_V2G,F_OK) != -1)
  10732. {
  10733. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10734. rename(ROOTCA_V2G, "/Storage/rootCaV2g_fallback.pem");
  10735. rename(tempCert, ROOTCA_V2G);
  10736. }
  10737. else
  10738. {
  10739. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10740. rename(tempCert, ROOTCA_V2G);
  10741. }
  10742. json_object *responsedata = json_object_new_object();
  10743. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10744. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10745. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10746. }
  10747. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10748. {
  10749. if(access(ROOTCA_MO,F_OK) != -1)
  10750. {
  10751. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10752. rename(ROOTCA_MO, "/Storage/rootCaMo_fallback.pem");
  10753. rename(tempCert, ROOTCA_MO);
  10754. }
  10755. else
  10756. {
  10757. DEBUG_INFO("No existed MORootCertificate. Creating...\n");
  10758. rename(tempCert, ROOTCA_MO);
  10759. }
  10760. json_object *responsedata = json_object_new_object();
  10761. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10762. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10763. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10764. }
  10765. else
  10766. {
  10767. json_object *responsedata = json_object_new_object();
  10768. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10769. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10770. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10771. }
  10772. }
  10773. else
  10774. {
  10775. json_object *responsedata = json_object_new_object();
  10776. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10777. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10778. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10779. }
  10780. }
  10781. else
  10782. {
  10783. json_object *responsedata = json_object_new_object();
  10784. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10785. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10786. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10787. }
  10788. json_object_put(data);
  10789. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10790. json_object_put(response);
  10791. }
  10792. else
  10793. {
  10794. // Can not find valid message id
  10795. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10796. }
  10797. }
  10798. else
  10799. {
  10800. // Payload is null
  10801. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10802. }
  10803. LWS_Send(message);
  10804. return result;
  10805. }
  10806. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10807. {
  10808. mtrace();
  10809. int result = FAIL;
  10810. int connectorIdInt, durationInt;
  10811. char chargingRateUnitStr[4]={0};
  10812. char comfirmstr[20];
  10813. int confirmPeriods = 0;
  10814. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10815. json_object *GetCompositeSchedule;
  10816. GetCompositeSchedule = json_tokener_parse(payload);
  10817. if(!is_error(GetCompositeSchedule))
  10818. {
  10819. // Required data
  10820. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10821. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10822. else
  10823. connectorIdInt = -1;
  10824. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10825. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10826. else
  10827. durationInt = 86400;
  10828. // Optional data
  10829. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10830. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10831. }
  10832. json_object_put(GetCompositeSchedule);
  10833. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10834. if((connectorIdInt == 0) ||
  10835. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10836. {
  10837. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10838. struct StructChargingProfile tmpProfile[1];
  10839. if(strstr(chargingRateUnitStr, "W") != NULL)
  10840. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10841. else
  10842. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10843. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10844. {
  10845. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10846. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10847. }
  10848. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10849. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10850. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10851. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10852. {
  10853. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10854. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10855. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10856. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10857. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10858. {
  10859. confirmPeriods = idx;
  10860. break;
  10861. }
  10862. }
  10863. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10864. {
  10865. confirmPeriods += 1;
  10866. }
  10867. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10868. }
  10869. else
  10870. {
  10871. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10872. }
  10873. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10874. return result;
  10875. }
  10876. int handleGetConfigurationRequest(char *uuid, char *payload)
  10877. {
  10878. mtrace();
  10879. int result = FAIL;
  10880. int MaxKeySupported = 0;
  10881. int n_keys = 0;
  10882. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10883. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10884. json_object *GetConfiguration;
  10885. GetConfiguration = json_tokener_parse(payload);
  10886. if(!is_error(GetConfiguration))
  10887. {
  10888. // Optional data
  10889. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10890. {
  10891. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10892. {
  10893. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10894. n_keys = idx + 1;
  10895. }
  10896. }
  10897. }
  10898. json_object_put(GetConfiguration);
  10899. UnknownKeynum = 0;
  10900. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10901. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10902. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10903. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10904. if(n_keys != 0)
  10905. {
  10906. for(int i=0;i<n_keys;i++)
  10907. {
  10908. getKeyValue(requestKey[i]);
  10909. }
  10910. }
  10911. else
  10912. {
  10913. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10914. getKeyValue("");
  10915. }
  10916. processUnkownKey();
  10917. sendGetConfigurationConfirmation(uuid);
  10918. return result;
  10919. }
  10920. static char fnamePlusPath[100]={0};
  10921. static char fnamePWithNoPath[60]={0};
  10922. void checkUploadLog(void)
  10923. {
  10924. FILE *fp;
  10925. /* Open the command for reading. */
  10926. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10927. if (fp == NULL) {
  10928. DEBUG_WARN("Failed to run command\n" );
  10929. exit(1);
  10930. }
  10931. int ftppathlen = 0;
  10932. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10933. int i = 0;
  10934. /* Read the output a line at a time - output it. */
  10935. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10936. if(i==0)
  10937. {
  10938. ftppathlen = strlen(fnamePlusPath);
  10939. DEBUG_INFO("%s\n", fnamePlusPath);
  10940. fnamePlusPath[ftppathlen]='\0';
  10941. break;
  10942. }
  10943. i= i+1;
  10944. }
  10945. /* close */
  10946. pclose(fp);
  10947. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10948. {
  10949. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10950. {
  10951. fnamePlusPath[k]='\0';
  10952. }
  10953. }
  10954. i=1;
  10955. //char fname[60]={0};
  10956. while(i < ftppathlen)
  10957. {
  10958. int len=ftppathlen-i;
  10959. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10960. {
  10961. DEBUG_INFO("compare '/' all right\n");
  10962. break;
  10963. }
  10964. i=i+1;
  10965. }
  10966. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10967. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10968. fnamePWithNoPath[i+1] = '\0';
  10969. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10970. {
  10971. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10972. {
  10973. fnamePWithNoPath[j]='\0';
  10974. }
  10975. }
  10976. FILE* fp1 = fopen(fnamePlusPath, "r");
  10977. if (fp1)
  10978. {
  10979. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10980. // file exists
  10981. fclose(fp1);
  10982. }
  10983. else
  10984. {
  10985. // file doesn't exist
  10986. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10987. }
  10988. }
  10989. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10990. {
  10991. mtrace();
  10992. int result = FAIL;
  10993. time_t CurrentTime;
  10994. struct tm *tm;
  10995. pthread_t th_Status;
  10996. CurrentTime = time(NULL);
  10997. tm = localtime(&CurrentTime);
  10998. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10999. 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);
  11000. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11001. if(!interLock.isGetDiagnosticGoing)
  11002. {
  11003. interLock.isGetDiagnosticGoing = 1;
  11004. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11005. sleep(1);
  11006. }
  11007. else
  11008. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11009. return result;
  11010. }
  11011. void* GetDiagnosticsProcess(void* data)
  11012. {
  11013. pthread_detach(pthread_self());
  11014. mtrace();
  11015. int retriesInt=0, retryIntervalInt=0;
  11016. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11017. 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};
  11018. int port=0;
  11019. int isSuccess = FALSE;
  11020. char cmdBuf[2048];
  11021. struct tm *tmNow;
  11022. time_t CurrentTime;
  11023. struct tm tmStart;
  11024. struct tm tmStop;
  11025. CurrentTime = time(NULL);
  11026. tmNow=localtime(&CurrentTime);
  11027. uint16_t targetYear, targetMonth;
  11028. json_object *GetDiagnostics;
  11029. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11030. GetDiagnostics = json_tokener_parse(data);
  11031. if(!is_error(GetDiagnostics))
  11032. {
  11033. // Required data
  11034. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11035. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11036. // Optional data
  11037. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11038. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11039. else
  11040. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11041. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11042. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11043. else
  11044. retryIntervalInt = 30;
  11045. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11046. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11047. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11048. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11049. }
  11050. json_object_put(GetDiagnostics);
  11051. // Notify CSU to get log of dispensers.
  11052. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  11053. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  11054. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  11055. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  11056. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  11057. )
  11058. {
  11059. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StartTime,"%s",startTimestr);
  11060. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StopTime,"%s",stopTimestr);
  11061. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = TRUE;
  11062. struct timespec timerGetDiagnostics;
  11063. refreshStartTimer(&timerGetDiagnostics);
  11064. while(ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq != FALSE)
  11065. {
  11066. if(getDiffSecNow(timerGetDiagnostics)>=180)
  11067. {
  11068. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = FALSE;
  11069. DEBUG_INFO("Waiting log of dispenser timeout.");
  11070. }
  11071. }
  11072. }
  11073. // Pack log to compress file
  11074. 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) &&
  11075. (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))
  11076. {
  11077. // Pack system log
  11078. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11079. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11080. targetYear = tmStart.tm_year;
  11081. targetMonth = tmStart.tm_mon;
  11082. do
  11083. {
  11084. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11085. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11086. if(targetMonth+1>=13)
  11087. {
  11088. targetYear += 1;
  11089. targetMonth = 1;
  11090. }
  11091. else
  11092. {
  11093. targetMonth += 1;
  11094. }
  11095. }while((targetYear < (tmNow->tm_year+1900)) ||
  11096. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11097. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11098. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11099. sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
  11100. sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
  11101. sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
  11102. system(cmdBuf);
  11103. // Pack charging & event log
  11104. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11105. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11106. targetYear = tmStart.tm_year;
  11107. targetMonth = tmStart.tm_mon;
  11108. do
  11109. {
  11110. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11111. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  11112. if(targetMonth+1>=13)
  11113. {
  11114. targetYear += 1;
  11115. targetMonth = 1;
  11116. }
  11117. else
  11118. {
  11119. targetMonth += 1;
  11120. }
  11121. }while((targetYear < (tmNow->tm_year+1900)) ||
  11122. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11123. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11124. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11125. system(cmdBuf);
  11126. // Combine log file
  11127. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11128. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11129. }
  11130. else
  11131. {
  11132. system("exec /root/logPackTools 'log' 6");
  11133. }
  11134. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11135. system(cmdBuf);
  11136. checkUploadLog();
  11137. //****************location*******************/
  11138. if(strcmp(locationstr,"")==0)
  11139. {
  11140. DEBUG_INFO("location is <Empty>!\n");
  11141. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11142. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11143. goto end;
  11144. }
  11145. memset(protocol, 0, ARRAY_SIZE(protocol));
  11146. memset(user, 0, ARRAY_SIZE(user) );
  11147. memset(password, 0, ARRAY_SIZE(password));
  11148. memset(host, 0, ARRAY_SIZE(host));
  11149. memset(path, 0, ARRAY_SIZE(path));
  11150. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11151. memset(host1, 0, ARRAY_SIZE(host1));
  11152. memset(path1, 0, ARRAY_SIZE(path1));
  11153. /*location: ftp://user:password@host:port/path*/
  11154. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11155. if((access(fnamePlusPath,F_OK))!=-1)
  11156. {
  11157. DEBUG_INFO("fnamePlusPath exist.\n");
  11158. }
  11159. else
  11160. {
  11161. DEBUG_INFO("fnamePlusPath not exist!\n");
  11162. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11163. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11164. goto end;
  11165. }
  11166. if(strchr(locationstr,'@')==NULL)
  11167. {
  11168. sscanf(locationstr,
  11169. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11170. protocol, host, &port, path);
  11171. strcpy(user,"anonymous");
  11172. strcpy(password,"");
  11173. }
  11174. else
  11175. {
  11176. //DEBUG_INFO("pch=%s\n", pch);
  11177. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11178. protocol, user, password, host, &port, path);
  11179. }
  11180. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11181. {
  11182. DEBUG_INFO("protocol is not ftp/http ! \n");
  11183. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11184. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11185. goto end;
  11186. }
  11187. if(strncmp(locationstr,"http", 4) == 0)
  11188. {
  11189. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11190. sprintf(ftppath,"/%s", path);
  11191. do
  11192. {
  11193. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11194. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11195. sleep(3);
  11196. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11197. if(!isSuccess)
  11198. {
  11199. DEBUG_INFO("Diagnostics fail.\n");
  11200. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11201. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11202. sleep(retryIntervalInt);
  11203. }
  11204. else
  11205. {
  11206. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11207. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11208. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11209. }
  11210. retriesInt--;
  11211. }while((isSuccess == 0)&&(retriesInt >= 0));
  11212. }
  11213. else
  11214. {
  11215. sscanf(host,"%[^/]%s",host1, path1);
  11216. if(strlen(path) > 0)
  11217. sprintf(ftppath,"/%s", path);
  11218. else
  11219. sprintf(ftppath,"/%s", path1);
  11220. int ftppathlen=strlen(ftppath);
  11221. int i=1;
  11222. char filenametemp[50];
  11223. while(i < ftppathlen)
  11224. {
  11225. int len=ftppathlen-i;
  11226. if(ftppath[len]== 47) // '/' ascll code: 47
  11227. {
  11228. DEBUG_INFO("find '/' all right\n");
  11229. break;
  11230. }
  11231. i=i+1;
  11232. }
  11233. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11234. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11235. filenametemp[i+1] = 0;
  11236. if(port == 0)
  11237. port = 21;
  11238. do
  11239. {
  11240. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11242. sleep(3);
  11243. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11244. if(!isSuccess)
  11245. {
  11246. DEBUG_INFO("Diagnostics fail.\n");
  11247. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11248. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11249. sleep(retryIntervalInt);
  11250. }
  11251. else
  11252. {
  11253. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11254. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11255. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11256. }
  11257. retriesInt--;
  11258. }while((!isSuccess)&&(retriesInt >= 0));
  11259. }
  11260. end:
  11261. system("rm -f /mnt/*");
  11262. sleep(5);
  11263. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11264. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11265. interLock.isGetDiagnosticGoing = 0;
  11266. pthread_exit(NULL);
  11267. }
  11268. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11269. {
  11270. mtrace();
  11271. int result = FAIL;
  11272. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11273. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11274. {
  11275. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11276. locallistVersion = -1;
  11277. }
  11278. else
  11279. {
  11280. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11281. locallistVersion = 0;
  11282. OCPP_getListVerion();
  11283. }
  11284. //from db.OCPP_getListVerion
  11285. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11286. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11287. sendGetLocalListVersionConfirmation(uuid,"");
  11288. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11289. return result;
  11290. }
  11291. int handleRemoteStartRequest(char *uuid, char *payload)
  11292. {
  11293. mtrace();
  11294. int result = PASS;
  11295. int connectorIdInt=-1;
  11296. int tempIndex = 0;
  11297. char comfirmstr[20]={0};
  11298. char cmdBuf[512];
  11299. json_object *RemoteStartTransaction;
  11300. FILE *fp;
  11301. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11302. if(server_pending == TRUE)
  11303. {
  11304. result = FAIL;
  11305. }
  11306. RemoteStartTransaction = json_tokener_parse(payload);
  11307. if(!is_error(RemoteStartTransaction))
  11308. {
  11309. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11310. {
  11311. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11312. }
  11313. else
  11314. {
  11315. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11316. {
  11317. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11318. {
  11319. connectorIdInt = (gun_index+1);
  11320. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11321. break;
  11322. }
  11323. }
  11324. }
  11325. if(connectorIdInt == 0)
  11326. {
  11327. DEBUG_WARN("Connector id shall not equal 0.\n");
  11328. result = FAIL;
  11329. }
  11330. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11331. {
  11332. DEBUG_WARN("idTag should not be NULL.\n");
  11333. result = FAIL;
  11334. }
  11335. else if(connectorIdInt == -1)
  11336. {
  11337. DEBUG_INFO("Connector id does not specific.\n");
  11338. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11339. {
  11340. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11341. // Required data
  11342. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11343. // Optional data
  11344. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11345. {
  11346. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11347. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11348. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11349. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11350. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11351. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11352. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11353. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11354. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11355. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11356. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11357. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11358. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11359. {
  11360. 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")));
  11361. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11362. 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"));
  11363. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11364. 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"));
  11365. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11366. 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")));
  11367. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11368. {
  11369. 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++)
  11370. {
  11371. 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"));
  11372. 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"));
  11373. 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)
  11374. 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"));
  11375. }
  11376. }
  11377. }
  11378. }
  11379. else
  11380. {
  11381. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11382. }
  11383. }
  11384. }
  11385. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11386. {
  11387. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11388. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11389. // Required data
  11390. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11391. // Optional data
  11392. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11393. {
  11394. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11395. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11396. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11397. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11398. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11399. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11400. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11401. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11402. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11403. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11404. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11405. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11406. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11407. {
  11408. 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")));
  11409. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11410. 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"));
  11411. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11412. 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"));
  11413. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11414. 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")));
  11415. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11416. {
  11417. 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++)
  11418. {
  11419. 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"));
  11420. 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"));
  11421. 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)
  11422. 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"));
  11423. }
  11424. }
  11425. }
  11426. }
  11427. else
  11428. {
  11429. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11430. }
  11431. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') && (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W'))
  11432. {
  11433. DEBUG_INFO("Checking charging status for DW series...\n");
  11434. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11435. {
  11436. if(cpinitateMsg.bits[gun_index].isOnCharging ||
  11437. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL) ||
  11438. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing") != NULL))
  11439. {
  11440. DEBUG_INFO("Found gun-%d is in charging.\n", gun_index);
  11441. if(connectorIdInt != (gun_index+1))
  11442. {
  11443. DEBUG_WARN("DWseries--> Other connector is in charging.\n");
  11444. result = FAIL;
  11445. break;
  11446. }
  11447. }
  11448. }
  11449. }
  11450. }
  11451. else
  11452. {
  11453. DEBUG_WARN("Connector id is over maximun value.\n");
  11454. result = FAIL;
  11455. }
  11456. }
  11457. if(result == PASS)
  11458. {
  11459. if(connectorIdInt > 0)
  11460. {
  11461. DEBUG_INFO("Specified gun-%d type: %d\n", (connectorIdInt -1), gunType[connectorIdInt -1]);
  11462. //check Transaction active
  11463. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11464. {
  11465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11466. {
  11467. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11468. }
  11469. else
  11470. {
  11471. tempIndex = connectorIdInt -1;
  11472. }
  11473. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11474. {
  11475. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11476. {
  11477. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11478. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11479. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11480. {
  11481. //Reserved
  11482. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11483. }
  11484. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11485. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11486. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11487. {
  11488. //Reserved
  11489. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11490. {
  11491. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11492. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11493. goto end;
  11494. }
  11495. }
  11496. else
  11497. {
  11498. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11499. {
  11500. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11501. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11502. goto end;
  11503. }
  11504. }//END FOR ELSE
  11505. }
  11506. }// END FOR CHAdeMO_QUANTITY
  11507. }
  11508. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11509. {
  11510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11511. {
  11512. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11513. }
  11514. else
  11515. {
  11516. tempIndex = connectorIdInt -1;
  11517. }
  11518. for (int index = 0; index < CCS_QUANTITY; index++)
  11519. {
  11520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11521. {
  11522. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11523. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11524. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11525. {
  11526. //Reserved
  11527. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11528. }
  11529. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11530. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11531. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11532. {
  11533. //Reserved
  11534. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11535. {
  11536. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11537. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11538. goto end;
  11539. }
  11540. }
  11541. else
  11542. {
  11543. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11544. {
  11545. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11546. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11547. goto end;
  11548. }
  11549. }// END FOR ELSE
  11550. }
  11551. }// END FOR CCS_QUANTITY
  11552. }
  11553. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11554. {
  11555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11556. {
  11557. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11558. }
  11559. else
  11560. {
  11561. tempIndex = connectorIdInt -1;
  11562. }
  11563. for (int index = 0; index < GB_QUANTITY; index++)
  11564. {
  11565. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11566. {
  11567. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11568. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11569. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11570. {
  11571. //Reserved
  11572. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11573. }
  11574. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11575. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11576. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11577. {
  11578. //Reserved
  11579. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11580. {
  11581. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11582. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11583. goto end;
  11584. }
  11585. }
  11586. else
  11587. {
  11588. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11589. {
  11590. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11591. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11592. goto end;
  11593. }
  11594. }// END FOR ELSE
  11595. }
  11596. } // END FOR GB_QUANTITY
  11597. }
  11598. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11599. {
  11600. tempIndex = connectorIdInt -1;
  11601. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11602. {
  11603. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11604. {
  11605. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11606. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11607. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11608. {
  11609. //Reserved
  11610. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11611. }
  11612. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11613. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11614. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11615. {
  11616. //Reserved
  11617. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11618. {
  11619. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11620. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11621. goto end;
  11622. }
  11623. }
  11624. else
  11625. {
  11626. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11627. {
  11628. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11629. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11630. goto end;
  11631. }
  11632. }// END FOR ELSE
  11633. }
  11634. } // END FOR GB_QUANTITY
  11635. }
  11636. else
  11637. {
  11638. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11639. {
  11640. tempIndex = 2;
  11641. }
  11642. else
  11643. {
  11644. tempIndex = connectorIdInt -1;
  11645. }
  11646. for (int index = 0; index < AC_QUANTITY; index++)
  11647. {
  11648. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11649. {
  11650. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11651. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11652. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11653. {
  11654. //Reserved
  11655. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11656. }
  11657. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11658. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11659. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11660. {
  11661. //Reserved
  11662. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11663. {
  11664. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11665. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11666. goto end;
  11667. }
  11668. }
  11669. else
  11670. {
  11671. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11672. {
  11673. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11674. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11675. goto end;
  11676. }
  11677. }//END FOR ELSE
  11678. }
  11679. }// END FOR AC_QUANTITY
  11680. }
  11681. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11682. {
  11683. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11684. {
  11685. // Save profile to file
  11686. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11687. system(cmdBuf);
  11688. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11689. fp = fopen(cmdBuf, "w");
  11690. 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));
  11691. fclose(fp);
  11692. }
  11693. else
  11694. {
  11695. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11696. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11697. goto end;
  11698. }
  11699. }
  11700. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11701. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11702. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11703. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11704. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11705. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11706. }
  11707. else
  11708. {
  11709. uint8_t isHasIdleConnector = FALSE;
  11710. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11711. {
  11712. DEBUG_INFO("Check not specified gun-%d type: %d\n", gun_index, gunType[gun_index]);
  11713. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11714. {
  11715. isHasIdleConnector = TRUE;
  11716. break;
  11717. }
  11718. }
  11719. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11720. {
  11721. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11722. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11723. {
  11724. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11725. {
  11726. // Save profile to file
  11727. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11728. system(cmdBuf);
  11729. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11730. fp = fopen(cmdBuf, "w");
  11731. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11732. fclose(fp);
  11733. refreshStartTimer(&clientTime.RemoteStartWait);
  11734. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11735. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11736. }
  11737. else
  11738. {
  11739. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11740. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11741. }
  11742. }
  11743. else
  11744. {
  11745. refreshStartTimer(&clientTime.RemoteStartWait);
  11746. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11747. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11748. }
  11749. }
  11750. else
  11751. {
  11752. DEBUG_INFO("There is not any connector is idle.\n");
  11753. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11754. }
  11755. }
  11756. }
  11757. else
  11758. {
  11759. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11760. }
  11761. end:
  11762. json_object_put(RemoteStartTransaction);
  11763. sendRemoteStartConfirmation(uuid, comfirmstr);
  11764. return result;
  11765. }
  11766. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11767. {
  11768. mtrace();
  11769. int result = FAIL;
  11770. int match = FALSE;
  11771. int GunNO = 0;
  11772. int tempIndex = 0;
  11773. int transactionIdInt=0;
  11774. int transactionIdIsNULL= TRUE;
  11775. char comfirmstr[20];
  11776. json_object *RemoteStopTransaction;
  11777. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11778. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11779. if(server_pending == TRUE)
  11780. {
  11781. return 0;
  11782. }
  11783. RemoteStopTransaction = json_tokener_parse(payload);
  11784. if(!is_error(RemoteStopTransaction))
  11785. {
  11786. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11787. {
  11788. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11789. transactionIdIsNULL = FALSE;
  11790. }
  11791. }
  11792. json_object_put(RemoteStopTransaction);
  11793. if(transactionIdIsNULL == FALSE)
  11794. {
  11795. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11796. {
  11797. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11798. {
  11799. //check Transaction active
  11800. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11801. {
  11802. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11803. {
  11804. tempIndex = ((gun_index==2) ? 1: 0);
  11805. }
  11806. else
  11807. {
  11808. tempIndex = gun_index;
  11809. }
  11810. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11811. {
  11812. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11813. {
  11814. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11815. {
  11816. match = TRUE;
  11817. GunNO = gun_index;
  11818. }
  11819. }
  11820. }// END FOR CHAdeMO_QUANTITY
  11821. }
  11822. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11823. {
  11824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11825. {
  11826. tempIndex = ((gun_index==2) ? 1: 0);
  11827. }
  11828. else
  11829. {
  11830. tempIndex = gun_index;
  11831. }
  11832. for (int index = 0; index < CCS_QUANTITY; index++)
  11833. {
  11834. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11835. {
  11836. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11837. {
  11838. match = TRUE;
  11839. GunNO = gun_index;
  11840. }
  11841. }
  11842. }// END FOR CCS_QUANTITY
  11843. }
  11844. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11845. {
  11846. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11847. {
  11848. tempIndex = ((gun_index==2) ? 1: 0);
  11849. }
  11850. else
  11851. {
  11852. tempIndex = gun_index;
  11853. }
  11854. for (int index = 0; index < GB_QUANTITY; index++)
  11855. {
  11856. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11857. {
  11858. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11859. {
  11860. match = TRUE;
  11861. GunNO = gun_index;
  11862. }
  11863. }
  11864. }// END FOR GB_QUANTITY
  11865. }
  11866. else if(gunType[gun_index] == GUN_TYPE_DO)
  11867. {
  11868. tempIndex = gun_index;
  11869. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11870. {
  11871. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11872. {
  11873. 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
  11874. {
  11875. match = TRUE;
  11876. GunNO = gun_index;
  11877. }
  11878. }
  11879. }// END FOR GB_QUANTITY
  11880. }
  11881. else
  11882. {
  11883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11884. {
  11885. tempIndex = 2;
  11886. }
  11887. else
  11888. {
  11889. tempIndex = gun_index;
  11890. }
  11891. for (int index = 0; index < AC_QUANTITY; index++)
  11892. {
  11893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11894. {
  11895. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11896. {
  11897. match = TRUE;
  11898. GunNO = gun_index;
  11899. }
  11900. }
  11901. }// END FOR CHAdeMO_QUANTITY
  11902. } // END FOR AC ELSE
  11903. }// CHECK IF ResponseTransactionId == transactionIdInt
  11904. }//END FOR
  11905. if( match == TRUE)
  11906. {
  11907. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11908. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11909. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11910. }
  11911. else
  11912. {
  11913. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11914. }
  11915. }
  11916. else
  11917. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11918. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11919. return result;
  11920. }
  11921. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11922. {
  11923. mtrace();
  11924. int result = FAIL;
  11925. int connectorIdInt=0, reservationIdInt=0;
  11926. int tempIndex = 0;
  11927. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11928. char comfirmstr[20]={0};
  11929. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11930. int c = 0;
  11931. char *loc;
  11932. //char *ptr;
  11933. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11934. strcpy(sstrtemp, stringtrimspace(payload));
  11935. //***(1)connectorId ****/
  11936. c=0;
  11937. loc = strstr(sstrtemp, "connectorId");
  11938. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11939. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11940. {
  11941. sstr[c] = loc[strlen("connectorId")+2+c];
  11942. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11943. c++;
  11944. }
  11945. sstr[c] = '\0';
  11946. connectorIdInt = atoi(sstr);
  11947. //***(2)expiryDate ****/
  11948. loc = strstr(sstrtemp, "expiryDate");
  11949. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11950. c = 0;
  11951. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11952. {
  11953. sstr[c] = loc[3+strlen("expiryDate")+c];
  11954. c++;
  11955. }
  11956. sstr[c] = '\0';
  11957. strcpy(expiryDatestr, sstr);
  11958. //***(3)idTag ****/
  11959. loc = strstr(sstrtemp, "idTag");
  11960. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11961. c = 0;
  11962. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11963. {
  11964. sstr[c] = loc[3+strlen("idTag")+c];
  11965. c++;
  11966. }
  11967. sstr[c] = '\0';
  11968. strcpy(idTagstr, sstr);
  11969. //***(4)parentIdTag ****/
  11970. loc = strstr(sstrtemp, "parentIdTag");
  11971. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11972. c = 0;
  11973. if(loc == NULL)
  11974. {
  11975. strcpy(parentIdTagstr, "");
  11976. }
  11977. else
  11978. {
  11979. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11980. {
  11981. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11982. c++;
  11983. }
  11984. sstr[c] = '\0';
  11985. strcpy(parentIdTagstr, sstr);
  11986. }
  11987. //***(5)reservationId ****/
  11988. c=0;
  11989. loc = strstr(sstrtemp, "reservationId");
  11990. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11991. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11992. {
  11993. sstr[c] = loc[strlen("reservationId")+2+c];
  11994. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11995. c++;
  11996. }
  11997. sstr[c] = '\0';
  11998. reservationIdInt = atoi(sstr);
  11999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12000. /*
  12001. enum SYSTEM_STATUS
  12002. {
  12003. SYS_MODE_BOOTING = 0,
  12004. SYS_MODE_IDLE = 1,
  12005. SYS_MODE_AUTHORIZING = 2,
  12006. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12007. SYS_MODE_REASSIGN = 4,
  12008. SYS_MODE_PREPARING = 5,
  12009. SYS_MODE_PREPARE_FOR_EV = 6,
  12010. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12011. SYS_MODE_CHARGING = 8,
  12012. SYS_MODE_TERMINATING = 9,
  12013. SYS_MODE_COMPLETE = 10,
  12014. SYS_MODE_ALARM = 11,
  12015. SYS_MODE_FAULT = 12,
  12016. SYS_MODE_RESERVATION = 13,
  12017. SYS_MODE_BOOKING = 14,
  12018. SYS_MODE_MAINTAIN = 15,
  12019. SYS_MODE_DEBUG = 16,
  12020. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12021. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12022. SYS_MODE_UPDATE = 19
  12023. };
  12024. */
  12025. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12026. {
  12027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12028. goto end;
  12029. }
  12030. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12031. {
  12032. //check Transaction active
  12033. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12034. {
  12035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12036. {
  12037. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12038. }
  12039. else
  12040. {
  12041. tempIndex = connectorIdInt -1;
  12042. }
  12043. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12044. {
  12045. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12046. {
  12047. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12048. {
  12049. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12050. {
  12051. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12052. {
  12053. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12054. {
  12055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12056. }
  12057. else
  12058. {
  12059. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12061. }
  12062. }
  12063. 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'))
  12064. {
  12065. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12066. }
  12067. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12068. {
  12069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12070. }
  12071. else
  12072. {
  12073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12074. }
  12075. }
  12076. 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
  12077. {
  12078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12079. }
  12080. }
  12081. else
  12082. {
  12083. //replace reservation
  12084. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12085. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12086. }
  12087. }
  12088. } // END FOR CHAdeMO_QUANTITY
  12089. }
  12090. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12091. {
  12092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12093. {
  12094. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12095. }
  12096. else
  12097. {
  12098. tempIndex = connectorIdInt -1;
  12099. }
  12100. for (int index = 0; index < CCS_QUANTITY; index++)
  12101. {
  12102. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12103. {
  12104. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12105. {
  12106. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12107. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12108. {
  12109. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12110. {
  12111. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12112. {
  12113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12114. }
  12115. else
  12116. {
  12117. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12118. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12119. }
  12120. }
  12121. 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'))
  12122. {
  12123. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12124. }
  12125. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12126. {
  12127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12128. }
  12129. else
  12130. {
  12131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12132. }
  12133. }
  12134. 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
  12135. {
  12136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12137. }
  12138. }
  12139. else
  12140. {
  12141. //replace reservation
  12142. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12143. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12144. }
  12145. }
  12146. } // END FOR CCS_QUANTITY
  12147. }
  12148. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12149. {
  12150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12151. {
  12152. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12153. }
  12154. else
  12155. {
  12156. tempIndex = connectorIdInt -1;
  12157. }
  12158. for (int index = 0; index < GB_QUANTITY; index++)
  12159. {
  12160. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12161. {
  12162. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12163. {
  12164. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12165. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12166. {
  12167. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12168. {
  12169. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12170. {
  12171. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12172. }
  12173. else
  12174. {
  12175. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12176. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12177. }
  12178. }
  12179. 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'))
  12180. {
  12181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12182. }
  12183. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12184. {
  12185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12186. }
  12187. else
  12188. {
  12189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12190. }
  12191. }
  12192. 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
  12193. {
  12194. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12195. }
  12196. }
  12197. else
  12198. {
  12199. //replace reservation
  12200. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12201. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12202. }
  12203. }
  12204. }// END FOR GB_QUANTITY
  12205. }
  12206. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12207. {
  12208. tempIndex = connectorIdInt -1;
  12209. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12210. {
  12211. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12212. {
  12213. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12214. {
  12215. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12216. 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
  12217. {
  12218. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12219. {
  12220. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12221. {
  12222. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12223. }
  12224. else
  12225. {
  12226. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12227. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12228. }
  12229. }
  12230. 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'))
  12231. {
  12232. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12233. }
  12234. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12235. {
  12236. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12237. }
  12238. else
  12239. {
  12240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12241. }
  12242. }
  12243. 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
  12244. {
  12245. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12246. }
  12247. }
  12248. else
  12249. {
  12250. //replace reservation
  12251. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12252. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12253. }
  12254. }
  12255. }// END FOR GB_QUANTITY
  12256. }
  12257. else
  12258. {
  12259. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12260. {
  12261. tempIndex = 2;
  12262. }
  12263. else
  12264. {
  12265. tempIndex = (connectorIdInt -1);
  12266. }
  12267. for (int index = 0; index < AC_QUANTITY; index++)
  12268. {
  12269. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12270. {
  12271. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12272. {
  12273. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12274. {
  12275. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12276. {
  12277. 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))
  12278. {
  12279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12280. }
  12281. else
  12282. {
  12283. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12285. }
  12286. }
  12287. 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'))
  12288. {
  12289. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12290. }
  12291. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12292. {
  12293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12294. }
  12295. else
  12296. {
  12297. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12298. }
  12299. }
  12300. 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
  12301. {
  12302. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12303. }
  12304. }
  12305. else
  12306. {
  12307. //replace reservation
  12308. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12309. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12310. }
  12311. }
  12312. } // END FOR AC_QUANTITY
  12313. }
  12314. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12315. }
  12316. else if(connectorIdInt == 0)
  12317. {
  12318. //check Transaction active
  12319. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12320. {
  12321. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12322. {
  12323. 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'))
  12324. {
  12325. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12326. goto end;
  12327. }
  12328. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12329. {
  12330. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12331. goto end;
  12332. }
  12333. 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
  12334. {
  12335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12336. goto end;
  12337. }
  12338. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12339. {
  12340. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12341. goto end;
  12342. }
  12343. }
  12344. }// END FOR CHAdeMO_QUANTITY
  12345. for (int index = 0; index < CCS_QUANTITY; index++)
  12346. {
  12347. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12348. {
  12349. 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'))
  12350. {
  12351. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12352. goto end;
  12353. }
  12354. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12355. {
  12356. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12357. goto end;
  12358. }
  12359. 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
  12360. {
  12361. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12362. goto end;
  12363. }
  12364. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12365. {
  12366. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12367. goto end;
  12368. }
  12369. }
  12370. } // END FOR CCS_QUANTITY
  12371. for (int index = 0; index < GB_QUANTITY; index++)
  12372. {
  12373. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12374. {
  12375. 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'))
  12376. {
  12377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12378. goto end;
  12379. }
  12380. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12381. {
  12382. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12383. goto end;
  12384. }
  12385. 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
  12386. {
  12387. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12388. goto end;
  12389. }
  12390. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12391. {
  12392. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12393. goto end;
  12394. }
  12395. }
  12396. } // END FOR GB_QUANTITY
  12397. for (int index = 0; index < AC_QUANTITY; index++)
  12398. {
  12399. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12400. {
  12401. 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'))
  12402. {
  12403. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12404. goto end;
  12405. }
  12406. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12407. {
  12408. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12409. goto end;
  12410. }
  12411. 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
  12412. {
  12413. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12414. goto end;
  12415. }
  12416. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12417. {
  12418. 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))
  12419. {
  12420. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12421. goto end;
  12422. }
  12423. }
  12424. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12425. {
  12426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12427. goto end;
  12428. }
  12429. }
  12430. }// END FOR AC_QUANTITY
  12431. //The connectorId is 0
  12432. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12433. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12434. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12435. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12436. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12437. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12438. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12439. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12440. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12441. result = TRUE;
  12442. return result;
  12443. }
  12444. else
  12445. {
  12446. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12447. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12448. }
  12449. if(strcmp(comfirmstr,"Accepted") == 0)
  12450. {
  12451. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12452. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12453. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12454. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12455. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12456. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12457. result = TRUE;
  12458. return result;
  12459. }
  12460. end:
  12461. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12462. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12463. return result;
  12464. }
  12465. int handleResetRequest(char *uuid, char *payload)
  12466. {
  12467. mtrace();
  12468. int result = FAIL;
  12469. char sstr[10]={0},sstrtemp[30]={ 0 };
  12470. char typestr[10]={0};
  12471. char comfirmstr[20]={0};
  12472. int c = 0;
  12473. char *loc;
  12474. DEBUG_INFO("handleResetRequest...\n");
  12475. strcpy(sstrtemp, stringtrimspace(payload));
  12476. loc = strstr(sstrtemp, "type");
  12477. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12478. c = 0;
  12479. while (loc[3+strlen("type")+c] != '\"')
  12480. {
  12481. sstr[c] = loc[3+strlen("type")+c];
  12482. c++;
  12483. }
  12484. sstr[c] = '\0';
  12485. strcpy(typestr,sstr);
  12486. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12487. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12488. {
  12489. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12490. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12491. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12492. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12493. }
  12494. else
  12495. {
  12496. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12497. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12498. result = PASS;
  12499. }
  12500. sendResetConfirmation(uuid, comfirmstr);
  12501. return result;
  12502. }
  12503. int handleSendLocalListRequest(char *uuid, char *payload)
  12504. {
  12505. mtrace();
  12506. int result = FAIL;
  12507. char comfirmstr[20];
  12508. int checkState_Faulted = FALSE;
  12509. json_object *SendLocalList;
  12510. DEBUG_INFO("handleSendLocalListRequest...\n");
  12511. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12512. {
  12513. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12514. goto end;
  12515. }
  12516. //check Charge Point state
  12517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12518. {
  12519. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12520. {
  12521. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12522. }
  12523. }
  12524. for (int index = 0; index < CCS_QUANTITY; index++)
  12525. {
  12526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12527. {
  12528. checkState_Faulted = TRUE; //OCPP Status
  12529. }
  12530. }
  12531. for (int index = 0; index < GB_QUANTITY; index++)
  12532. {
  12533. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12534. {
  12535. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12536. }
  12537. }
  12538. //check Charge Point state
  12539. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12540. {
  12541. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12542. {
  12543. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12544. }
  12545. }
  12546. //check Charge Point state
  12547. for (int index = 0; index < AC_QUANTITY; index++)
  12548. {
  12549. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12550. {
  12551. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12552. }
  12553. }
  12554. if(checkState_Faulted == TRUE)
  12555. {
  12556. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12557. goto end;
  12558. }
  12559. // Parsing payload
  12560. SendLocalList = json_tokener_parse(payload);
  12561. if(!is_error(SendLocalList))
  12562. {
  12563. // Required data
  12564. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12565. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12566. // Optional data
  12567. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12568. {
  12569. //Check UpdateType
  12570. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12571. {
  12572. //Local list full update
  12573. DEBUG_INFO("Local list full update.\n");
  12574. locallistVersion = 0;
  12575. OCPP_getListVerion();
  12576. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12577. {
  12578. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12579. goto end;
  12580. }
  12581. OCPP_cleanLocalList();
  12582. }
  12583. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12584. {
  12585. //Local list different update
  12586. DEBUG_INFO("Local list different update.\n");
  12587. locallistVersion = 0;
  12588. OCPP_getListVerion();
  12589. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12590. {
  12591. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12592. goto end;
  12593. }
  12594. }
  12595. else
  12596. {
  12597. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12598. goto end;
  12599. }
  12600. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12601. {
  12602. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12603. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12604. goto end;
  12605. }
  12606. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12607. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12608. {
  12609. 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"))));
  12610. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12611. {
  12612. 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"))));
  12613. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12614. 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"))));
  12615. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12616. 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"))));
  12617. }
  12618. // Add to db
  12619. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12620. {
  12621. //Local list full update
  12622. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12623. idx,
  12624. ShmOCPP16Data->SendLocalList.ListVersion,
  12625. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12626. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12627. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12628. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12629. // update list
  12630. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12631. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12632. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12633. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12634. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12635. }
  12636. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12637. {
  12638. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12639. idx,
  12640. ShmOCPP16Data->SendLocalList.ListVersion,
  12641. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12642. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12643. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12644. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12645. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12646. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12647. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12648. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12649. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12650. }
  12651. }
  12652. }
  12653. else
  12654. {
  12655. //Check UpdateType
  12656. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12657. {
  12658. //Local list full update
  12659. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12660. OCPP_cleanLocalList();
  12661. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12662. goto end;
  12663. }
  12664. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12665. {
  12666. //Local list different update
  12667. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12668. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12669. goto end;
  12670. }
  12671. }
  12672. result = PASS;
  12673. }
  12674. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12675. end:
  12676. json_object_put(SendLocalList);
  12677. sendSendLocalListConfirmation(uuid, comfirmstr);
  12678. return result;
  12679. }
  12680. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12681. {
  12682. mtrace();
  12683. int result = FAIL;
  12684. struct StructSetChargingProfile SetProfileReq = {0};
  12685. int tempchargingProfileIdInt;
  12686. int tempstackLevelInt;
  12687. int chargingSchedulePeriodCount = 0;
  12688. char comfirmstr[20]={0};
  12689. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12690. char rmFileCmd[128]={0};
  12691. int profileQuantity = 0;
  12692. int replaceableProfileCnt = 0;
  12693. json_object *SetChargingProfile;
  12694. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12695. SetChargingProfile = json_tokener_parse(payload);
  12696. if(!is_error(SetChargingProfile))
  12697. {
  12698. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12699. {
  12700. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12701. }
  12702. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12703. {
  12704. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12705. {
  12706. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12707. }
  12708. else
  12709. {
  12710. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12711. DEBUG_WARN("Cannot find chargingProfileId field.");
  12712. goto end;
  12713. }
  12714. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12715. {
  12716. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12717. }
  12718. else
  12719. {
  12720. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12721. DEBUG_WARN("Cannot find stackLevel field.");
  12722. goto end;
  12723. }
  12724. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12725. {
  12726. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12727. }
  12728. else
  12729. {
  12730. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12731. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12732. goto end;
  12733. }
  12734. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12735. {
  12736. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12737. }
  12738. else
  12739. {
  12740. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12741. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12742. goto end;
  12743. }
  12744. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12745. {
  12746. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12747. }
  12748. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12749. {
  12750. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12751. }
  12752. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12753. {
  12754. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12755. }
  12756. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12757. {
  12758. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12759. }
  12760. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12761. {
  12762. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12763. {
  12764. 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")));
  12765. }
  12766. else
  12767. {
  12768. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12769. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12770. goto end;
  12771. }
  12772. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12773. {
  12774. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12775. }
  12776. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12777. {
  12778. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12779. }
  12780. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12781. {
  12782. 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")));
  12783. }
  12784. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12785. {
  12786. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12787. if(chargingSchedulePeriodCount <= 10)
  12788. {
  12789. 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++)
  12790. {
  12791. 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)
  12792. {
  12793. 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"));
  12794. }
  12795. else
  12796. {
  12797. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12798. DEBUG_WARN("Cannot find startPeriod field.");
  12799. goto end;
  12800. }
  12801. 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)
  12802. {
  12803. 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"));
  12804. }
  12805. else
  12806. {
  12807. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12808. DEBUG_WARN("Cannot find limit field.");
  12809. goto end;
  12810. }
  12811. 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)
  12812. {
  12813. 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"));
  12814. }
  12815. }
  12816. }
  12817. }
  12818. else
  12819. {
  12820. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12821. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12822. goto end;
  12823. }
  12824. }
  12825. else
  12826. {
  12827. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12828. DEBUG_WARN("Cannot find chargingSchedule field.");
  12829. goto end;
  12830. }
  12831. }
  12832. }
  12833. // Profile periods quantity check
  12834. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12835. {
  12836. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12837. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12838. goto end;
  12839. }
  12840. // Check invalid limit
  12841. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12842. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12843. {
  12844. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12845. {
  12846. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12847. {
  12848. 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)))) ||
  12849. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12850. {
  12851. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12852. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12853. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12854. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12855. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12856. goto end;
  12857. }
  12858. }
  12859. }
  12860. else
  12861. {
  12862. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12863. {
  12864. 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) ||
  12865. (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)))
  12866. {
  12867. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12868. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12869. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12870. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12871. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12872. goto end;
  12873. }
  12874. }
  12875. }
  12876. }
  12877. // Profile purpose info check
  12878. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12879. {
  12880. FILE *fp;
  12881. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12882. if(SetProfileReq.ConnectorId != 0)
  12883. {
  12884. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12885. DEBUG_WARN("Profile connector id is not 0.\n");
  12886. goto end;
  12887. }
  12888. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12889. if (!fp)
  12890. {
  12891. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12892. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12893. }
  12894. else
  12895. {
  12896. char *line = NULL;
  12897. size_t len = 0;
  12898. while(getline(&line, &len, fp) != -1)
  12899. {
  12900. json_object *obj = NULL;
  12901. obj = json_tokener_parse(line);
  12902. if(is_error(obj))
  12903. {
  12904. DEBUG_ERROR("Parse txProfile from file error.\n");
  12905. }
  12906. else
  12907. {
  12908. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12909. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12910. {
  12911. profileQuantity += 1;
  12912. }
  12913. else
  12914. replaceableProfileCnt += 1;
  12915. }
  12916. }
  12917. }
  12918. fclose(fp);
  12919. }
  12920. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12921. {
  12922. FILE *fp;
  12923. char filename[128]={0};
  12924. int tmpProfileQuantity;
  12925. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12926. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12927. {
  12928. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12929. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12930. goto end;
  12931. }
  12932. if(SetProfileReq.ConnectorId == 0)
  12933. {
  12934. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12935. {
  12936. tmpProfileQuantity = 0;
  12937. memset(filename, 0, ARRAY_SIZE(filename));
  12938. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12939. fp = fopen(filename, "r");
  12940. if (!fp)
  12941. {
  12942. DEBUG_INFO("%s does not create.\n", filename);
  12943. fp = fopen(filename, "w+");
  12944. }
  12945. else
  12946. {
  12947. char *line = NULL;
  12948. size_t len = 0;
  12949. while(getline(&line, &len, fp) != -1)
  12950. {
  12951. json_object *obj = NULL;
  12952. obj = json_tokener_parse(line);
  12953. if(is_error(obj))
  12954. {
  12955. DEBUG_ERROR("Parse txProfile from file error.\n");
  12956. }
  12957. else
  12958. {
  12959. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12960. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12961. {
  12962. tmpProfileQuantity += 1;
  12963. }
  12964. else
  12965. replaceableProfileCnt += 1;
  12966. }
  12967. }
  12968. }
  12969. fclose(fp);
  12970. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12971. }
  12972. }
  12973. else
  12974. {
  12975. memset(filename, 0, ARRAY_SIZE(filename));
  12976. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12977. fp = fopen(filename, "r");
  12978. if (!fp)
  12979. {
  12980. DEBUG_INFO("%s does not create.\n", filename);
  12981. fp = fopen(filename, "w+");
  12982. }
  12983. else
  12984. {
  12985. char *line = NULL;
  12986. size_t len = 0;
  12987. while(getline(&line, &len, fp) != -1)
  12988. {
  12989. json_object *obj = NULL;
  12990. obj = json_tokener_parse(line);
  12991. if(is_error(obj))
  12992. {
  12993. DEBUG_ERROR("Parse txProfile from file error.\n");
  12994. }
  12995. else
  12996. {
  12997. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12998. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12999. {
  13000. profileQuantity += 1;
  13001. }
  13002. else
  13003. replaceableProfileCnt += 1;
  13004. }
  13005. }
  13006. }
  13007. fclose(fp);
  13008. }
  13009. }
  13010. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13011. {
  13012. int isMatchTransactiodId= FALSE;
  13013. FILE *fp;
  13014. char filename[128]={0};
  13015. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13016. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13017. if(SetProfileReq.ConnectorId == 0)
  13018. {
  13019. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13020. DEBUG_WARN("Profile connector id is 0.\n");
  13021. goto end;
  13022. }
  13023. int tempIndex = 0;
  13024. //check Transaction active
  13025. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13026. {
  13027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13028. {
  13029. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13030. }
  13031. else
  13032. {
  13033. tempIndex = SetProfileReq.ConnectorId -1;
  13034. }
  13035. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13036. {
  13037. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13038. {
  13039. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13040. {
  13041. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13042. {
  13043. isMatchTransactiodId = TRUE;
  13044. break;
  13045. }
  13046. }
  13047. }
  13048. }
  13049. }
  13050. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13051. {
  13052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13053. {
  13054. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13055. }
  13056. else
  13057. {
  13058. tempIndex = SetProfileReq.ConnectorId -1;
  13059. }
  13060. for (int index = 0; index < CCS_QUANTITY; index++)
  13061. {
  13062. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13063. {
  13064. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13065. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13066. {
  13067. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13068. {
  13069. isMatchTransactiodId = TRUE;
  13070. break;
  13071. }
  13072. }
  13073. }
  13074. }
  13075. }
  13076. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13077. {
  13078. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13079. {
  13080. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13081. }
  13082. else
  13083. {
  13084. tempIndex = SetProfileReq.ConnectorId -1;
  13085. }
  13086. for (int index = 0; index < GB_QUANTITY; index++)
  13087. {
  13088. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13089. {
  13090. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13091. {
  13092. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13093. {
  13094. isMatchTransactiodId = TRUE;
  13095. break;
  13096. }
  13097. }
  13098. }
  13099. }
  13100. }
  13101. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13102. {
  13103. tempIndex = SetProfileReq.ConnectorId -1;
  13104. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13105. {
  13106. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13107. {
  13108. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13109. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13110. {
  13111. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13112. {
  13113. isMatchTransactiodId = TRUE;
  13114. break;
  13115. }
  13116. }
  13117. }
  13118. }
  13119. }
  13120. else
  13121. {
  13122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13123. {
  13124. tempIndex = 2;
  13125. }
  13126. else
  13127. {
  13128. tempIndex = (SetProfileReq.ConnectorId -1);
  13129. }
  13130. for (int index = 0; index < AC_QUANTITY; index++)
  13131. {
  13132. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13133. {
  13134. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13135. {
  13136. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13137. {
  13138. isMatchTransactiodId = TRUE;
  13139. break;
  13140. }
  13141. }
  13142. }
  13143. }
  13144. }
  13145. //check Transaction active
  13146. if(isMatchTransactiodId == FALSE)
  13147. {
  13148. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13149. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13150. goto end;
  13151. }
  13152. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13153. {
  13154. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13155. DEBUG_WARN("Connector id is over max gun number.\n");
  13156. goto end;
  13157. }
  13158. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13159. fp = fopen(filename, "r");
  13160. if (!fp)
  13161. {
  13162. DEBUG_INFO("%s does not create.\n", filename);
  13163. fp = fopen(filename, "w+");
  13164. }
  13165. else
  13166. {
  13167. char *line = NULL;
  13168. size_t len = 0;
  13169. while(getline(&line, &len, fp) != -1)
  13170. {
  13171. json_object *obj = NULL;
  13172. obj = json_tokener_parse(line);
  13173. if(is_error(obj))
  13174. {
  13175. DEBUG_ERROR("Parse txProfile from file error.\n");
  13176. }
  13177. else
  13178. {
  13179. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13180. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13181. {
  13182. profileQuantity += 1;
  13183. }
  13184. else
  13185. replaceableProfileCnt += 1;
  13186. }
  13187. }
  13188. }
  13189. fclose(fp);
  13190. }
  13191. // Check ChargeProfileMaxStackLevel
  13192. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13193. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13194. {
  13195. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13196. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13197. goto end;
  13198. }
  13199. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13200. {
  13201. FILE *fp;
  13202. char dataLine[4096]={0};
  13203. char fnametemp[128]={0};
  13204. int tmpProfileQuantity;
  13205. //Check ChargePointMaxProfile.json exit
  13206. profileQuantity = 0;
  13207. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13208. {
  13209. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13210. //Check Charging Profile Count
  13211. tmpProfileQuantity = 0;
  13212. while(fscanf(fp, "%s", dataLine) != EOF)
  13213. {
  13214. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13215. {
  13216. profileQuantity += 1;
  13217. tmpProfileQuantity += 1;
  13218. }
  13219. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13220. }
  13221. fclose(fp);
  13222. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13223. }
  13224. //Check TxDefaultProfile_%d.json
  13225. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13226. {
  13227. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13228. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13229. if((access(fnametemp,F_OK))!=-1)
  13230. {
  13231. fp = fopen(fnametemp, "r");
  13232. //Check Charging Profile Count
  13233. tmpProfileQuantity = 0;
  13234. while(fscanf(fp, "%s", dataLine) != EOF)
  13235. {
  13236. //DEBUG_INFO("word=%s\n",word);
  13237. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13238. {
  13239. profileQuantity += 1;
  13240. tmpProfileQuantity += 1;
  13241. }
  13242. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13243. }
  13244. fclose(fp);
  13245. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13246. }
  13247. }
  13248. //Check TxProfile_%d.json
  13249. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13250. {
  13251. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13252. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13253. if((access(fnametemp,F_OK))!=-1)
  13254. {
  13255. fp = fopen(fnametemp, "r");
  13256. //Check Charging Profile Count
  13257. tmpProfileQuantity = 0;
  13258. while(fscanf(fp, "%s", dataLine) != EOF)
  13259. {
  13260. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13261. {
  13262. profileQuantity += 1;
  13263. tmpProfileQuantity += 1;
  13264. }
  13265. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13266. }
  13267. fclose(fp);
  13268. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13269. }
  13270. }
  13271. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13272. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13273. // To check total Profile quantity
  13274. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13275. {
  13276. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13277. {
  13278. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13279. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13280. goto end;
  13281. }
  13282. }
  13283. else
  13284. {
  13285. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13286. {
  13287. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13288. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13289. goto end;
  13290. }
  13291. }
  13292. }
  13293. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13294. //**********************************Write to File********************************************************/
  13295. {
  13296. FILE *infile;
  13297. FILE *outfile;
  13298. char dataLine[4096]={0};
  13299. char filename[128]={0};
  13300. int chkChar=0;
  13301. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13302. {
  13303. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13304. {
  13305. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13306. }
  13307. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13308. {
  13309. if(SetProfileReq.ConnectorId==0)
  13310. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13311. else
  13312. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13313. }
  13314. else
  13315. {
  13316. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13317. }
  13318. infile = fopen (filename, "r");
  13319. outfile = fopen (tempfile, "w");
  13320. chkChar = fgetc(infile);
  13321. rewind(infile);
  13322. if(chkChar == EOF)
  13323. {
  13324. // Profile is empty
  13325. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13326. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13327. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13328. fclose(infile);
  13329. fclose(outfile);
  13330. sprintf(rmFileCmd,"rm -f %s",filename);
  13331. system(rmFileCmd);
  13332. rename(tempfile, filename);
  13333. }
  13334. else
  13335. {
  13336. // Profile is not empty
  13337. int ChargingProfileAdded = FALSE;
  13338. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13339. {
  13340. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13341. json_object *tmpChargingProfile;
  13342. tmpChargingProfile = json_tokener_parse(dataLine);
  13343. if(!is_error(SetChargingProfile))
  13344. {
  13345. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13346. {
  13347. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13348. {
  13349. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13350. }
  13351. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13352. {
  13353. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13354. }
  13355. }
  13356. }
  13357. json_object_put(tmpChargingProfile);
  13358. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13359. {
  13360. if(ChargingProfileAdded == FALSE)
  13361. {
  13362. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13363. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13364. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13365. ChargingProfileAdded = TRUE;
  13366. }
  13367. }
  13368. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13369. {
  13370. if(ChargingProfileAdded == FALSE)
  13371. {
  13372. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13373. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13374. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13375. ChargingProfileAdded = TRUE;
  13376. }
  13377. }
  13378. else
  13379. {
  13380. fprintf(outfile,"%s\n",dataLine);
  13381. if(ChargingProfileAdded == FALSE)
  13382. {
  13383. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13384. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13385. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13386. ChargingProfileAdded = TRUE;
  13387. }
  13388. }
  13389. } // end of while loop
  13390. fclose(infile);
  13391. fclose(outfile);
  13392. sprintf(rmFileCmd,"rm -f %s",filename);
  13393. system(rmFileCmd);
  13394. rename(tempfile, filename);
  13395. }
  13396. }
  13397. sleep(1);
  13398. result = TRUE;
  13399. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13400. }
  13401. end:
  13402. json_object_put(SetChargingProfile);
  13403. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13404. {
  13405. if(SetProfileReq.ConnectorId == 0)
  13406. {
  13407. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13408. {
  13409. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13410. }
  13411. }
  13412. else
  13413. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13414. }
  13415. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13416. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13417. return result;
  13418. }
  13419. int handleTriggerMessageRequest(char *uuid, char *payload)
  13420. {
  13421. mtrace();
  13422. int result = FAIL;
  13423. int connectorIdIsNULL = FALSE;
  13424. int connectorIdInt =0;
  13425. char sstr[40]={0},sstrtemp[100]={ 0 };
  13426. char requestedMessagestr[40]={0};
  13427. char comfirmstr[20]={0};
  13428. int c = 0;
  13429. char *loc;
  13430. DEBUG_INFO("handleTriggerMessageRequest\n");
  13431. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13432. strcpy(sstrtemp, stringtrimspace(payload));
  13433. c = 0;
  13434. loc = strstr(sstrtemp, "requestedMessage");
  13435. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13436. {
  13437. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13438. c++;
  13439. }
  13440. sstr[c] = '\0';
  13441. strcpy(requestedMessagestr, sstr);
  13442. c = 0;
  13443. loc = strstr(sstrtemp, "connectorId");
  13444. if(loc == NULL)
  13445. {
  13446. connectorIdIsNULL = TRUE;
  13447. }
  13448. else
  13449. {
  13450. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13451. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13452. {
  13453. sstr[c] = loc[strlen("connectorId")+2+c];
  13454. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13455. c++;
  13456. }
  13457. sstr[c] = '\0';
  13458. connectorIdInt = atoi(sstr);
  13459. }
  13460. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13461. {
  13462. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13463. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13464. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13465. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13466. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13467. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13468. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13469. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13470. {
  13471. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13472. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13473. return TRUE;
  13474. }
  13475. else
  13476. {
  13477. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13478. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13479. }
  13480. }
  13481. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13482. {
  13483. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13484. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13485. return TRUE;
  13486. }
  13487. //==========================
  13488. // Trigger message
  13489. //==========================
  13490. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13491. {
  13492. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13493. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13494. {
  13495. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13496. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13497. }
  13498. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13499. }
  13500. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13501. {
  13502. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13503. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13504. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13505. }
  13506. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13507. {
  13508. //sendBootNotificationRequest();
  13509. server_sign = FALSE;
  13510. }
  13511. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13512. {
  13513. refreshStartTimer(&clientTime.Heartbeat);
  13514. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13515. }
  13516. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13517. {
  13518. if(connectorIdIsNULL == FALSE)
  13519. {
  13520. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13521. {
  13522. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13523. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13524. }
  13525. }
  13526. else
  13527. {
  13528. for(int idx=0;idx< gunTotalNumber;idx++)
  13529. {
  13530. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13531. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13532. }
  13533. }
  13534. }
  13535. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13536. {
  13537. if(connectorIdIsNULL == FALSE)
  13538. {
  13539. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13540. {
  13541. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13542. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13543. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13544. }
  13545. }
  13546. else
  13547. {
  13548. for(int idx=0;idx< gunTotalNumber;idx++)
  13549. {
  13550. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13551. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13552. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13553. }
  13554. }
  13555. }
  13556. return result;
  13557. }
  13558. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13559. {
  13560. mtrace();
  13561. int result = FAIL;
  13562. int connectorIdInt =0;
  13563. char comfirmstr[20]={0};
  13564. int tempIndex = 0;
  13565. json_object *UnlockConnector;
  13566. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13567. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13568. UnlockConnector = json_tokener_parse(payload);
  13569. if(!is_error(UnlockConnector))
  13570. {
  13571. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13572. {
  13573. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13574. }
  13575. }
  13576. json_object_put(UnlockConnector);
  13577. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13578. if(gunTotalNumber == 0)
  13579. {
  13580. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13581. goto end;
  13582. }
  13583. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13584. {
  13585. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13586. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13587. goto end;
  13588. }
  13589. else
  13590. {
  13591. //check Transaction active
  13592. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13593. {
  13594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13595. {
  13596. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13597. }
  13598. else
  13599. {
  13600. tempIndex = connectorIdInt -1;
  13601. }
  13602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13603. {
  13604. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13605. {
  13606. //stop Transaction
  13607. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13608. }
  13609. }
  13610. }
  13611. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13612. {
  13613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13614. {
  13615. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13616. }
  13617. else
  13618. {
  13619. tempIndex = connectorIdInt -1;
  13620. }
  13621. for (int index = 0; index < CCS_QUANTITY; index++)
  13622. {
  13623. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13624. {
  13625. //stop Transaction
  13626. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13627. }
  13628. }
  13629. }
  13630. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13631. {
  13632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13633. {
  13634. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13635. }
  13636. else
  13637. {
  13638. tempIndex = connectorIdInt -1;
  13639. }
  13640. for (int index = 0; index < GB_QUANTITY; index++)
  13641. {
  13642. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13643. {
  13644. //stop Transaction
  13645. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13646. }
  13647. }
  13648. }
  13649. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13650. {
  13651. tempIndex = connectorIdInt -1;
  13652. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13653. {
  13654. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13655. {
  13656. //stop Transaction
  13657. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13658. }
  13659. }
  13660. }
  13661. else
  13662. {
  13663. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13664. {
  13665. tempIndex = 2;
  13666. }
  13667. else
  13668. {
  13669. tempIndex = connectorIdInt-1;
  13670. }
  13671. for (int index = 0; index < AC_QUANTITY; index++)
  13672. {
  13673. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13674. {
  13675. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13676. }
  13677. }
  13678. }
  13679. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13680. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13681. result = TRUE;
  13682. return result;
  13683. }
  13684. end:
  13685. //json_object_put(obj); --- remove temporally
  13686. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13687. return result;
  13688. }
  13689. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13690. {
  13691. mtrace();
  13692. int result = FAIL;
  13693. pthread_t t;
  13694. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13695. sendUpdateFirmwareConfirmation(uuid);
  13696. if(!interLock.isUpdateFirmwareGoing)
  13697. {
  13698. interLock.isUpdateFirmwareGoing = 1;
  13699. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13700. sleep(1);
  13701. }
  13702. else
  13703. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13704. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13705. return result;
  13706. }
  13707. void *UpdateFirmwareProcess(void *data)
  13708. {
  13709. pthread_detach(pthread_self());
  13710. mtrace();
  13711. int retriesInt =0, retryIntervalInt=0;
  13712. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13713. int port=0;
  13714. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13715. int isSuccess = 0;
  13716. char ftpbuf[1024];
  13717. char temp[1024];
  13718. char * pch;
  13719. json_object *UpdateFirmware;
  13720. UpdateFirmware = json_tokener_parse(data);
  13721. if(!is_error(UpdateFirmware))
  13722. {
  13723. // Required data
  13724. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13725. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13726. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13727. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13728. // Optional data
  13729. if(json_object_object_get(UpdateFirmware, "retries"))
  13730. {
  13731. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13732. }
  13733. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13734. {
  13735. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13736. }
  13737. }
  13738. json_object_put(UpdateFirmware);
  13739. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13740. memset(path, 0, ARRAY_SIZE(path));
  13741. // Wait retrieveData
  13742. if(strlen(retrieveDatestr) > 10)
  13743. {
  13744. do
  13745. {
  13746. sleep(1);
  13747. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13748. }
  13749. // Ready to download
  13750. system("rm -f /mnt/*");
  13751. if(strncmp(locationstr,"http", 4) == 0)
  13752. {
  13753. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13754. sprintf(ftppath,"/%s", path);
  13755. DEBUG_INFO("locationstr: %s\n", locationstr);
  13756. DEBUG_INFO("protocol: %s\n",protocol);
  13757. DEBUG_INFO("host: %s\n",host);
  13758. DEBUG_INFO("path: %s\n",path);
  13759. DEBUG_INFO("ftppath: %s\n",ftppath);
  13760. int ftppathlen=strlen(ftppath);
  13761. int i=1;
  13762. char filenametemp[50];
  13763. while(i < ftppathlen)
  13764. {
  13765. int len=ftppathlen-i;
  13766. if(ftppath[len]== 47) // '/' ascll code: 47
  13767. {
  13768. DEBUG_INFO("compare '/' all right\n");
  13769. break;
  13770. }
  13771. i=i+1;
  13772. }
  13773. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13774. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13775. filenametemp[i+1] = 0;
  13776. do
  13777. {
  13778. sleep(1);
  13779. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13780. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13781. sleep(1);
  13782. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13783. if(!isSuccess)
  13784. {
  13785. sleep(1);
  13786. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13787. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13788. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13789. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13790. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13791. }
  13792. else
  13793. {
  13794. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13795. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13796. }
  13797. retriesInt--;
  13798. }while((isSuccess == 0)&&(retriesInt >= 0));
  13799. }
  13800. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13801. {
  13802. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13803. memset(temp, 0, ARRAY_SIZE(temp));
  13804. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13805. strcpy(ftpbuf, locationstr);
  13806. int ftppathlen=strlen(ftpbuf);
  13807. int i=1;
  13808. char filenametemp[50];
  13809. while(i < ftppathlen)
  13810. {
  13811. int len=ftppathlen-i;
  13812. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13813. {
  13814. DEBUG_INFO(" compare '/' all right\n");
  13815. break;
  13816. }
  13817. i=i+1;
  13818. }
  13819. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13820. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13821. filenametemp[i+1] = 0;
  13822. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13823. pch=strchr(temp,'@');
  13824. if(pch==NULL)
  13825. {
  13826. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13827. protocol, host, &port, path);
  13828. strcpy(user,"anonymous");
  13829. strcpy(password,"");
  13830. }
  13831. else
  13832. {
  13833. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13834. protocol, user, host, &port, path);
  13835. }
  13836. sscanf(host,"%[^/]%s",host1, path1);
  13837. sprintf(ftppath,"%s:/%s", host,path);
  13838. if(port == 0)
  13839. {
  13840. port = 21;
  13841. }
  13842. do
  13843. {
  13844. sleep(1);
  13845. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13846. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13847. sleep(1);
  13848. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13849. if(!isSuccess)
  13850. {
  13851. //BulldogUtil.sleepMs(interval*1000);
  13852. DEBUG_INFO("Update firmware request and download file fail.\n");
  13853. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13854. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13855. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13856. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13857. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13858. }
  13859. else
  13860. {
  13861. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13862. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13863. }
  13864. retriesInt--;
  13865. }while((!isSuccess)&&(retriesInt >= 0));
  13866. }
  13867. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13868. {
  13869. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13870. memset(temp, 0, ARRAY_SIZE(temp));
  13871. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13872. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13873. int ftppathlen=strlen(ftpbuf);
  13874. int i=1;
  13875. char filenametemp[50];
  13876. while(i < ftppathlen)
  13877. {
  13878. int len=ftppathlen-i;
  13879. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13880. {
  13881. DEBUG_INFO(" compare '/' all right\n");
  13882. break;
  13883. }
  13884. i=i+1;
  13885. }
  13886. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13887. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13888. filenametemp[i+1] = 0;
  13889. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13890. pch=strchr(temp,'@');
  13891. if(pch==NULL)
  13892. {
  13893. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13894. protocol, host, &port, path);
  13895. strcpy(user,"anonymous");
  13896. strcpy(password,"");
  13897. }
  13898. else
  13899. {
  13900. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13901. protocol, user, password, host, &port, path);
  13902. }
  13903. sscanf(host,"%[^/]%s",host1, path1);
  13904. sprintf(ftppath,"%s", path1);
  13905. //DEBUG_INFO("protocol =%s\n",protocol);
  13906. //DEBUG_INFO("user =%s\n",user);
  13907. //DEBUG_INFO("password =%s\n",password);
  13908. //DEBUG_INFO("host1 =%s\n",host1);
  13909. //DEBUG_INFO("port =%d\n",port);
  13910. //DEBUG_INFO("path1 =%s\n",path1);
  13911. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13912. //ftpFile(host, user, password, port, ftppath, fname);
  13913. //download firmware pthred
  13914. if(port == 0)
  13915. {
  13916. port = 21;
  13917. }
  13918. do
  13919. {
  13920. sleep(1);
  13921. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13922. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13923. sleep(1);
  13924. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13925. if(!isSuccess)
  13926. {
  13927. //BulldogUtil.sleepMs(interval*1000);
  13928. DEBUG_INFO("Update firmware request and download file fail.\n");
  13929. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13930. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13931. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13932. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13933. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13934. }
  13935. else
  13936. {
  13937. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13938. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13939. }
  13940. retriesInt--;
  13941. }while((!isSuccess)&&(retriesInt >= 0));
  13942. }
  13943. else
  13944. {
  13945. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13946. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13947. sleep(1);
  13948. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13949. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13950. }
  13951. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13952. {
  13953. sleep(3);
  13954. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13955. }
  13956. interLock.isUpdateFirmwareGoing = 0;
  13957. pthread_exit(NULL);
  13958. }
  13959. int handleCertificateSignedRequest(char *uuid, char *payload)
  13960. {
  13961. mtrace();
  13962. int result = PASS;
  13963. json_object *CertificateSigned;
  13964. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13965. CertificateSigned = json_tokener_parse(payload);
  13966. if(!is_error(CertificateSigned))
  13967. {
  13968. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13969. }
  13970. json_object_put(CertificateSigned);
  13971. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  13972. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13973. fclose(fp);
  13974. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13975. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13976. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  13977. {
  13978. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13979. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  13980. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  13981. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  13982. }
  13983. else
  13984. {
  13985. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  13986. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  13987. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  13988. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  13989. }
  13990. sendCertificateSignedConfirmation(uuid);
  13991. return result;
  13992. }
  13993. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13994. {
  13995. mtrace();
  13996. int result = PASS;
  13997. json_object *DeleteCertificate;
  13998. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13999. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14000. DeleteCertificate = json_tokener_parse(payload);
  14001. if(!is_error(DeleteCertificate))
  14002. {
  14003. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14004. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14005. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14006. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14007. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14008. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14009. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14010. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14011. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  14012. {
  14013. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  14014. }
  14015. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  14016. {
  14017. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  14018. }
  14019. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  14020. {
  14021. ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  14022. }
  14023. char temp[256] = {0};
  14024. char compareData[256] = {0};
  14025. int isMatch = TRUE;
  14026. // Check CentralSystemRootCertificate
  14027. if(access(ROOTCA_CS,F_OK) != -1)
  14028. {
  14029. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14030. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14031. for(int i = 0; compareData[i]; i++)
  14032. {
  14033. compareData[i] = tolower(compareData[i]);
  14034. }
  14035. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14036. isMatch = FALSE;
  14037. if(isMatch == TRUE)
  14038. {
  14039. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14040. for(int i = 0; compareData[i]; i++)
  14041. {
  14042. compareData[i] = tolower(compareData[i]);
  14043. }
  14044. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14045. isMatch = FALSE;
  14046. }
  14047. if(isMatch == TRUE)
  14048. {
  14049. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14050. for(int i = 0; compareData[i]; i++)
  14051. {
  14052. compareData[i] = tolower(compareData[i]);
  14053. }
  14054. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14055. isMatch = FALSE;
  14056. }
  14057. if(isMatch == TRUE)
  14058. {
  14059. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  14060. sprintf(temp, "rm -f %s", ROOTCA_CS);
  14061. system(temp);
  14062. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14063. goto End;
  14064. }
  14065. }
  14066. // Check ManufacturerRootCertificate
  14067. if(access(ROOTCA_MF,F_OK) != -1)
  14068. {
  14069. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  14070. isMatch = TRUE;
  14071. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  14072. for(int i = 0; compareData[i]; i++)
  14073. {
  14074. compareData[i] = tolower(compareData[i]);
  14075. }
  14076. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14077. isMatch = FALSE;
  14078. if(isMatch == TRUE)
  14079. {
  14080. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  14081. for(int i = 0; compareData[i]; i++)
  14082. {
  14083. compareData[i] = tolower(compareData[i]);
  14084. }
  14085. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14086. isMatch = FALSE;
  14087. }
  14088. if(isMatch == TRUE)
  14089. {
  14090. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  14091. for(int i = 0; compareData[i]; i++)
  14092. {
  14093. compareData[i] = tolower(compareData[i]);
  14094. }
  14095. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14096. isMatch = FALSE;
  14097. }
  14098. if(isMatch == TRUE)
  14099. {
  14100. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  14101. sprintf(temp, "rm -f %s", ROOTCA_MF);
  14102. system(temp);
  14103. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14104. goto End;
  14105. }
  14106. }
  14107. // Check certCP
  14108. if(access(CERTIFICATE_CP,F_OK) != -1)
  14109. {
  14110. DEBUG_INFO("Checking certCP...\n");
  14111. isMatch = TRUE;
  14112. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  14113. for(int i = 0; compareData[i]; i++)
  14114. {
  14115. compareData[i] = tolower(compareData[i]);
  14116. }
  14117. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14118. isMatch = FALSE;
  14119. if(isMatch == TRUE)
  14120. {
  14121. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  14122. for(int i = 0; compareData[i]; i++)
  14123. {
  14124. compareData[i] = tolower(compareData[i]);
  14125. }
  14126. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14127. isMatch = FALSE;
  14128. }
  14129. if(isMatch == TRUE)
  14130. {
  14131. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  14132. for(int i = 0; compareData[i]; i++)
  14133. {
  14134. compareData[i] = tolower(compareData[i]);
  14135. }
  14136. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14137. isMatch = FALSE;
  14138. }
  14139. if(isMatch == TRUE)
  14140. {
  14141. DEBUG_INFO("Deleting certCP...\n");
  14142. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14143. system(temp);
  14144. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14145. goto End;
  14146. }
  14147. }
  14148. }
  14149. End:
  14150. json_object_put(DeleteCertificate);
  14151. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14152. sendDeleteCertificateConfirmation(uuid);
  14153. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14154. return result;
  14155. }
  14156. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14157. {
  14158. mtrace();
  14159. int result = PASS;
  14160. json_object *ExtendedTriggerMessage;
  14161. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14162. ExtendedTriggerMessage = json_tokener_parse(payload);
  14163. if(!is_error(ExtendedTriggerMessage))
  14164. {
  14165. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14166. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14167. {
  14168. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14169. }
  14170. else
  14171. {
  14172. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14173. }
  14174. }
  14175. json_object_put(ExtendedTriggerMessage);
  14176. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14177. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14178. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14179. {
  14180. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14181. }
  14182. else
  14183. {
  14184. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14185. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14186. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14187. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14188. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14189. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14190. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14191. {
  14192. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14193. }
  14194. else
  14195. {
  14196. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14197. }
  14198. }
  14199. sendExtendedTriggerMessageConfirmation(uuid);
  14200. //==========================
  14201. // Trigger message
  14202. //==========================
  14203. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14204. {
  14205. //sendBootNotificationRequest();
  14206. server_sign = FALSE;
  14207. }
  14208. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14209. {
  14210. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14211. }
  14212. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14213. {
  14214. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14215. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14216. {
  14217. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14218. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14219. }
  14220. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14221. }
  14222. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14223. {
  14224. refreshStartTimer(&clientTime.Heartbeat);
  14225. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14226. }
  14227. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14228. {
  14229. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14230. {
  14231. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14232. }
  14233. else
  14234. {
  14235. for(int idx=0;idx< gunTotalNumber;idx++)
  14236. {
  14237. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14238. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14239. }
  14240. }
  14241. }
  14242. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14243. {
  14244. char cmdBuf[1024]={0};
  14245. 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);
  14246. system(cmdBuf);
  14247. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14248. }
  14249. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14250. {
  14251. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14252. {
  14253. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14254. }
  14255. else
  14256. {
  14257. for(int idx=0;idx< gunTotalNumber;idx++)
  14258. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14259. }
  14260. }
  14261. return result;
  14262. }
  14263. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14264. {
  14265. mtrace();
  14266. int result = PASS;
  14267. json_object *GetInstalledCertificateIds;
  14268. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14269. GetInstalledCertificateIds = json_tokener_parse(payload);
  14270. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14271. if(!is_error(GetInstalledCertificateIds))
  14272. {
  14273. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14274. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14275. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14276. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  14277. // Check CentralSystemRootCertificate
  14278. if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL)
  14279. {
  14280. if(access(ROOTCA_CS,F_OK) != -1)
  14281. {
  14282. char parseData[512] = {0};
  14283. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14284. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14285. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  14286. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14287. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14288. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14289. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14290. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14291. }
  14292. else
  14293. {
  14294. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  14295. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14296. }
  14297. }
  14298. // Check ManufacturerRootCertificate
  14299. else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
  14300. {
  14301. if(access(ROOTCA_MF,F_OK) != -1)
  14302. {
  14303. char parseData[512] = {0};
  14304. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14305. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14306. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  14307. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14308. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14309. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14310. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14311. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14312. }
  14313. else
  14314. {
  14315. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  14316. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14317. }
  14318. }
  14319. else
  14320. {
  14321. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14322. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14323. }
  14324. }
  14325. json_object_put(GetInstalledCertificateIds);
  14326. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14327. sendGetInstalledCertificateIdsConfirmation(uuid);
  14328. return result;
  14329. }
  14330. void* GetLogProcess(void* data)
  14331. {
  14332. pthread_detach(pthread_self());
  14333. mtrace();
  14334. 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};
  14335. int port=0;
  14336. int isSuccess = FALSE;
  14337. char cmdBuf[2048];
  14338. struct tm *tmNow;
  14339. time_t CurrentTime;
  14340. struct tm tmStart;
  14341. struct tm tmStop;
  14342. CurrentTime = time(NULL);
  14343. tmNow=localtime(&CurrentTime);
  14344. uint16_t targetYear, targetMonth;
  14345. json_object *GetLog;
  14346. DEBUG_INFO("GetLogProcess...\n");
  14347. GetLog = json_tokener_parse(data);
  14348. if(!is_error(GetLog))
  14349. {
  14350. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14351. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14352. if(json_object_object_get(GetLog, "retries") != NULL)
  14353. {
  14354. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14355. }
  14356. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14357. {
  14358. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14359. }
  14360. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14361. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14362. {
  14363. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14364. }
  14365. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14366. {
  14367. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14368. }
  14369. }
  14370. json_object_put(GetLog);
  14371. // Pack log to compress file
  14372. 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) &&
  14373. (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))
  14374. {
  14375. // Pack system log
  14376. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14377. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14378. targetYear = tmStart.tm_year;
  14379. targetMonth = tmStart.tm_mon;
  14380. do
  14381. {
  14382. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14383. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14384. if(targetMonth+1>=13)
  14385. {
  14386. targetYear += 1;
  14387. targetMonth = 1;
  14388. }
  14389. else
  14390. {
  14391. targetMonth += 1;
  14392. }
  14393. }while((targetYear < (tmNow->tm_year+1900)) ||
  14394. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14395. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14396. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14397. system(cmdBuf);
  14398. // Pack charging & event log
  14399. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14400. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14401. targetYear = tmStart.tm_year;
  14402. targetMonth = tmStart.tm_mon;
  14403. do
  14404. {
  14405. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14406. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14407. if(targetMonth+1>=13)
  14408. {
  14409. targetYear += 1;
  14410. targetMonth = 1;
  14411. }
  14412. else
  14413. {
  14414. targetMonth += 1;
  14415. }
  14416. }while((targetYear < (tmNow->tm_year+1900)) ||
  14417. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14418. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14419. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14420. system(cmdBuf);
  14421. // Combine log file
  14422. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14423. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14424. }
  14425. else
  14426. {
  14427. system("exec /root/logPackTools 'log' 6");
  14428. }
  14429. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14430. system(cmdBuf);
  14431. checkUploadLog();
  14432. //****************location*******************/
  14433. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14434. {
  14435. DEBUG_INFO("location is <Empty>!\n");
  14436. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14437. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14438. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14439. goto end;
  14440. }
  14441. memset(protocol, 0, ARRAY_SIZE(protocol));
  14442. memset(user, 0, ARRAY_SIZE(user) );
  14443. memset(password, 0, ARRAY_SIZE(password));
  14444. memset(host, 0, ARRAY_SIZE(host));
  14445. memset(path, 0, ARRAY_SIZE(path));
  14446. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14447. memset(host1, 0, ARRAY_SIZE(host1));
  14448. memset(path1, 0, ARRAY_SIZE(path1));
  14449. /*location: ftp://user:password@host:port/path*/
  14450. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14451. if((access(fnamePlusPath,F_OK))!=-1)
  14452. {
  14453. DEBUG_INFO("fnamePlusPath exist.\n");
  14454. }
  14455. else
  14456. {
  14457. DEBUG_INFO("fnamePlusPath not exist!\n");
  14458. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14459. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14460. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14461. goto end;
  14462. }
  14463. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14464. {
  14465. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14466. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14467. protocol, host, &port, path);
  14468. strcpy(user,"anonymous");
  14469. strcpy(password,"");
  14470. }
  14471. else
  14472. {
  14473. //DEBUG_INFO("pch=%s\n", pch);
  14474. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14475. protocol, user, password, host, &port, path);
  14476. }
  14477. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14478. {
  14479. DEBUG_INFO("protocol is not ftp/http ! \n");
  14480. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14481. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14482. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14483. goto end;
  14484. }
  14485. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14486. {
  14487. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14488. sprintf(ftppath,"/%s", path);
  14489. do
  14490. {
  14491. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14492. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14493. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14494. sleep(3);
  14495. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14496. if(!isSuccess)
  14497. {
  14498. DEBUG_INFO("Diagnostics fail.\n");
  14499. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14500. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14501. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14502. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14503. }
  14504. else
  14505. {
  14506. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14507. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14508. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14509. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14510. }
  14511. ShmOCPP16Data->GetLog.retries--;
  14512. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14513. }
  14514. else
  14515. {
  14516. sscanf(host,"%[^/]%s",host1, path1);
  14517. if(strlen(path) > 0)
  14518. sprintf(ftppath,"/%s", path);
  14519. else
  14520. sprintf(ftppath,"/%s", path1);
  14521. int ftppathlen=strlen(ftppath);
  14522. int i=1;
  14523. char filenametemp[50];
  14524. while(i < ftppathlen)
  14525. {
  14526. int len=ftppathlen-i;
  14527. if(ftppath[len]== 47) // '/' ascll code: 47
  14528. {
  14529. DEBUG_INFO("find '/' all right\n");
  14530. break;
  14531. }
  14532. i=i+1;
  14533. }
  14534. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14535. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14536. filenametemp[i+1] = 0;
  14537. if(port == 0)
  14538. port = 21;
  14539. do
  14540. {
  14541. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14542. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14543. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14544. sleep(3);
  14545. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14546. if(!isSuccess)
  14547. {
  14548. DEBUG_INFO("Diagnostics fail.\n");
  14549. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14550. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14551. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14552. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14553. }
  14554. else
  14555. {
  14556. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14557. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14558. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14559. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14560. }
  14561. ShmOCPP16Data->GetLog.retries--;
  14562. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14563. }
  14564. end:
  14565. system("rm -f /mnt/*");
  14566. sleep(5);
  14567. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14568. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14569. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14570. interLock.isGetDiagnosticGoing = 0;
  14571. pthread_exit(NULL);
  14572. }
  14573. int handleGetLogRequest(char *uuid, char *payload)
  14574. {
  14575. mtrace();
  14576. int result = PASS;
  14577. time_t CurrentTime;
  14578. struct tm *tm;
  14579. DEBUG_INFO("handleGetLogRequest...\n");
  14580. pthread_t th_Status;
  14581. CurrentTime = time(NULL);
  14582. tm = localtime(&CurrentTime);
  14583. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14584. 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);
  14585. if(!interLock.isGetDiagnosticGoing)
  14586. {
  14587. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14588. interLock.isGetDiagnosticGoing = 1;
  14589. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14590. sleep(1);
  14591. }
  14592. else
  14593. {
  14594. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14595. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14596. }
  14597. sendGetLogConfirmation(uuid);
  14598. return result;
  14599. }
  14600. int handleInstallCertificateRequest(char *uuid, char *payload)
  14601. {
  14602. mtrace();
  14603. int result = PASS;
  14604. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14605. json_object *InstallCertificate;
  14606. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14607. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14608. InstallCertificate = json_tokener_parse(payload);
  14609. if(!is_error(InstallCertificate))
  14610. {
  14611. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14612. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14613. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14614. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14615. char temp[1024];
  14616. FILE *fp = fopen(tempCert, "w");
  14617. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14618. fclose(fp);
  14619. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14620. char strExpDate[30];
  14621. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14622. fp = popen(temp, "r");
  14623. if(fp)
  14624. {
  14625. while(fgets(temp, sizeof(temp), fp) != NULL)
  14626. {
  14627. if(strstr(temp, "notAfter=") != NULL)
  14628. {
  14629. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14630. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14631. break;
  14632. }
  14633. }
  14634. }
  14635. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14636. struct tm tmExpDate;
  14637. struct timeb tbExpDate;
  14638. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14639. tbExpDate.time = mktime(&tmExpDate);
  14640. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14641. {
  14642. DEBUG_INFO("The enddate is already expired...\n");
  14643. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14644. goto End;
  14645. }
  14646. // Verify certificate with rootCA
  14647. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14648. fp = popen(temp, "r");
  14649. if(fp)
  14650. {
  14651. while(fgets(temp, sizeof(temp), fp) != NULL)
  14652. {
  14653. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14654. {
  14655. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14656. break;
  14657. }
  14658. else
  14659. {
  14660. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14661. }
  14662. }
  14663. }
  14664. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14665. {
  14666. //=====================================================
  14667. // Verify if the certificate is valid or not. (OCSP?)
  14668. //=====================================================
  14669. /*
  14670. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14671. // Get ocsp url
  14672. char ocspUrl[512];
  14673. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14674. fp = popen(temp, "r");
  14675. if(fp)
  14676. {
  14677. while(fgets(temp, sizeof(temp), fp) != NULL)
  14678. {
  14679. if(strstr(temp, "://") != NULL)
  14680. {
  14681. strcpy(ocspUrl, temp);
  14682. break;
  14683. }
  14684. }
  14685. }
  14686. // Get certificate chain for issuer
  14687. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14688. *
  14689. // Execute OCSP
  14690. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14691. fp = popen(temp, "r");
  14692. if(fp)
  14693. {
  14694. while(fgets(temp, sizeof(temp), fp) != NULL)
  14695. {
  14696. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14697. {
  14698. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14699. break;
  14700. }
  14701. }
  14702. }
  14703. system("rm -f /Storage/OCPP/tempChain.pem");
  14704. pclose(fp);
  14705. */
  14706. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14707. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14708. {
  14709. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14710. goto End;
  14711. }
  14712. else
  14713. DEBUG_INFO("OCSP verifying...PASS.\n");
  14714. }
  14715. else
  14716. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14717. }
  14718. End:
  14719. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14720. {
  14721. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14722. {
  14723. if(access(ROOTCA_CS,F_OK) != -1)
  14724. {
  14725. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14726. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14727. rename(tempCert, ROOTCA_CS);
  14728. }
  14729. else
  14730. {
  14731. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14732. rename(tempCert, ROOTCA_CS);
  14733. }
  14734. }
  14735. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14736. {
  14737. if(access(ROOTCA_MF,F_OK) != -1)
  14738. {
  14739. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14740. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14741. rename(tempCert, ROOTCA_MF);
  14742. }
  14743. else
  14744. {
  14745. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14746. rename(tempCert, ROOTCA_MF);
  14747. }
  14748. }
  14749. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14750. }
  14751. sendInstallCertificateConfirmation(uuid);
  14752. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14753. {
  14754. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14755. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14756. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14757. }
  14758. json_object_put(InstallCertificate);
  14759. return result;
  14760. }
  14761. void *SignedUpdateFirmwareProcess(void *data)
  14762. {
  14763. pthread_detach(pthread_self());
  14764. mtrace();
  14765. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14766. int port=0;
  14767. int isSuccess = 0;
  14768. char ftpbuf[1024];
  14769. char temp[1024];
  14770. char * pch;
  14771. char firmwareFileName[50];
  14772. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14773. json_object *SignedUpdateFirmware;
  14774. SignedUpdateFirmware = json_tokener_parse(data);
  14775. if(!is_error(SignedUpdateFirmware))
  14776. {
  14777. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14778. {
  14779. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14780. }
  14781. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14782. {
  14783. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14784. }
  14785. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14786. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14787. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14788. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14789. {
  14790. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14791. }
  14792. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14793. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14794. }
  14795. json_object_put(SignedUpdateFirmware);
  14796. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14797. memset(path, 0, ARRAY_SIZE(path));
  14798. // Wait retrieveData
  14799. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14800. {
  14801. do
  14802. {
  14803. sleep(1);
  14804. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14805. }
  14806. // Ready to download
  14807. system("rm -f /mnt/*");
  14808. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14809. {
  14810. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14811. sprintf(ftppath,"/%s", path);
  14812. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14813. DEBUG_INFO("protocol: %s\n",protocol);
  14814. DEBUG_INFO("host: %s\n",host);
  14815. DEBUG_INFO("path: %s\n",path);
  14816. DEBUG_INFO("ftppath: %s\n",ftppath);
  14817. int ftppathlen=strlen(ftppath);
  14818. int i=1;
  14819. while(i < ftppathlen)
  14820. {
  14821. int len=ftppathlen-i;
  14822. if(ftppath[len]== 47) // '/' ascll code: 47
  14823. {
  14824. DEBUG_INFO("compare '/' all right\n");
  14825. break;
  14826. }
  14827. i=i+1;
  14828. }
  14829. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14830. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14831. firmwareFileName[i+1] = 0;
  14832. do
  14833. {
  14834. sleep(1);
  14835. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14836. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14837. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14838. sleep(1);
  14839. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14840. if(!isSuccess)
  14841. {
  14842. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14843. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14844. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14845. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14846. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14847. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14848. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14849. }
  14850. else
  14851. {
  14852. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14853. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14854. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14855. }
  14856. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14857. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14858. }
  14859. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14860. {
  14861. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14862. memset(temp, 0, ARRAY_SIZE(temp));
  14863. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14864. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14865. int ftppathlen=strlen(ftpbuf);
  14866. int i=1;
  14867. while(i < ftppathlen)
  14868. {
  14869. int len=ftppathlen-i;
  14870. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14871. {
  14872. DEBUG_INFO(" compare '/' all right\n");
  14873. break;
  14874. }
  14875. i=i+1;
  14876. }
  14877. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14878. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14879. firmwareFileName[i+1] = 0;
  14880. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14881. pch=strchr(temp,'@');
  14882. if(pch==NULL)
  14883. {
  14884. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14885. protocol, host, &port, path);
  14886. strcpy(user,"anonymous");
  14887. strcpy(password,"");
  14888. }
  14889. else
  14890. {
  14891. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14892. protocol, user, host, &port, path);
  14893. }
  14894. sscanf(host,"%[^/]%s",host1, path1);
  14895. sprintf(ftppath,"%s:/%s", host,path);
  14896. if(port == 0)
  14897. {
  14898. port = 21;
  14899. }
  14900. do
  14901. {
  14902. sleep(1);
  14903. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14904. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14905. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14906. sleep(1);
  14907. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14908. if(!isSuccess)
  14909. {
  14910. sleep(1);
  14911. DEBUG_INFO("Update firmware request and download file fail.\n");
  14912. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14913. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14914. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14915. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14916. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14917. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14918. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14919. }
  14920. else
  14921. {
  14922. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14923. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14924. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14925. }
  14926. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14927. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14928. }
  14929. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14930. {
  14931. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14932. memset(temp, 0, ARRAY_SIZE(temp));
  14933. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14934. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14935. int ftppathlen=strlen(ftpbuf);
  14936. int i=1;
  14937. while(i < ftppathlen)
  14938. {
  14939. int len=ftppathlen-i;
  14940. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14941. {
  14942. DEBUG_INFO(" compare '/' all right\n");
  14943. break;
  14944. }
  14945. i=i+1;
  14946. }
  14947. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14948. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14949. firmwareFileName[i+1] = 0;
  14950. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14951. pch=strchr(temp,'@');
  14952. if(pch==NULL)
  14953. {
  14954. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14955. protocol, host, &port, path);
  14956. strcpy(user,"anonymous");
  14957. strcpy(password,"");
  14958. }
  14959. else
  14960. {
  14961. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14962. protocol, user, password, host, &port, path);
  14963. }
  14964. sscanf(host,"%[^/]%s",host1, path1);
  14965. sprintf(ftppath,"%s", path1);
  14966. //DEBUG_INFO("protocol =%s\n",protocol);
  14967. //DEBUG_INFO("user =%s\n",user);
  14968. //DEBUG_INFO("password =%s\n",password);
  14969. //DEBUG_INFO("host1 =%s\n",host1);
  14970. //DEBUG_INFO("port =%d\n",port);
  14971. //DEBUG_INFO("path1 =%s\n",path1);
  14972. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14973. //ftpFile(host, user, password, port, ftppath, fname);
  14974. //download firmware pthred
  14975. if(port == 0)
  14976. {
  14977. port = 21;
  14978. }
  14979. do
  14980. {
  14981. sleep(1);
  14982. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14983. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14984. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14985. sleep(1);
  14986. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14987. if(!isSuccess)
  14988. {
  14989. //BulldogUtil.sleepMs(interval*1000);
  14990. DEBUG_INFO("Update firmware request and download file fail.\n");
  14991. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14992. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14993. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14994. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14995. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14996. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14997. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14998. }
  14999. else
  15000. {
  15001. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15002. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15003. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15004. }
  15005. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15006. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15007. }
  15008. else
  15009. {
  15010. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15011. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15012. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15013. sleep(1);
  15014. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15015. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15016. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15017. }
  15018. // Verify firmware image signature
  15019. struct stat st;
  15020. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15021. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15022. fclose(fp);
  15023. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15024. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15025. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15026. fclose(fp);
  15027. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15028. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15029. if(st.st_size == 0)
  15030. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15031. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15032. {
  15033. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15034. fp = popen(temp, "r");
  15035. if(fp)
  15036. {
  15037. while(fgets(temp, sizeof(temp), fp) != NULL)
  15038. {
  15039. if(strstr(temp, "Verified OK") != NULL)
  15040. {
  15041. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15042. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15043. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15044. }
  15045. else
  15046. {
  15047. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15048. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15049. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15050. sleep(1);
  15051. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15052. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15053. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15054. sleep(1);
  15055. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15056. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15057. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15058. }
  15059. break;
  15060. }
  15061. }
  15062. pclose(fp);
  15063. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15064. }
  15065. interLock.isUpdateFirmwareGoing = 0;
  15066. pthread_exit(NULL);
  15067. }
  15068. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15069. {
  15070. mtrace();
  15071. int result = PASS;
  15072. pthread_t t;
  15073. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15074. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15075. sendSignedUpdateFirmwareConfirmation(uuid);
  15076. if(!interLock.isUpdateFirmwareGoing)
  15077. {
  15078. interLock.isUpdateFirmwareGoing = 1;
  15079. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15080. sleep(1);
  15081. }
  15082. else
  15083. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15084. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15085. return result;
  15086. }
  15087. int handleUnknownRequest(char *uuid, char *payload)
  15088. {
  15089. mtrace();
  15090. int result = PASS;
  15091. DEBUG_INFO("handleUnknownRequest...\n");
  15092. sendUnknownConfirmation(uuid);
  15093. return result;
  15094. }
  15095. //==========================================
  15096. // Handle server response routine
  15097. //==========================================
  15098. void handleAuthorizeResponse(char *payload, int gun_index)
  15099. {
  15100. mtrace();
  15101. char expiryDatestr[36]={0};
  15102. char parentIdTagstr[21]={0};
  15103. char statusstr[20]={0};
  15104. int expiryDateISNULL=FALSE;
  15105. int parentIdTagISNULL=FALSE;
  15106. DEBUG_INFO("handleAuthorizeResponse...\n");
  15107. json_object *Authorize;
  15108. Authorize = json_tokener_parse(payload);
  15109. if(!is_error(Authorize))
  15110. {
  15111. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15112. {
  15113. // Required data
  15114. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15115. // Optional data
  15116. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15117. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15118. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15119. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15120. }
  15121. }
  15122. json_object_put(Authorize);
  15123. if(expiryDateISNULL == FALSE)
  15124. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15125. if(parentIdTagISNULL == FALSE)
  15126. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15127. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15128. //Update idTag information to authorization cache if supproted
  15129. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15130. {
  15131. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15132. }
  15133. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15134. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15135. authorizeRetryTimes = 0;
  15136. }
  15137. void handleBootNotificationResponse(char *payload, int gun_index)
  15138. {
  15139. mtrace();
  15140. char statusStr[12]={0};
  15141. char currentTimeStr[30]={0};
  15142. int intervalInt = 0;
  15143. DEBUG_INFO("handleBootNotificationResponse...\n");
  15144. json_object *BootNotification;
  15145. BootNotification = json_tokener_parse(payload);
  15146. if(!is_error(BootNotification))
  15147. {
  15148. // Required data
  15149. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15150. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15151. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15152. }
  15153. json_object_put(BootNotification);
  15154. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15155. BootNotificationInterval = intervalInt;
  15156. //write back to ShmOCPP16Data->BootNotification
  15157. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15158. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15159. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15160. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15161. {
  15162. BootNotificationInterval = 0;
  15163. if((intervalInt == 0) || (intervalInt >= 10))
  15164. {
  15165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15166. HeartBeatWaitTime = intervalInt;
  15167. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15168. }
  15169. server_sign = TRUE;
  15170. server_pending =FALSE;
  15171. }
  15172. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15173. {
  15174. server_pending = TRUE;
  15175. }
  15176. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15177. srand(time(NULL));
  15178. refreshStartTimer(&clientTime.Heartbeat);
  15179. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15180. SetOcppConnStatus(TRUE);
  15181. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15182. }
  15183. void handleDataTransferResponse(char *payload, int gun_index)
  15184. {
  15185. json_object *DataTransfer = json_tokener_parse(payload);
  15186. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15187. if(!is_error(DataTransfer))
  15188. {
  15189. // Required data
  15190. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15191. // Optional data
  15192. if(json_object_object_get(DataTransfer, "data") != NULL)
  15193. {
  15194. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15195. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15196. if(!is_error(Data))
  15197. {
  15198. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15199. {
  15200. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15201. {
  15202. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15203. }
  15204. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15205. {
  15206. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15207. {
  15208. 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")));
  15209. }
  15210. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15211. {
  15212. 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")));
  15213. }
  15214. }
  15215. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15216. }
  15217. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15218. {
  15219. if(json_object_object_get(Data, "status") != NULL)
  15220. {
  15221. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15222. }
  15223. if(json_object_object_get(Data, "exiResponse") != NULL)
  15224. {
  15225. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15226. }
  15227. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15228. }
  15229. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15230. {
  15231. if(json_object_object_get(Data, "status") != NULL)
  15232. {
  15233. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15234. }
  15235. if(json_object_object_get(Data, "ocspResult") != NULL)
  15236. {
  15237. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15238. }
  15239. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15240. }
  15241. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15242. {
  15243. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15244. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15245. }
  15246. else
  15247. {
  15248. if(json_object_object_get(Data, "msgId") != NULL)
  15249. {
  15250. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15251. {
  15252. 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")));
  15253. }
  15254. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15255. {
  15256. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15257. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15258. }
  15259. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyFeeAct") != NULL)
  15260. {
  15261. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15262. {
  15263. 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")));
  15264. if(json_object_object_get(Data, "occupancySN") != NULL)
  15265. 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")));
  15266. if(json_object_object_get(Data, "startTime") != NULL)
  15267. 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")));
  15268. if(json_object_object_get(Data, "duration") != NULL)
  15269. 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"));
  15270. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15271. 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"));
  15272. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].OccupancyFeeActReq = 0;
  15273. }
  15274. else
  15275. {
  15276. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15277. {
  15278. if(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq)
  15279. {
  15280. strcpy((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].response_status, "Rejected");
  15281. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq = 0;
  15282. }
  15283. }
  15284. }
  15285. }
  15286. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15287. {
  15288. if(json_object_object_get(Data, "occupancySN") != NULL)
  15289. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15290. }
  15291. }
  15292. }
  15293. }
  15294. json_object_put(Data);
  15295. }
  15296. }
  15297. json_object_put(DataTransfer);
  15298. }
  15299. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15300. {
  15301. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15302. //struct json_object *obj;
  15303. // obj = json_tokener_parse(payload);
  15304. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15305. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15306. //No fields are defined.
  15307. }
  15308. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15309. {
  15310. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15311. //struct json_object *obj;
  15312. // obj = json_tokener_parse(payload);
  15313. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15314. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15315. //No fields are defined.
  15316. }
  15317. void handleHeartbeatResponse(char *payload, int gun_index)
  15318. {
  15319. mtrace();
  15320. DEBUG_INFO("handleHeartbeatResponse...\n");
  15321. json_object *Heartbeat;
  15322. Heartbeat = json_tokener_parse(payload);
  15323. if(!is_error(Heartbeat))
  15324. {
  15325. // Required data
  15326. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15327. }
  15328. json_object_put(Heartbeat);
  15329. if(FirstHeartBeat == 0)
  15330. {
  15331. FirstHeartBeat = 1;
  15332. DEBUG_INFO("FirstHeartBeat \n");
  15333. }
  15334. HeartBeatWithNOResponse = 0;
  15335. refreshStartTimer(&clientTime.Heartbeat);
  15336. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15337. }
  15338. void handleMeterValuesResponse(char *payload, int gun_index)
  15339. {
  15340. mtrace();
  15341. DEBUG_INFO("handleMeterValuesResponse...\n");
  15342. isQueueSendable = 1;
  15343. }
  15344. void handleStartTransactionResponse(char *payload, int gun_index)
  15345. {
  15346. mtrace();
  15347. //int transactionIdInt = 0;
  15348. FILE *outfile;
  15349. char data[100]={0};
  15350. DEBUG_INFO("handleStartTransactionResponse...\n");
  15351. json_object *StartTransaction;
  15352. StartTransaction = json_tokener_parse(payload);
  15353. if(!is_error(StartTransaction))
  15354. {
  15355. // Required data
  15356. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15357. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15358. // Optional data
  15359. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15360. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15361. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15362. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15363. }
  15364. json_object_put(StartTransaction);
  15365. OCPP_updatePeriodEnergy(gun_index);
  15366. //-----------Start : write to the Queue TransactionId file -----------------//
  15367. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15368. {}
  15369. else
  15370. {
  15371. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15372. if(log == NULL)
  15373. {
  15374. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15375. return ;
  15376. }
  15377. else
  15378. {
  15379. fclose(log);
  15380. }
  15381. }
  15382. // open file for writing
  15383. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15384. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15385. {
  15386. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15387. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15388. fputs(data, outfile);
  15389. fclose (outfile);
  15390. DEBUG_INFO("Update QueueTransactionId done...\n");
  15391. }
  15392. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15393. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15394. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15395. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15396. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15397. isQueueSendable = 1;
  15398. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15399. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15400. }
  15401. void handleStatusNotificationResponse(char *payload, int gun_index)
  15402. {
  15403. mtrace();
  15404. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15405. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15406. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15407. if(gun_index != 99)
  15408. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15409. }
  15410. void handleStopTransactionnResponse(char *payload, int gun_index)
  15411. {
  15412. mtrace();
  15413. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15414. json_object *StopTransaction;
  15415. StopTransaction = json_tokener_parse(payload);
  15416. if(!is_error(StopTransaction))
  15417. {
  15418. // Optional data
  15419. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15420. {
  15421. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15422. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15423. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15424. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15425. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15426. }
  15427. }
  15428. json_object_put(StopTransaction);
  15429. isQueueSendable = 1;
  15430. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15431. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15432. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15433. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15434. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15435. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15436. }
  15437. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15438. {
  15439. mtrace();
  15440. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15441. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15442. }
  15443. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15444. {
  15445. mtrace();
  15446. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15447. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15448. }
  15449. void handleSignCertificateResponse(char *payload, int gun_index)
  15450. {
  15451. mtrace();
  15452. DEBUG_INFO("handleSignCertificateResponse...\n");
  15453. json_object *SignCertificate;
  15454. SignCertificate = json_tokener_parse(payload);
  15455. if(!is_error(SignCertificate))
  15456. {
  15457. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15458. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15459. }
  15460. json_object_put(SignCertificate);
  15461. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15462. }
  15463. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15464. {
  15465. mtrace();
  15466. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15467. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15468. }
  15469. //==========================================
  15470. // Handle Error routine
  15471. //==========================================
  15472. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15473. {
  15474. mtrace();
  15475. #ifdef SystemLogMessage
  15476. DEBUG_INFO("errorCode: %s\n", errorCode);
  15477. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15478. DEBUG_INFO("errorDetails: %s\n", payload);
  15479. #endif
  15480. }
  15481. //===============================================
  15482. // Common routine
  15483. //===============================================
  15484. int initialConfigurationTable(void)
  15485. {
  15486. //clock_t start_t, end_t, total_t;
  15487. FILE *fp;
  15488. FILE *outfile;
  15489. char str[512]={0};
  15490. char sstr[256]={0};
  15491. int c = 0;
  15492. char *loc;
  15493. int confVersion = 23;
  15494. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15495. //start_t = clock();
  15496. //printf("Starting of the program, start_t = %ld\n", start_t);
  15497. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15498. // Check configuration file size is correct
  15499. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15500. {
  15501. struct stat st;
  15502. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15503. if(st.st_size < 3100)
  15504. {
  15505. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15506. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15507. }
  15508. }
  15509. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15510. {
  15511. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15512. if(outfile == NULL)
  15513. {
  15514. DEBUG_INFO("Error opening file\n");
  15515. return FALSE;
  15516. }
  15517. /*Core Profile*/
  15518. //AllowOfflineTxForUnknownId
  15519. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15523. //AuthorizationCacheEnabled
  15524. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15528. //AuthorizeRemoteTxRequests
  15529. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15533. //BlinkRepeat
  15534. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15538. //ClockAlignedDataInterval
  15539. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15543. //ConnectionTimeOut
  15544. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15546. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15548. else
  15549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15551. //GetConfigurationMaxKeys
  15552. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15556. // HeartbeatInterval
  15557. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15561. // LightIntensity
  15562. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15566. // LocalAuthorizeOffline
  15567. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15571. // LocalPreAuthorize
  15572. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15576. // MaxEnergyOnInvalidId
  15577. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15581. // MeterValuesAlignedData
  15582. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15585. 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" );
  15586. else
  15587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15589. // MeterValuesAlignedDataMaxLength
  15590. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15594. else
  15595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15597. // MeterValuesSampledData
  15598. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15600. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15601. 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" );
  15602. else
  15603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15605. // MeterValuesSampledDataMaxLength
  15606. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15610. else
  15611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15613. // MeterValueSampleInterval
  15614. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15618. // MinimumStatusDuration
  15619. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15622. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15624. // NumberOfConnectors
  15625. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15627. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15628. {
  15629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15630. }
  15631. else
  15632. {
  15633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15634. }
  15635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15636. // ResetRetries
  15637. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15641. // ConnectorPhaseRotation
  15642. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15646. // ConnectorPhaseRotationMaxLength
  15647. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15651. // StopTransactionOnEVSideDisconnect
  15652. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15656. // StopTransactionOnInvalidId
  15657. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15661. // StopTxnAlignedData
  15662. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15666. // StopTxnAlignedDataMaxLength
  15667. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15669. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15670. {
  15671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 8);
  15672. }
  15673. else
  15674. {
  15675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 10);
  15676. }
  15677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15678. // StopTxnSampledData
  15679. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15683. // StopTxnSampledDataMaxLength
  15684. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15686. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15687. {
  15688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 8);
  15689. }
  15690. else
  15691. {
  15692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 10);
  15693. }
  15694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15695. // SupportedFeatureProfiles
  15696. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15700. // SupportedFeatureProfilesMaxLength
  15701. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15705. // TransactionMessageAttempts
  15706. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15709. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15711. // TransactionMessageRetryInterval
  15712. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15715. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15717. // UnlockConnectorOnEVSideDisconnect
  15718. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15722. // WebSocketPingInterval
  15723. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15727. // QueueOffLineMeterValues
  15728. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15732. // AuthorizationKey
  15733. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15737. // SecurityProfile
  15738. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15742. // DefaultPrice
  15743. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15747. // CustomDisplayCostAndPrice
  15748. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15752. // CustomIdleFeeAfterStop
  15753. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15757. // TimeOffset
  15758. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15762. // NextTimeOffsetTransitionDateTime
  15763. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15767. // TimeOffsetNextTransition
  15768. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15772. // SystemUptimeSec
  15773. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15777. // FreeVend
  15778. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15782. // FreeVendIdtag
  15783. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15787. // OcppServer
  15788. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15790. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15792. // MaintainServer
  15793. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15795. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15797. // StatusNotificationPeriodically
  15798. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15802. // StatusNotificationInterval
  15803. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15807. // PreAuthAmount
  15808. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15812. // isEnableLocalPowerSharing
  15813. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15817. // PowerSharingServerIP
  15818. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15820. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15822. // EVCCID_PREFIX
  15823. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15827. // OffLineMaxChargingPower
  15828. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15832. // Configuration Version
  15833. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15837. // Charging profile refresh interval
  15838. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15842. // CpoName
  15843. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15847. // Ocpp Software certificated version
  15848. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15852. //* Local Auth List Management Profile*/
  15853. #if 0
  15854. //For OCTT Test Case
  15855. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15858. #endif
  15859. #if 1
  15860. //LocalAuthListEnabled
  15861. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15865. #endif
  15866. //LocalAuthListMaxLength
  15867. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15871. //SendLocalListMaxLength
  15872. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15876. //ReserveConnectorZeroSupported
  15877. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15881. //* Smart Charging Profile */
  15882. //ChargeProfileMaxStackLevel
  15883. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15887. // ChargingScheduleAllowedChargingRateUnit
  15888. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15892. // ChargingScheduleMaxPeriods
  15893. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15897. // ConnectorSwitch3to1PhaseSupported
  15898. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15902. // MaxChargingProfilesInstalled
  15903. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15907. fclose(outfile);
  15908. }
  15909. else
  15910. {
  15911. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15912. char keystr[60]={0};
  15913. char readonlystr[10]={0};
  15914. char valuestr[256]={0};
  15915. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15916. if(fp == NULL) {
  15917. DEBUG_INFO("Error opening file");
  15918. return FALSE;
  15919. }
  15920. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15921. {
  15922. //DEBUG_INFO("Get Configuration \n");
  15923. if(strlen(str) > 0)
  15924. {
  15925. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15926. //*************************key*********************************/
  15927. if(strstr(str, "key") != NULL)
  15928. {
  15929. loc = strstr(str, "key");
  15930. c = 0;
  15931. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15932. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15933. {
  15934. sstr[c] = loc[strlen("key")+3+c];
  15935. c++;
  15936. }
  15937. sstr[c] = '\0';
  15938. strcpy(keystr,sstr);
  15939. }
  15940. //*************************readonly*********************************/
  15941. if(strstr(str, "readonly") != NULL)
  15942. {
  15943. loc = strstr(str, "readonly");
  15944. c = 0;
  15945. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15946. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  15947. {
  15948. sstr[c] = loc[strlen("readonly")+2+c];
  15949. c++;
  15950. }
  15951. sstr[c] = '\0';
  15952. strcpy(readonlystr,sstr);
  15953. }
  15954. //*************************value*********************************/
  15955. if(strstr(str, "value") != NULL)
  15956. {
  15957. loc = strstr(str, "value");
  15958. c = 0;
  15959. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15960. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15961. {
  15962. sstr[c] = loc[strlen("value")+3+c];
  15963. c++;
  15964. }
  15965. sstr[c] = '\0';
  15966. strcpy(valuestr,sstr);
  15967. }
  15968. // DEBUG_INFO("keystr=%s\n",keystr);
  15969. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15970. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15971. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15972. {
  15973. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15974. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15976. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15977. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15978. }
  15979. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15980. {
  15981. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15982. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  15984. }
  15985. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  15986. {
  15987. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  15989. }
  15990. if(strcmp(keystr, "BlinkRepeat") == 0)
  15991. {
  15992. //Charger.BlinkRepeat = Integer.parseInt(value);
  15993. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  15995. }
  15996. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  15997. {
  15998. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  16000. }
  16001. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16002. {
  16003. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16005. }
  16006. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16007. {
  16008. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16010. }
  16011. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16012. {
  16013. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16015. HeartBeatWaitTime = atoi(valuestr);
  16016. }
  16017. if(strcmp(keystr, "LightIntensity") == 0)
  16018. {
  16019. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16021. }
  16022. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16023. {
  16024. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16026. }
  16027. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16028. {
  16029. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16031. }
  16032. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16033. {
  16034. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16036. }
  16037. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16038. {
  16039. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16041. }
  16042. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16043. {
  16044. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16046. }
  16047. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16048. {
  16049. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16051. }
  16052. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16053. {
  16054. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16056. }
  16057. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16058. {
  16059. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16061. }
  16062. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16063. {
  16064. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16066. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16067. }
  16068. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16069. {
  16070. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16072. }
  16073. if(strcmp(keystr, "ResetRetries") == 0)
  16074. {
  16075. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16077. }
  16078. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16079. {
  16080. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16082. }
  16083. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16084. {
  16085. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16087. }
  16088. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16089. {
  16090. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16092. }
  16093. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16094. {
  16095. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16097. }
  16098. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16099. {
  16100. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16101. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16102. }
  16103. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16104. {
  16105. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16107. }
  16108. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16109. {
  16110. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16112. }
  16113. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16114. {
  16115. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16117. }
  16118. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16119. {
  16120. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16122. }
  16123. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16124. {
  16125. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16127. }
  16128. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16129. {
  16130. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16132. TransactionMessageAttemptsValue = atoi(valuestr);
  16133. }
  16134. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16135. {
  16136. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16138. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16139. }
  16140. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16141. {
  16142. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16144. }
  16145. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16146. {
  16147. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16149. }
  16150. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16151. {
  16152. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16154. }
  16155. if(strcmp(keystr, "AuthorizationKey") == 0)
  16156. {
  16157. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16158. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16160. }
  16161. if(strcmp(keystr, "SecurityProfile") == 0)
  16162. {
  16163. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16165. }
  16166. if(strcmp(keystr, "DefaultPrice") == 0)
  16167. {
  16168. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16170. }
  16171. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16172. {
  16173. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16175. }
  16176. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16177. {
  16178. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16180. }
  16181. if(strcmp(keystr, "TimeOffset") == 0)
  16182. {
  16183. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16185. }
  16186. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16187. {
  16188. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16190. }
  16191. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16192. {
  16193. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16195. }
  16196. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16197. {
  16198. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16200. }
  16201. if(strcmp(keystr, "FreeVend") == 0)
  16202. {
  16203. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16205. }
  16206. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16207. {
  16208. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16210. }
  16211. if(strcmp(keystr, "OcppServer") == 0)
  16212. {
  16213. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16214. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16215. }
  16216. if(strcmp(keystr, "MaintainServer") == 0)
  16217. {
  16218. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16219. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16220. }
  16221. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16222. {
  16223. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16225. }
  16226. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16227. {
  16228. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16230. }
  16231. if(strcmp(keystr, "PreAuthAmount") == 0)
  16232. {
  16233. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16235. }
  16236. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16237. {
  16238. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16240. }
  16241. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16242. {
  16243. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16244. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16245. }
  16246. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16247. {
  16248. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16250. }
  16251. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16252. {
  16253. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16255. }
  16256. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16257. {
  16258. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16260. }
  16261. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16262. {
  16263. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16265. }
  16266. if(strcmp(keystr, "CpoName") == 0)
  16267. {
  16268. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16270. }
  16271. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16272. {
  16273. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16275. }
  16276. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16277. {
  16278. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16280. }
  16281. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16282. {
  16283. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16285. }
  16286. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16287. {
  16288. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16290. }
  16291. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16292. {
  16293. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16295. }
  16296. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16297. {
  16298. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16300. }
  16301. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16302. {
  16303. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16305. }
  16306. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16307. {
  16308. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16310. }
  16311. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16312. {
  16313. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16315. }
  16316. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16317. {
  16318. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16320. }
  16321. }
  16322. }
  16323. fclose(fp);
  16324. }
  16325. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16326. {
  16327. return PASS;
  16328. }
  16329. else
  16330. {
  16331. return FAIL;
  16332. }
  16333. }
  16334. void StoreConfigurationTable(void)
  16335. {
  16336. FILE *outfile;
  16337. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16338. if(outfile == NULL)
  16339. {
  16340. DEBUG_INFO("Error opening file");
  16341. return ;
  16342. }
  16343. /*Core Profile*/
  16344. //AllowOfflineTxForUnknownId
  16345. /*
  16346. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16347. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16350. */
  16351. //DEBUG_INFO("data=%s\n",data);
  16352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16353. //AuthorizationCacheEnabled
  16354. /*
  16355. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16358. */
  16359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16360. //AuthorizeRemoteTxRequests
  16361. /*
  16362. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16365. */
  16366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16367. //BlinkRepeat
  16368. /*
  16369. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16372. */
  16373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16374. //ClockAlignedDataInterval
  16375. /*
  16376. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16379. */
  16380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16381. //ConnectionTimeOut
  16382. /*
  16383. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16386. */
  16387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16388. //GetConfigurationMaxKeys
  16389. /*
  16390. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16393. */
  16394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16395. // HeartbeatInterval
  16396. /*
  16397. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16400. */
  16401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16402. // LightIntensity
  16403. /*
  16404. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16407. */
  16408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16409. // LocalAuthorizeOffline
  16410. /*
  16411. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16414. */
  16415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16416. // LocalPreAuthorize
  16417. /*
  16418. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16421. */
  16422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16423. // MaxEnergyOnInvalidId
  16424. /*
  16425. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16428. */
  16429. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16431. // MeterValuesAlignedData
  16432. /*
  16433. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16436. */
  16437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16438. // MeterValuesAlignedDataMaxLength
  16439. /*
  16440. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16443. */
  16444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16445. // MeterValuesSampledData
  16446. /*
  16447. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16450. */
  16451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16452. // MeterValuesSampledDataMaxLength
  16453. /*
  16454. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16457. */
  16458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16459. // MeterValueSampleInterval
  16460. /*
  16461. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16464. */
  16465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16466. // MinimumStatusDuration
  16467. /*
  16468. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16471. */
  16472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16473. // NumberOfConnectors
  16474. /*
  16475. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16478. {
  16479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16480. }
  16481. else
  16482. {
  16483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16484. }
  16485. */
  16486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16487. // ResetRetries
  16488. /*
  16489. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16492. */
  16493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16494. // ConnectorPhaseRotation
  16495. /*
  16496. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16499. */
  16500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16501. // ConnectorPhaseRotationMaxLength
  16502. /*
  16503. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16506. */
  16507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16508. // StopTransactionOnEVSideDisconnect
  16509. /*
  16510. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16513. */
  16514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16515. // StopTransactionOnInvalidId
  16516. /*
  16517. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16520. */
  16521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16522. // StopTxnAlignedData
  16523. /*
  16524. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16527. */
  16528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16529. // StopTxnAlignedDataMaxLength
  16530. /*
  16531. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16534. */
  16535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16536. // StopTxnSampledData
  16537. /*
  16538. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16541. */
  16542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16543. // StopTxnSampledDataMaxLength
  16544. /*
  16545. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16548. */
  16549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16550. // SupportedFeatureProfiles
  16551. /*
  16552. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16555. */
  16556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16557. // SupportedFeatureProfilesMaxLength
  16558. /*
  16559. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16562. */
  16563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16564. // TransactionMessageAttempts
  16565. /*
  16566. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16569. */
  16570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16571. // TransactionMessageRetryInterval
  16572. /*
  16573. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16576. */
  16577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16578. // UnlockConnectorOnEVSideDisconnect
  16579. /*
  16580. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16583. */
  16584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16585. // WebSocketPingInterval
  16586. /*
  16587. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16590. */
  16591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16592. // QueueOffLineMeterValues
  16593. /*
  16594. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16597. */
  16598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16599. // AuthorizationKey
  16600. /*
  16601. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16604. */
  16605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16606. // SecurityProfile
  16607. /*
  16608. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16611. */
  16612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16613. // DefaultPrice
  16614. /*
  16615. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16618. */
  16619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16620. // CustomDisplayCostAndPrice
  16621. /*
  16622. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16625. */
  16626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16627. // CustomIdleFeeAfterStop
  16628. /*
  16629. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16632. */
  16633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16634. // TimeOffset
  16635. /*
  16636. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16639. */
  16640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16641. // NextTimeOffsetTransitionDateTime
  16642. /*
  16643. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16646. */
  16647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16648. // TimeOffsetNextTransition
  16649. /*
  16650. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16653. */
  16654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16655. // SystemUptimeSec
  16656. /*
  16657. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16660. */
  16661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16662. // FreeVend
  16663. /*
  16664. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16667. */
  16668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16669. // FreeVendIdtag
  16670. /*
  16671. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16674. */
  16675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16676. // OcppServer
  16677. /*
  16678. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16681. */
  16682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16683. // MaintainServer
  16684. /*
  16685. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16688. */
  16689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16690. // StatusNotificationPeriodically
  16691. /*
  16692. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16695. */
  16696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16697. // StatusNotificationInterval
  16698. /*
  16699. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16702. */
  16703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16704. // PreAuthAmount
  16705. /*
  16706. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16709. */
  16710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16711. // isEnableLocalPowerSharing
  16712. /*
  16713. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16716. */
  16717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16718. // PowerSharingServerIP
  16719. /*
  16720. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16723. */
  16724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16725. // EVCCID_PREFIX
  16726. /*
  16727. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16730. */
  16731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16732. // OffLineMaxChargingPower
  16733. /*
  16734. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16737. */
  16738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16739. // ConfigurationVersion
  16740. /*
  16741. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16744. */
  16745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16746. // CharingProfileRefreshInterval
  16747. /*
  16748. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16751. */
  16752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16753. // CpoName
  16754. /*
  16755. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16758. */
  16759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16760. // OcppSoftwareVersion
  16761. /*
  16762. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16765. */
  16766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16767. //* Local Auth List Management Profile*/
  16768. //LocalAuthListEnabled
  16769. /*
  16770. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16773. */
  16774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16775. //LocalAuthListMaxLength
  16776. /*
  16777. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16780. */
  16781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16782. //SendLocalListMaxLength
  16783. /*
  16784. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16787. */
  16788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16789. //ReserveConnectorZeroSupported
  16790. /*
  16791. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16794. */
  16795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16796. //* Smart Charging Profile */
  16797. //ChargeProfileMaxStackLevel
  16798. /*
  16799. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16802. */
  16803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16804. // ChargingScheduleAllowedChargingRateUnit
  16805. /*
  16806. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16809. */
  16810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16811. // ChargingScheduleMaxPeriods
  16812. /*
  16813. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16816. */
  16817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16818. // ConnectorSwitch3to1PhaseSupported
  16819. /*
  16820. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16823. */
  16824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16825. // MaxChargingProfilesInstalled
  16826. /*
  16827. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16830. */
  16831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16832. fclose(outfile);
  16833. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16834. }
  16835. void getKeyValue(char *keyReq)
  16836. {
  16837. int isEmpty = FALSE;
  16838. int isKnowKey = FALSE;
  16839. DEBUG_INFO("keyReq = %s\n", keyReq);
  16840. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16841. isEmpty = TRUE;
  16842. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16843. {
  16844. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16846. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16847. {
  16848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16849. }
  16850. else
  16851. {
  16852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16853. }
  16854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16855. isKnowKey = TRUE;
  16856. }
  16857. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16858. {
  16859. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16862. {
  16863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16864. }
  16865. else
  16866. {
  16867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16868. }
  16869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16870. isKnowKey = TRUE;
  16871. }
  16872. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16873. {
  16874. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16877. {
  16878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16879. }
  16880. else
  16881. {
  16882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16883. }
  16884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16885. isKnowKey = TRUE;
  16886. }
  16887. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16888. {
  16889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16892. {
  16893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16894. }
  16895. else
  16896. {
  16897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16898. }
  16899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16900. isKnowKey = TRUE;
  16901. }
  16902. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16903. {
  16904. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16907. {
  16908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16909. }
  16910. else
  16911. {
  16912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16913. }
  16914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16915. isKnowKey = TRUE;
  16916. }
  16917. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16918. {
  16919. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16922. {
  16923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  16924. }
  16925. else
  16926. {
  16927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  16928. }
  16929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  16930. isKnowKey = TRUE;
  16931. }
  16932. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  16933. {
  16934. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  16935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  16936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16937. {
  16938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  16939. }
  16940. else
  16941. {
  16942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  16943. }
  16944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  16945. isKnowKey = TRUE;
  16946. }
  16947. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  16948. {
  16949. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  16950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  16951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16952. {
  16953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  16954. }
  16955. else
  16956. {
  16957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  16958. }
  16959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  16960. isKnowKey = TRUE;
  16961. }
  16962. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  16963. {
  16964. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  16965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  16966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16967. {
  16968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  16969. }
  16970. else
  16971. {
  16972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  16973. }
  16974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  16975. isKnowKey = TRUE;
  16976. }
  16977. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  16978. {
  16979. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  16980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  16981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16982. {
  16983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  16984. }
  16985. else
  16986. {
  16987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  16988. }
  16989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  16990. isKnowKey = TRUE;
  16991. }
  16992. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  16993. {
  16994. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  16995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  16996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16997. {
  16998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  16999. }
  17000. else
  17001. {
  17002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17003. }
  17004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17005. isKnowKey = TRUE;
  17006. }
  17007. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17008. {
  17009. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17012. {
  17013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17014. }
  17015. else
  17016. {
  17017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17018. }
  17019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17020. isKnowKey = TRUE;
  17021. }
  17022. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17023. {
  17024. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17027. {
  17028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17029. }
  17030. else
  17031. {
  17032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17033. }
  17034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17035. isKnowKey = TRUE;
  17036. }
  17037. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17038. {
  17039. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17042. {
  17043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17044. }
  17045. else
  17046. {
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17048. }
  17049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17050. isKnowKey = TRUE;
  17051. }
  17052. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17053. {
  17054. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17057. {
  17058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17059. }
  17060. else
  17061. {
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17063. }
  17064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17065. isKnowKey = TRUE;
  17066. }
  17067. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17068. {
  17069. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17072. {
  17073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17074. }
  17075. else
  17076. {
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17078. }
  17079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17080. isKnowKey = TRUE;
  17081. }
  17082. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17083. {
  17084. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17087. {
  17088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17089. }
  17090. else
  17091. {
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17093. }
  17094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17095. isKnowKey = TRUE;
  17096. }
  17097. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17098. {
  17099. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17102. {
  17103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17104. }
  17105. else
  17106. {
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17108. }
  17109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17110. isKnowKey = TRUE;
  17111. }
  17112. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17113. {
  17114. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17116. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17117. {
  17118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17119. }
  17120. else
  17121. {
  17122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17123. }
  17124. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17126. isKnowKey = TRUE;
  17127. }
  17128. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17129. {
  17130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17133. {
  17134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17135. }
  17136. else
  17137. {
  17138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17139. }
  17140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17141. isKnowKey = TRUE;
  17142. }
  17143. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17144. {
  17145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17148. {
  17149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17150. }
  17151. else
  17152. {
  17153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17154. }
  17155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17156. isKnowKey = TRUE;
  17157. }
  17158. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17159. {
  17160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17163. {
  17164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17165. }
  17166. else
  17167. {
  17168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17169. }
  17170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17171. isKnowKey = TRUE;
  17172. }
  17173. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17174. {
  17175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17178. {
  17179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17180. }
  17181. else
  17182. {
  17183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17184. }
  17185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17186. isKnowKey = TRUE;
  17187. }
  17188. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17189. {
  17190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17193. {
  17194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17195. }
  17196. else
  17197. {
  17198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17199. }
  17200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17201. isKnowKey = TRUE;
  17202. }
  17203. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17204. {
  17205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17208. {
  17209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17210. }
  17211. else
  17212. {
  17213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17214. }
  17215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17216. isKnowKey = TRUE;
  17217. }
  17218. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17219. {
  17220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17223. {
  17224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17225. }
  17226. else
  17227. {
  17228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17229. }
  17230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17231. isKnowKey = TRUE;
  17232. }
  17233. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17234. {
  17235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17238. {
  17239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17240. }
  17241. else
  17242. {
  17243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17244. }
  17245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17246. isKnowKey = TRUE;
  17247. }
  17248. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17249. {
  17250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17253. {
  17254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17255. }
  17256. else
  17257. {
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17259. }
  17260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17261. isKnowKey = TRUE;
  17262. }
  17263. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17264. {
  17265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17268. {
  17269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17270. }
  17271. else
  17272. {
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17274. }
  17275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17276. isKnowKey = TRUE;
  17277. }
  17278. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17279. {
  17280. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17283. {
  17284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17285. }
  17286. else
  17287. {
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17289. }
  17290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17291. isKnowKey = TRUE;
  17292. }
  17293. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17294. {
  17295. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17298. {
  17299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17300. }
  17301. else
  17302. {
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17304. }
  17305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17306. isKnowKey = TRUE;
  17307. }
  17308. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17309. {
  17310. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17313. {
  17314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17315. }
  17316. else
  17317. {
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17319. }
  17320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17321. isKnowKey = TRUE;
  17322. }
  17323. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17324. {
  17325. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17327. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17328. {
  17329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17330. }
  17331. else
  17332. {
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17334. }
  17335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17336. isKnowKey = TRUE;
  17337. }
  17338. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17339. {
  17340. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17343. {
  17344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17345. }
  17346. else
  17347. {
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17349. }
  17350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17351. isKnowKey = TRUE;
  17352. }
  17353. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17354. {
  17355. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17358. {
  17359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17360. }
  17361. else
  17362. {
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17364. }
  17365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17366. isKnowKey = TRUE;
  17367. }
  17368. /*
  17369. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17370. {
  17371. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17374. {
  17375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17376. }
  17377. else
  17378. {
  17379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17380. }
  17381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17382. isKnowKey = TRUE;
  17383. }*/
  17384. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17385. {
  17386. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17388. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17389. {
  17390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17391. }
  17392. else
  17393. {
  17394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17395. }
  17396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17397. isKnowKey = TRUE;
  17398. }
  17399. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17400. {
  17401. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17404. {
  17405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17406. }
  17407. else
  17408. {
  17409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17410. }
  17411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17412. isKnowKey = TRUE;
  17413. }
  17414. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17415. {
  17416. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17419. {
  17420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17421. }
  17422. else
  17423. {
  17424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17425. }
  17426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17427. isKnowKey = TRUE;
  17428. }
  17429. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17430. {
  17431. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17434. {
  17435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17436. }
  17437. else
  17438. {
  17439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17440. }
  17441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17442. isKnowKey = TRUE;
  17443. }
  17444. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17445. {
  17446. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17449. {
  17450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17451. }
  17452. else
  17453. {
  17454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17455. }
  17456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17457. isKnowKey = TRUE;
  17458. }
  17459. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17460. {
  17461. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17464. {
  17465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17466. }
  17467. else
  17468. {
  17469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17470. }
  17471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17472. isKnowKey = TRUE;
  17473. }
  17474. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17475. {
  17476. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17479. {
  17480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17481. }
  17482. else
  17483. {
  17484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17485. }
  17486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17487. isKnowKey = TRUE;
  17488. }
  17489. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17490. {
  17491. struct sysinfo s_info;
  17492. int error = sysinfo(&s_info);
  17493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17496. {
  17497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17498. }
  17499. else
  17500. {
  17501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17502. }
  17503. if(error != 0)
  17504. {
  17505. DEBUG_WARN("System uptime get error: %d\n", error);
  17506. }
  17507. else
  17508. {
  17509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17510. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17511. }
  17512. isKnowKey = TRUE;
  17513. }
  17514. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17515. {
  17516. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17519. {
  17520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17521. }
  17522. else
  17523. {
  17524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17525. }
  17526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17527. isKnowKey = TRUE;
  17528. }
  17529. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17530. {
  17531. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17534. {
  17535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17536. }
  17537. else
  17538. {
  17539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17540. }
  17541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17542. isKnowKey = TRUE;
  17543. }
  17544. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17545. {
  17546. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17549. {
  17550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17551. }
  17552. else
  17553. {
  17554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17555. }
  17556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17557. isKnowKey = TRUE;
  17558. }
  17559. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17560. {
  17561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17564. {
  17565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17566. }
  17567. else
  17568. {
  17569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17570. }
  17571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17572. isKnowKey = TRUE;
  17573. }
  17574. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17575. {
  17576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17579. {
  17580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17581. }
  17582. else
  17583. {
  17584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17585. }
  17586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17587. isKnowKey = TRUE;
  17588. }
  17589. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17590. {
  17591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17594. {
  17595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17596. }
  17597. else
  17598. {
  17599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17600. }
  17601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17602. isKnowKey = TRUE;
  17603. }
  17604. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17605. {
  17606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17609. {
  17610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17611. }
  17612. else
  17613. {
  17614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17615. }
  17616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17617. isKnowKey = TRUE;
  17618. }
  17619. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17620. {
  17621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17624. {
  17625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17626. }
  17627. else
  17628. {
  17629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17630. }
  17631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17632. isKnowKey = TRUE;
  17633. }
  17634. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17635. {
  17636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17639. {
  17640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17641. }
  17642. else
  17643. {
  17644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17645. }
  17646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17647. isKnowKey = TRUE;
  17648. }
  17649. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17650. {
  17651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17654. {
  17655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17656. }
  17657. else
  17658. {
  17659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17660. }
  17661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17662. isKnowKey = TRUE;
  17663. }
  17664. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17665. {
  17666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17669. {
  17670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17671. }
  17672. else
  17673. {
  17674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17675. }
  17676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17677. isKnowKey = TRUE;
  17678. }
  17679. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17680. {
  17681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17684. {
  17685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17686. }
  17687. else
  17688. {
  17689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17690. }
  17691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17692. isKnowKey = TRUE;
  17693. }
  17694. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17695. {
  17696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17699. {
  17700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17701. }
  17702. else
  17703. {
  17704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17705. }
  17706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17707. isKnowKey = TRUE;
  17708. }
  17709. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17710. {
  17711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17714. {
  17715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17716. }
  17717. else
  17718. {
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17720. }
  17721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17722. isKnowKey = TRUE;
  17723. }
  17724. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17725. {
  17726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17729. {
  17730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17731. }
  17732. else
  17733. {
  17734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17735. }
  17736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17737. isKnowKey = TRUE;
  17738. }
  17739. #if 1
  17740. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17741. {
  17742. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17744. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17745. {
  17746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17747. }
  17748. else
  17749. {
  17750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17751. }
  17752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17753. isKnowKey = TRUE;
  17754. }
  17755. #endif
  17756. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17757. {
  17758. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17760. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17761. {
  17762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17763. }
  17764. else
  17765. {
  17766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17767. }
  17768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17769. isKnowKey = TRUE;
  17770. }
  17771. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17772. {
  17773. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17775. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17776. {
  17777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17778. }
  17779. else
  17780. {
  17781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17782. }
  17783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17784. isKnowKey = TRUE;
  17785. }
  17786. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17787. {
  17788. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17790. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17791. {
  17792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17793. }
  17794. else
  17795. {
  17796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17797. }
  17798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17799. isKnowKey = TRUE;
  17800. }
  17801. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17802. {
  17803. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17805. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17806. {
  17807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17808. }
  17809. else
  17810. {
  17811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17812. }
  17813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17814. isKnowKey = TRUE;
  17815. }
  17816. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17817. {
  17818. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17820. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17821. {
  17822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17823. }
  17824. else
  17825. {
  17826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17827. }
  17828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17829. isKnowKey = TRUE;
  17830. }
  17831. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17832. {
  17833. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17835. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17836. {
  17837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17838. }
  17839. else
  17840. {
  17841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17842. }
  17843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17844. isKnowKey = TRUE;
  17845. }
  17846. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17847. {
  17848. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17850. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17851. {
  17852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17853. }
  17854. else
  17855. {
  17856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17857. }
  17858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17859. isKnowKey = TRUE;
  17860. }
  17861. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17862. {
  17863. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17865. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17866. {
  17867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17868. }
  17869. else
  17870. {
  17871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17872. }
  17873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17874. isKnowKey = TRUE;
  17875. }
  17876. //=========================================================
  17877. if(!isEmpty && !isKnowKey)
  17878. {
  17879. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17880. strcpy(unknownkey[UnknownKeynum], keyReq);
  17881. UnknownKeynum = UnknownKeynum + 1;
  17882. }
  17883. }
  17884. void processUnkownKey(void)
  17885. {
  17886. DEBUG_INFO("processUnkownKey...\n");
  17887. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17888. for(int index=0; index < UnknownKeynum; index++)
  17889. {
  17890. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17891. {
  17892. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17893. }
  17894. }
  17895. }
  17896. int setKeyValue(char *key, char *value)
  17897. {
  17898. int isSuccess = NotSupported;
  17899. int check_ascii=0;
  17900. char str[501]={0};
  17901. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17902. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17903. {
  17904. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17906. {
  17907. strcpy(str, (const char*)value);
  17908. for(int i = 0; str[i]; i++){
  17909. str[i] = tolower(str[i]);
  17910. }
  17911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17912. isSuccess = ConfigurationStatus_Accepted;
  17913. }
  17914. else
  17915. {
  17916. isSuccess = ConfigurationStatus_Rejected;
  17917. }
  17918. }
  17919. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  17920. {
  17921. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  17922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17923. {
  17924. strcpy(str, (const char*)value);
  17925. for(int i = 0; str[i]; i++){
  17926. str[i] = tolower(str[i]);
  17927. }
  17928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17929. isSuccess = ConfigurationStatus_Accepted;
  17930. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  17931. }
  17932. else
  17933. {
  17934. isSuccess = ConfigurationStatus_Rejected;
  17935. }
  17936. }
  17937. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  17938. {
  17939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17940. {
  17941. strcpy(str, (const char*)value);
  17942. for(int i = 0; str[i]; i++)
  17943. {
  17944. str[i] = tolower(str[i]);
  17945. }
  17946. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  17947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17948. isSuccess = ConfigurationStatus_Accepted;
  17949. }
  17950. else
  17951. {
  17952. isSuccess = ConfigurationStatus_Rejected;
  17953. }
  17954. }
  17955. if(strcmp(key, "BlinkRepeat") == 0)
  17956. {
  17957. //Charger.BlinkRepeat = Integer.parseInt(value);
  17958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17959. {
  17960. check_ascii = value[0];
  17961. if( (check_ascii < 48) || (check_ascii > 57) )
  17962. {
  17963. isSuccess = ConfigurationStatus_Rejected;
  17964. }
  17965. else
  17966. {
  17967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  17968. isSuccess = ConfigurationStatus_Accepted;
  17969. }
  17970. }
  17971. else
  17972. {
  17973. isSuccess = ConfigurationStatus_Rejected;
  17974. }
  17975. }
  17976. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  17977. {
  17978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17979. {
  17980. check_ascii = value[0];
  17981. if( (check_ascii < 48) || (check_ascii > 57) )
  17982. {
  17983. isSuccess = ConfigurationStatus_Rejected;
  17984. }
  17985. else
  17986. {
  17987. if((atoi(value) == 0) || (atoi(value) >= 5))
  17988. {
  17989. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  17990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  17991. isSuccess = ConfigurationStatus_Accepted;
  17992. }
  17993. else
  17994. isSuccess = ConfigurationStatus_Rejected;
  17995. }
  17996. }
  17997. else
  17998. {
  17999. isSuccess = ConfigurationStatus_Rejected;
  18000. }
  18001. }
  18002. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18003. {
  18004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18005. {
  18006. check_ascii = value[0];
  18007. if( (check_ascii < 48) || (check_ascii > 57) )
  18008. {
  18009. isSuccess = ConfigurationStatus_Rejected;
  18010. }
  18011. else
  18012. {
  18013. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18015. isSuccess = ConfigurationStatus_Accepted;
  18016. }
  18017. }
  18018. else
  18019. {
  18020. isSuccess = ConfigurationStatus_Rejected;
  18021. }
  18022. }
  18023. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18024. {
  18025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18026. {
  18027. check_ascii = value[0];
  18028. if( (check_ascii < 48) || (check_ascii > 57) )
  18029. {
  18030. isSuccess = ConfigurationStatus_Rejected;
  18031. }
  18032. else
  18033. {
  18034. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18036. isSuccess = ConfigurationStatus_Accepted;
  18037. }
  18038. }
  18039. else
  18040. {
  18041. isSuccess = ConfigurationStatus_Rejected;
  18042. }
  18043. }
  18044. if(strcmp(key, "HeartbeatInterval") == 0)
  18045. {
  18046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18047. {
  18048. check_ascii = value[0];
  18049. if( (check_ascii < 48) || (check_ascii > 57) )
  18050. {
  18051. isSuccess = ConfigurationStatus_Rejected;
  18052. }
  18053. else
  18054. {
  18055. if((atoi(value) == 0) || (atoi(value) >= 10))
  18056. {
  18057. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18059. HeartBeatWaitTime = atoi(value);
  18060. isSuccess = ConfigurationStatus_Accepted;
  18061. }
  18062. else
  18063. {
  18064. isSuccess = ConfigurationStatus_Rejected;
  18065. }
  18066. }
  18067. }
  18068. else
  18069. {
  18070. isSuccess = ConfigurationStatus_Rejected;
  18071. }
  18072. }
  18073. if(strcmp(key, "LightIntensity") == 0)
  18074. {
  18075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18076. {
  18077. check_ascii = value[0];
  18078. if( (check_ascii < 48) || (check_ascii > 57) )
  18079. {
  18080. isSuccess = ConfigurationStatus_Rejected;
  18081. }
  18082. else
  18083. {
  18084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18085. isSuccess = ConfigurationStatus_Accepted;
  18086. }
  18087. }
  18088. else
  18089. {
  18090. isSuccess = ConfigurationStatus_Rejected;
  18091. }
  18092. }
  18093. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18094. {
  18095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18096. {
  18097. strcpy(str, (const char*)value);
  18098. for(int i = 0; str[i]; i++)
  18099. {
  18100. str[i] = tolower(str[i]);
  18101. }
  18102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18103. isSuccess = ConfigurationStatus_Accepted;
  18104. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18105. }
  18106. else
  18107. {
  18108. isSuccess = ConfigurationStatus_Rejected;
  18109. }
  18110. }
  18111. if(strcmp(key, "LocalPreAuthorize") == 0)
  18112. {
  18113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18114. {
  18115. strcpy(str, (const char*)value);
  18116. for(int i = 0; str[i]; i++)
  18117. {
  18118. str[i] = tolower(str[i]);
  18119. }
  18120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18121. isSuccess = ConfigurationStatus_Accepted;
  18122. }
  18123. else
  18124. {
  18125. isSuccess = ConfigurationStatus_Rejected;
  18126. }
  18127. }
  18128. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18129. {
  18130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18131. {
  18132. check_ascii = value[0];
  18133. if( (check_ascii < 48) || (check_ascii > 57) )
  18134. {
  18135. isSuccess = ConfigurationStatus_Rejected;
  18136. }
  18137. else
  18138. {
  18139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18140. isSuccess = ConfigurationStatus_Accepted;
  18141. }
  18142. }
  18143. else
  18144. {
  18145. isSuccess = ConfigurationStatus_Rejected;
  18146. }
  18147. }
  18148. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18149. {
  18150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18151. {
  18152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18153. isSuccess = ConfigurationStatus_Accepted;
  18154. }
  18155. else
  18156. {
  18157. isSuccess = ConfigurationStatus_Rejected;
  18158. }
  18159. }
  18160. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18161. {
  18162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18163. {
  18164. check_ascii = value[0];
  18165. if( (check_ascii < 48) || (check_ascii > 57) )
  18166. {
  18167. isSuccess = ConfigurationStatus_Rejected;
  18168. }
  18169. else
  18170. {
  18171. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18173. isSuccess = ConfigurationStatus_Accepted;
  18174. }
  18175. }
  18176. else
  18177. {
  18178. isSuccess = ConfigurationStatus_Rejected;
  18179. }
  18180. }
  18181. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18182. {
  18183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18184. {
  18185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18186. isSuccess = ConfigurationStatus_Accepted;
  18187. }
  18188. else
  18189. {
  18190. isSuccess = ConfigurationStatus_Rejected;
  18191. }
  18192. }
  18193. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18194. {
  18195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18196. {
  18197. check_ascii = value[0];
  18198. if( (check_ascii < 48) || (check_ascii > 57) )
  18199. {
  18200. isSuccess = ConfigurationStatus_Rejected;
  18201. }
  18202. else
  18203. {
  18204. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18206. isSuccess = ConfigurationStatus_Accepted;
  18207. }
  18208. }
  18209. else
  18210. {
  18211. isSuccess = ConfigurationStatus_Rejected;
  18212. }
  18213. }
  18214. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18215. {
  18216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18217. {
  18218. check_ascii = value[0];
  18219. if( (check_ascii < 48) || (check_ascii > 57) )
  18220. {
  18221. isSuccess = ConfigurationStatus_Rejected;
  18222. }
  18223. else
  18224. {
  18225. if((atoi(value) == 0) || (atoi(value) >= 3))
  18226. {
  18227. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18229. isSuccess = ConfigurationStatus_Accepted;
  18230. }
  18231. else
  18232. {
  18233. isSuccess = ConfigurationStatus_Rejected;
  18234. }
  18235. }
  18236. }
  18237. else
  18238. {
  18239. isSuccess = ConfigurationStatus_Rejected;
  18240. }
  18241. }
  18242. if(strcmp(key, "MinimumStatusDuration") == 0)
  18243. {
  18244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18245. {
  18246. check_ascii = value[0];
  18247. if( (check_ascii < 48) || (check_ascii > 57) )
  18248. {
  18249. isSuccess = ConfigurationStatus_Rejected;
  18250. }
  18251. else
  18252. {
  18253. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18254. {
  18255. isSuccess = ConfigurationStatus_Rejected;
  18256. }
  18257. else
  18258. {
  18259. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18261. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18262. isSuccess = ConfigurationStatus_Accepted;
  18263. }
  18264. }
  18265. }
  18266. else
  18267. {
  18268. isSuccess = ConfigurationStatus_Rejected;
  18269. }
  18270. }
  18271. if(strcmp(key, "NumberOfConnectors") == 0)
  18272. {
  18273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18274. {
  18275. check_ascii = value[0];
  18276. if( (check_ascii < 48) || (check_ascii > 57) )
  18277. {
  18278. isSuccess = ConfigurationStatus_Rejected;
  18279. }
  18280. else
  18281. {
  18282. //Charger.ResetRetries = Integer.parseInt(value);
  18283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18284. isSuccess = ConfigurationStatus_Accepted;
  18285. }
  18286. }
  18287. else
  18288. {
  18289. isSuccess = ConfigurationStatus_Rejected;
  18290. }
  18291. }
  18292. if(strcmp(key, "ResetRetries") == 0)
  18293. {
  18294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18295. {
  18296. check_ascii = value[0];
  18297. if( (check_ascii < 48) || (check_ascii > 57) )
  18298. {
  18299. isSuccess = ConfigurationStatus_Rejected;
  18300. }
  18301. else
  18302. {
  18303. //Charger.ResetRetries = Integer.parseInt(value);
  18304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18305. isSuccess = ConfigurationStatus_Accepted;
  18306. }
  18307. }
  18308. else
  18309. {
  18310. isSuccess = ConfigurationStatus_Rejected;
  18311. }
  18312. }
  18313. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18314. {
  18315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18316. {
  18317. strcpy(str, (const char*)value);
  18318. for(int i = 0; str[i]; i++)
  18319. {
  18320. str[i] = tolower(str[i]);
  18321. }
  18322. if(strcmp(str, "notapplicable")== 0)
  18323. {
  18324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18325. isSuccess = ConfigurationStatus_Accepted;
  18326. }
  18327. else if(strcmp(str, "unknown")== 0)
  18328. {
  18329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18330. isSuccess = ConfigurationStatus_Accepted;
  18331. }
  18332. else if(strcmp(str, "rst")== 0)
  18333. {
  18334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18335. isSuccess = ConfigurationStatus_Accepted;
  18336. }
  18337. else if(strcmp(str, "rts")== 0)
  18338. {
  18339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18340. isSuccess = ConfigurationStatus_Accepted;
  18341. }
  18342. else if(strcmp(str, "srt")== 0)
  18343. {
  18344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18345. isSuccess = ConfigurationStatus_Accepted;
  18346. }
  18347. else if(strcmp(str, "str")== 0)
  18348. {
  18349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18350. isSuccess = ConfigurationStatus_Accepted;
  18351. }
  18352. else if(strcmp(str, "trs")== 0)
  18353. {
  18354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18355. isSuccess = ConfigurationStatus_Accepted;
  18356. }
  18357. else if(strcmp(str, "tsr")== 0)
  18358. {
  18359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18360. isSuccess = ConfigurationStatus_Accepted;
  18361. }
  18362. else
  18363. {
  18364. isSuccess = ConfigurationStatus_Rejected;
  18365. }
  18366. }
  18367. else
  18368. {
  18369. isSuccess = ConfigurationStatus_Rejected;
  18370. }
  18371. }
  18372. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18373. {
  18374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18375. {
  18376. check_ascii = value[0];
  18377. if( (check_ascii < 48) || (check_ascii > 57) )
  18378. {
  18379. isSuccess = ConfigurationStatus_Rejected;
  18380. }
  18381. else
  18382. {
  18383. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18384. isSuccess = ConfigurationStatus_Accepted;
  18385. }
  18386. }
  18387. else
  18388. {
  18389. isSuccess = ConfigurationStatus_Rejected;
  18390. }
  18391. }
  18392. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18393. {
  18394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18395. {
  18396. strcpy(str, (const char*)value);
  18397. for(int i = 0; str[i]; i++)
  18398. {
  18399. str[i] = tolower(str[i]);
  18400. }
  18401. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18403. isSuccess = ConfigurationStatus_Accepted;
  18404. }
  18405. else
  18406. {
  18407. isSuccess = ConfigurationStatus_Rejected;
  18408. }
  18409. }
  18410. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18411. {
  18412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18413. {
  18414. strcpy(str, (const char*)value);
  18415. for(int i = 0; str[i]; i++)
  18416. {
  18417. str[i] = tolower(str[i]);
  18418. }
  18419. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18421. isSuccess = ConfigurationStatus_Accepted;
  18422. }
  18423. else
  18424. {
  18425. isSuccess = ConfigurationStatus_Rejected;
  18426. }
  18427. }
  18428. if(strcmp(key, "StopTxnAlignedData") == 0)
  18429. {
  18430. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18431. {
  18432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18433. isSuccess = ConfigurationStatus_Accepted;
  18434. }
  18435. else
  18436. {
  18437. isSuccess = ConfigurationStatus_Rejected;
  18438. }
  18439. }
  18440. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18441. {
  18442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18443. {
  18444. check_ascii = value[0];
  18445. if( (check_ascii < 48) || (check_ascii > 57) )
  18446. {
  18447. isSuccess = ConfigurationStatus_Rejected;
  18448. }
  18449. else
  18450. {
  18451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18452. isSuccess = ConfigurationStatus_Accepted;
  18453. }
  18454. }
  18455. else
  18456. {
  18457. isSuccess = ConfigurationStatus_Rejected;
  18458. }
  18459. }
  18460. if(strcmp(key, "StopTxnSampledData") == 0)
  18461. {
  18462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18463. {
  18464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18465. isSuccess = ConfigurationStatus_Accepted;
  18466. }
  18467. else
  18468. {
  18469. isSuccess = ConfigurationStatus_Rejected;
  18470. }
  18471. }
  18472. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18473. {
  18474. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18475. {
  18476. check_ascii = value[0];
  18477. if( (check_ascii < 48) || (check_ascii > 57) )
  18478. {
  18479. isSuccess = ConfigurationStatus_Rejected;
  18480. }
  18481. else
  18482. {
  18483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18484. isSuccess = ConfigurationStatus_Accepted;
  18485. }
  18486. }
  18487. else
  18488. {
  18489. isSuccess = ConfigurationStatus_Rejected;
  18490. }
  18491. }
  18492. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18493. {
  18494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18495. {
  18496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18497. isSuccess = ConfigurationStatus_Accepted;
  18498. }
  18499. else
  18500. {
  18501. isSuccess = ConfigurationStatus_Rejected;
  18502. }
  18503. }
  18504. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18505. {
  18506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18507. {
  18508. check_ascii = value[0];
  18509. if( (check_ascii < 48) || (check_ascii > 57) )
  18510. {
  18511. isSuccess = ConfigurationStatus_Rejected;
  18512. }
  18513. else
  18514. {
  18515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18516. isSuccess = ConfigurationStatus_Accepted;
  18517. }
  18518. }
  18519. else
  18520. {
  18521. isSuccess = ConfigurationStatus_Rejected;
  18522. }
  18523. }
  18524. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18525. {
  18526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18527. {
  18528. check_ascii = value[0];
  18529. if( (check_ascii < 48) || (check_ascii > 57) )
  18530. {
  18531. isSuccess = ConfigurationStatus_Rejected;
  18532. }
  18533. else
  18534. {
  18535. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18537. TransactionMessageAttemptsValue = atoi(value);
  18538. isSuccess = ConfigurationStatus_Accepted;
  18539. }
  18540. }
  18541. else
  18542. {
  18543. isSuccess = ConfigurationStatus_Rejected;
  18544. }
  18545. }
  18546. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18547. {
  18548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18549. {
  18550. check_ascii = value[0];
  18551. if( (check_ascii < 48) || (check_ascii > 57) )
  18552. {
  18553. isSuccess = ConfigurationStatus_Rejected;
  18554. }
  18555. else
  18556. {
  18557. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18559. TransactionMessageRetryIntervalValue = atoi(value);
  18560. isSuccess = ConfigurationStatus_Accepted;
  18561. }
  18562. }
  18563. else
  18564. {
  18565. isSuccess = ConfigurationStatus_Rejected;
  18566. }
  18567. }
  18568. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18569. {
  18570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18571. {
  18572. strcpy(str, (const char*)value);
  18573. for(int i = 0; str[i]; i++)
  18574. {
  18575. str[i] = tolower(str[i]);
  18576. }
  18577. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18579. isSuccess = ConfigurationStatus_Accepted;
  18580. }
  18581. else
  18582. {
  18583. isSuccess = ConfigurationStatus_Rejected;
  18584. }
  18585. }
  18586. if(strcmp(key, "WebSocketPingInterval") == 0)
  18587. {
  18588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18589. {
  18590. check_ascii = value[0];
  18591. if( (check_ascii < 48) || (check_ascii > 57) )
  18592. {
  18593. isSuccess = ConfigurationStatus_Rejected;
  18594. }
  18595. else
  18596. {
  18597. if((atoi(value) == 0) || (atoi(value) >= 10))
  18598. {
  18599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18600. isSuccess = ConfigurationStatus_Accepted;
  18601. }
  18602. else
  18603. isSuccess = ConfigurationStatus_Rejected;
  18604. }
  18605. }
  18606. else
  18607. {
  18608. isSuccess = ConfigurationStatus_Rejected;
  18609. }
  18610. }
  18611. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18612. {
  18613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18614. {
  18615. strcpy(str, (const char*)value);
  18616. for(int i = 0; str[i]; i++)
  18617. {
  18618. str[i] = tolower(str[i]);
  18619. }
  18620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18621. isSuccess = ConfigurationStatus_Accepted;
  18622. }
  18623. else
  18624. {
  18625. isSuccess = ConfigurationStatus_Rejected;
  18626. }
  18627. }
  18628. if(strcmp(key, "AuthorizationKey") == 0)
  18629. {
  18630. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18631. {
  18632. strcpy(str, (const char*)value);
  18633. int strlength = strlen(str);
  18634. char capture[3];
  18635. char stackItem = 0;
  18636. char password[21] = {0};
  18637. printf("String length: %d\n", strlength);
  18638. for(int idx=0; idx<(strlength/2); idx++)
  18639. {
  18640. capture[0] = str[(idx*2)];
  18641. capture[1] = str[(idx*2)+1];
  18642. capture[2] = 0;
  18643. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18644. sprintf(password,"%s%c", password, stackItem);
  18645. }
  18646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  18647. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18648. isSuccess = ConfigurationStatus_Accepted;
  18649. }
  18650. else
  18651. {
  18652. isSuccess = ConfigurationStatus_Rejected;
  18653. }
  18654. }
  18655. if(strcmp(key, "SecurityProfile") == 0)
  18656. {
  18657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18658. {
  18659. check_ascii = value[0];
  18660. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18661. {
  18662. isSuccess = ConfigurationStatus_Rejected;
  18663. }
  18664. else if(check_ascii == 0x33)
  18665. {
  18666. isSuccess = NotSupported;
  18667. }
  18668. else
  18669. {
  18670. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18671. {
  18672. if(((check_ascii - 0x30) == 1) ||
  18673. ((check_ascii - 0x30) == 2) ||
  18674. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18675. {
  18676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18677. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18678. isSuccess = ConfigurationStatus_Accepted;
  18679. }
  18680. else
  18681. isSuccess = ConfigurationStatus_Rejected;
  18682. }
  18683. else
  18684. isSuccess = ConfigurationStatus_Rejected;
  18685. }
  18686. }
  18687. else
  18688. {
  18689. isSuccess = ConfigurationStatus_Rejected;
  18690. }
  18691. }
  18692. if(strcmp(key, "DefaultPrice") == 0)
  18693. {
  18694. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18695. {
  18696. strcpy(str, (const char*)value);
  18697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18698. isSuccess = ConfigurationStatus_Accepted;
  18699. }
  18700. else
  18701. {
  18702. isSuccess = ConfigurationStatus_Rejected;
  18703. }
  18704. }
  18705. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18706. {
  18707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18708. {
  18709. strcpy(str, (const char*)value);
  18710. for(int i = 0; str[i]; i++)
  18711. {
  18712. str[i] = tolower(str[i]);
  18713. }
  18714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18715. isSuccess = ConfigurationStatus_Accepted;
  18716. }
  18717. else
  18718. {
  18719. isSuccess = ConfigurationStatus_Rejected;
  18720. }
  18721. }
  18722. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18723. {
  18724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18725. {
  18726. strcpy(str, (const char*)value);
  18727. for(int i = 0; str[i]; i++)
  18728. {
  18729. str[i] = tolower(str[i]);
  18730. }
  18731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18732. isSuccess = ConfigurationStatus_Accepted;
  18733. }
  18734. else
  18735. {
  18736. isSuccess = ConfigurationStatus_Rejected;
  18737. }
  18738. }
  18739. if(strcmp(key, "TimeOffset") == 0)
  18740. {
  18741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18742. {
  18743. strcpy(str, (const char*)value);
  18744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18745. isSuccess = ConfigurationStatus_Accepted;
  18746. }
  18747. else
  18748. {
  18749. isSuccess = ConfigurationStatus_Rejected;
  18750. }
  18751. }
  18752. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18753. {
  18754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18755. {
  18756. strcpy(str, (const char*)value);
  18757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18758. isSuccess = ConfigurationStatus_Accepted;
  18759. }
  18760. else
  18761. {
  18762. isSuccess = ConfigurationStatus_Rejected;
  18763. }
  18764. }
  18765. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18766. {
  18767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18768. {
  18769. strcpy(str, (const char*)value);
  18770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18771. isSuccess = ConfigurationStatus_Accepted;
  18772. }
  18773. else
  18774. {
  18775. isSuccess = ConfigurationStatus_Rejected;
  18776. }
  18777. }
  18778. if(strcmp(key, "SystemUptimeSec") == 0)
  18779. {
  18780. isSuccess = NotSupported;
  18781. }
  18782. if(strcmp(key, "FreeVend") == 0)
  18783. {
  18784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18785. {
  18786. strcpy(str, (const char*)value);
  18787. for(int i = 0; str[i]; i++)
  18788. {
  18789. str[i] = tolower(str[i]);
  18790. }
  18791. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18793. isSuccess = ConfigurationStatus_Accepted;
  18794. }
  18795. else
  18796. {
  18797. isSuccess = ConfigurationStatus_Rejected;
  18798. }
  18799. }
  18800. if(strcmp(key, "FreeVendIdtag") == 0)
  18801. {
  18802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18803. {
  18804. strcpy(str, (const char*)value);
  18805. if(strlen(str) <= 20)
  18806. {
  18807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18808. isSuccess = ConfigurationStatus_Accepted;
  18809. }
  18810. else
  18811. {
  18812. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18813. isSuccess = ConfigurationStatus_Rejected;
  18814. }
  18815. }
  18816. else
  18817. {
  18818. isSuccess = ConfigurationStatus_Rejected;
  18819. }
  18820. }
  18821. if(strcmp(key, "OcppServer") == 0)
  18822. {
  18823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18824. {
  18825. strcpy(str, (const char*)value);
  18826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18827. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18828. isSuccess = ConfigurationStatus_Accepted;
  18829. }
  18830. else
  18831. {
  18832. isSuccess = ConfigurationStatus_Rejected;
  18833. }
  18834. }
  18835. if(strcmp(key, "MaintainServer") == 0)
  18836. {
  18837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18838. {
  18839. strcpy(str, (const char*)value);
  18840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18841. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18842. isSuccess = ConfigurationStatus_Accepted;
  18843. }
  18844. else
  18845. {
  18846. isSuccess = ConfigurationStatus_Rejected;
  18847. }
  18848. }
  18849. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18850. {
  18851. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18852. {
  18853. strcpy(str, (const char*)value);
  18854. for(int i = 0; str[i]; i++)
  18855. {
  18856. str[i] = tolower(str[i]);
  18857. }
  18858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18859. isSuccess = ConfigurationStatus_Accepted;
  18860. }
  18861. else
  18862. {
  18863. isSuccess = ConfigurationStatus_Rejected;
  18864. }
  18865. }
  18866. if(strcmp(key, "StatusNotificationInterval") == 0)
  18867. {
  18868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18869. {
  18870. check_ascii = value[0];
  18871. if( (check_ascii < 48) || (check_ascii > 57) )
  18872. {
  18873. isSuccess = ConfigurationStatus_Rejected;
  18874. }
  18875. else
  18876. {
  18877. if((atoi(value) == 0) || (atoi(value) >= 10))
  18878. {
  18879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18880. isSuccess = ConfigurationStatus_Accepted;
  18881. }
  18882. else
  18883. isSuccess = ConfigurationStatus_Rejected;
  18884. }
  18885. }
  18886. else
  18887. {
  18888. isSuccess = ConfigurationStatus_Rejected;
  18889. }
  18890. }
  18891. if(strcmp(key, "PreAuthAmount") == 0)
  18892. {
  18893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18894. {
  18895. check_ascii = value[0];
  18896. if( (check_ascii < 48) || (check_ascii > 57) )
  18897. {
  18898. isSuccess = ConfigurationStatus_Rejected;
  18899. }
  18900. else
  18901. {
  18902. if(atof(value) >= 0)
  18903. {
  18904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18905. isSuccess = ConfigurationStatus_Accepted;
  18906. }
  18907. else
  18908. isSuccess = ConfigurationStatus_Rejected;
  18909. }
  18910. }
  18911. else
  18912. {
  18913. isSuccess = ConfigurationStatus_Rejected;
  18914. }
  18915. }
  18916. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  18917. {
  18918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  18919. {
  18920. check_ascii = value[0];
  18921. if( (check_ascii < 48) || (check_ascii > 57) )
  18922. {
  18923. isSuccess = ConfigurationStatus_Rejected;
  18924. }
  18925. else
  18926. {
  18927. if(atoi(value) >= 0)
  18928. {
  18929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  18930. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  18931. isSuccess = ConfigurationStatus_Accepted;
  18932. }
  18933. else
  18934. isSuccess = ConfigurationStatus_Rejected;
  18935. }
  18936. }
  18937. else
  18938. {
  18939. isSuccess = ConfigurationStatus_Rejected;
  18940. }
  18941. }
  18942. if(strcmp(key, "PowerSharingServerIP") == 0)
  18943. {
  18944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  18945. {
  18946. strcpy(str, (const char*)value);
  18947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  18948. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  18949. isSuccess = ConfigurationStatus_Accepted;
  18950. }
  18951. else
  18952. {
  18953. isSuccess = ConfigurationStatus_Rejected;
  18954. }
  18955. }
  18956. if(strcmp(key, "EVCCID_PREFIX") == 0)
  18957. {
  18958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  18959. {
  18960. strcpy(str, (const char*)value);
  18961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  18962. isSuccess = ConfigurationStatus_Accepted;
  18963. }
  18964. else
  18965. {
  18966. isSuccess = ConfigurationStatus_Rejected;
  18967. }
  18968. }
  18969. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  18970. {
  18971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  18972. {
  18973. if(atoi(value) > modelnameInfo.ratedPower)
  18974. {
  18975. isSuccess = ConfigurationStatus_Rejected;
  18976. }
  18977. else{
  18978. strcpy(str, (const char*)value);
  18979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  18980. isSuccess = ConfigurationStatus_Accepted;
  18981. }
  18982. }
  18983. else
  18984. {
  18985. isSuccess = ConfigurationStatus_Rejected;
  18986. }
  18987. }
  18988. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  18989. {
  18990. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  18991. {
  18992. if((atoi(value) != 0) && (atoi(value) < 5))
  18993. {
  18994. isSuccess = ConfigurationStatus_Rejected;
  18995. }
  18996. else{
  18997. strcpy(str, (const char*)value);
  18998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  18999. isSuccess = ConfigurationStatus_Accepted;
  19000. }
  19001. }
  19002. else
  19003. {
  19004. isSuccess = ConfigurationStatus_Rejected;
  19005. }
  19006. }
  19007. if(strcmp(key, "CpoName") == 0)
  19008. {
  19009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19010. {
  19011. strcpy(str, (const char*)value);
  19012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19013. isSuccess = ConfigurationStatus_Accepted;
  19014. }
  19015. else
  19016. {
  19017. isSuccess = ConfigurationStatus_Rejected;
  19018. }
  19019. }
  19020. #if 0
  19021. //For OCPP Test Case
  19022. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19023. {
  19024. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19025. {
  19026. strcpy(str, (const char*)value);
  19027. for(int i = 0; str[i]; i++)
  19028. {
  19029. str[i] = tolower(str[i]);
  19030. }
  19031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19032. isSuccess = ConfigurationStatus_Accepted;
  19033. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19034. }
  19035. else
  19036. {
  19037. isSuccess = ConfigurationStatus_Rejected;
  19038. }
  19039. }
  19040. #endif
  19041. #if 1
  19042. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19043. {
  19044. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19045. {
  19046. strcpy(str, (const char*)value);
  19047. for(int i = 0; str[i]; i++)
  19048. {
  19049. str[i] = tolower(str[i]);
  19050. }
  19051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19052. isSuccess = ConfigurationStatus_Accepted;
  19053. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19054. }
  19055. else
  19056. {
  19057. isSuccess = ConfigurationStatus_Rejected;
  19058. }
  19059. }
  19060. #endif
  19061. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19062. {
  19063. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19064. {
  19065. check_ascii = value[0];
  19066. if( (check_ascii < 48) || (check_ascii > 57) )
  19067. {
  19068. isSuccess = ConfigurationStatus_Rejected;
  19069. }
  19070. else
  19071. {
  19072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19073. isSuccess = ConfigurationStatus_Accepted;
  19074. }
  19075. }
  19076. else
  19077. {
  19078. isSuccess = ConfigurationStatus_Rejected;
  19079. }
  19080. }
  19081. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19082. {
  19083. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19084. {
  19085. check_ascii = value[0];
  19086. if( (check_ascii < 48) || (check_ascii > 57) )
  19087. {
  19088. isSuccess = ConfigurationStatus_Rejected;
  19089. }
  19090. else
  19091. {
  19092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19093. isSuccess = ConfigurationStatus_Accepted;
  19094. }
  19095. }
  19096. else
  19097. {
  19098. isSuccess = ConfigurationStatus_Rejected;
  19099. }
  19100. }
  19101. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19102. {
  19103. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19104. {
  19105. strcpy(str, (const char*)value);
  19106. for(int i = 0; str[i]; i++)
  19107. {
  19108. str[i] = tolower(str[i]);
  19109. }
  19110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19111. isSuccess = ConfigurationStatus_Accepted;
  19112. }
  19113. else
  19114. {
  19115. isSuccess = ConfigurationStatus_Rejected;
  19116. }
  19117. }
  19118. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19119. {
  19120. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19121. {
  19122. check_ascii = value[0];
  19123. if( (check_ascii < 48) || (check_ascii > 57) )
  19124. {
  19125. isSuccess = ConfigurationStatus_Rejected;
  19126. }
  19127. else
  19128. {
  19129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19130. isSuccess = ConfigurationStatus_Accepted;
  19131. }
  19132. }
  19133. else
  19134. {
  19135. isSuccess = ConfigurationStatus_Rejected;
  19136. }
  19137. }
  19138. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19139. {
  19140. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19141. {
  19142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19143. isSuccess = ConfigurationStatus_Accepted;
  19144. }
  19145. else
  19146. {
  19147. isSuccess = ConfigurationStatus_Rejected;
  19148. }
  19149. }
  19150. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19151. {
  19152. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19153. {
  19154. check_ascii = value[0];
  19155. if( (check_ascii < 48) || (check_ascii > 57) )
  19156. {
  19157. isSuccess = ConfigurationStatus_Rejected;
  19158. }
  19159. else
  19160. {
  19161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19162. isSuccess = ConfigurationStatus_Accepted;
  19163. }
  19164. }
  19165. else
  19166. {
  19167. isSuccess = ConfigurationStatus_Rejected;
  19168. }
  19169. }
  19170. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19171. {
  19172. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19173. {
  19174. strcpy(str, (const char*)value);
  19175. for(int i = 0; str[i]; i++)
  19176. {
  19177. str[i] = tolower(str[i]);
  19178. }
  19179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19180. isSuccess = ConfigurationStatus_Accepted;
  19181. }
  19182. else
  19183. {
  19184. isSuccess = ConfigurationStatus_Rejected;
  19185. }
  19186. }
  19187. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19188. {
  19189. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19190. {
  19191. check_ascii = value[0];
  19192. if( (check_ascii < 48) || (check_ascii > 57) )
  19193. {
  19194. isSuccess = ConfigurationStatus_Rejected;
  19195. }
  19196. else
  19197. {
  19198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19199. isSuccess = ConfigurationStatus_Accepted;
  19200. }
  19201. }
  19202. else
  19203. {
  19204. isSuccess = ConfigurationStatus_Rejected;
  19205. }
  19206. }
  19207. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19208. return isSuccess;
  19209. }
  19210. int TransactionMessageAttemptsGet(void)
  19211. {
  19212. return TransactionMessageAttemptsValue;
  19213. }
  19214. int FirstHeartBeatResponse(void)
  19215. {
  19216. return FirstHeartBeat;
  19217. }
  19218. int TransactionMessageRetryIntervalGet(void)
  19219. {
  19220. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19221. }
  19222. int ReadHttpStatus(int sock)
  19223. {
  19224. //char c;
  19225. char buff[1024]="",*ptr=buff+1;
  19226. int bytes_received, status;
  19227. DEBUG_INFO("Begin Response ..\n");
  19228. while((bytes_received = recv(sock, ptr, 1, 0))){
  19229. if(bytes_received==-1){
  19230. perror("ReadHttpStatus");
  19231. exit(1);
  19232. }
  19233. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19234. ptr++;
  19235. }
  19236. *ptr=0;
  19237. ptr=buff+1;
  19238. sscanf(ptr,"%*s %d ", &status);
  19239. DEBUG_INFO("%s\n",ptr);
  19240. DEBUG_INFO("status=%d\n",status);
  19241. DEBUG_INFO("End Response ..\n");
  19242. return (bytes_received>0)?status:0;
  19243. }
  19244. //the only filed that it parsed is 'Content-Length'
  19245. int ParseHeader(int sock)
  19246. {
  19247. //char c;
  19248. char buff[1024]="",*ptr=buff+4;
  19249. int bytes_received;
  19250. DEBUG_INFO("Begin HEADER ..\n");
  19251. while((bytes_received = recv(sock, ptr, 1, 0))){
  19252. if(bytes_received==-1){
  19253. perror("Parse Header");
  19254. exit(1);
  19255. }
  19256. if(
  19257. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19258. (ptr[-1]=='\r') && (*ptr=='\n' )
  19259. ) break;
  19260. ptr++;
  19261. }
  19262. *ptr=0;
  19263. ptr=buff+4;
  19264. //printf("%s",ptr);
  19265. if(bytes_received){
  19266. ptr=strstr(ptr,"Content-Length:");
  19267. if(ptr){
  19268. sscanf(ptr,"%*s %d",&bytes_received);
  19269. }else
  19270. bytes_received=-1; //unknown size
  19271. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19272. }
  19273. DEBUG_INFO("End HEADER ..\n");
  19274. return bytes_received ;
  19275. }
  19276. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19277. {
  19278. int result = TRUE;
  19279. char rmFileCmd[100]={0};
  19280. char FilePath[100]={0};
  19281. char ftpbuf[200];
  19282. int systemresult;
  19283. sprintf(FilePath,"/mnt/%s",filename);
  19284. system("ping 8.8.8.8 &");
  19285. if((access(FilePath,F_OK))!=-1)
  19286. {
  19287. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19288. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19289. system(rmFileCmd);
  19290. }
  19291. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19292. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19293. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19294. systemresult = system(ftpbuf);
  19295. if(systemresult != 0)
  19296. {
  19297. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19298. result = FALSE;
  19299. }
  19300. system("pkill ping");
  19301. return result;
  19302. }
  19303. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19304. {
  19305. int result = TRUE;
  19306. char rmFileCmd[100]={0};
  19307. char FilePath[100]={0};
  19308. char ftpbuf[200];
  19309. int systemresult;
  19310. sprintf(FilePath,"/mnt/%s",filename);
  19311. system("ping 8.8.8.8 &");
  19312. if((access(FilePath,F_OK))!=-1)
  19313. {
  19314. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19315. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19316. system(rmFileCmd);
  19317. }
  19318. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19319. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19320. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19321. systemresult = system(ftpbuf);
  19322. if(systemresult != 0)
  19323. {
  19324. DEBUG_WARN("scp error!\n");
  19325. result = FALSE;
  19326. }
  19327. system("pkill ping");
  19328. return result;
  19329. }
  19330. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19331. {
  19332. int result = TRUE;
  19333. char rmFileCmd[100]={0};
  19334. char FilePath[100]={0};
  19335. char ftpbuf[200];
  19336. int systemresult;
  19337. sprintf(FilePath,"/mnt/%s",filename);
  19338. system("ping 8.8.8.8 &");
  19339. if((access(FilePath,F_OK))!=-1)
  19340. {
  19341. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19342. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19343. system(rmFileCmd);
  19344. }
  19345. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19346. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  19347. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19348. systemresult = system(ftpbuf);
  19349. if(systemresult != 0)
  19350. {
  19351. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  19352. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19353. systemresult = system(ftpbuf);
  19354. if(systemresult != 0)
  19355. {
  19356. DEBUG_WARN("FTP download fail!\n");
  19357. result = FALSE;
  19358. }
  19359. }
  19360. system("pkill ping");
  19361. return result;
  19362. }
  19363. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19364. {
  19365. char rmFileCmd[100]={0};
  19366. char FilePath[100]={0};
  19367. char buf[512];
  19368. int systemresult = 0;
  19369. //DEBUG_INFO("filename=%s\n",filename);
  19370. //DEBUG_INFO("url=%s\n",url);
  19371. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19372. if((access(FilePath,F_OK))!=-1)
  19373. {
  19374. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19375. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19376. system(rmFileCmd);
  19377. }
  19378. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19379. if(fp == NULL)
  19380. {
  19381. DEBUG_INFO("log is NULL\n");
  19382. return FALSE;
  19383. }
  19384. else
  19385. {
  19386. fprintf(fp, "%s\n", url);
  19387. fprintf(fp, "%s\n", filename);
  19388. fclose(fp);
  19389. }
  19390. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19391. if(phpFP == NULL)
  19392. {
  19393. DEBUG_INFO("PHP upload fail.\n");
  19394. return FALSE;
  19395. }
  19396. else
  19397. {
  19398. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19399. {
  19400. if(strstr(buf, "result") != NULL)
  19401. {
  19402. sscanf(buf, "result: %d", &systemresult);
  19403. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19404. }
  19405. }
  19406. pclose(phpFP);
  19407. }
  19408. if(systemresult != 1)
  19409. {
  19410. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19411. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19412. if(phpFP == NULL)
  19413. {
  19414. DEBUG_WARN("PHP PUT upload fail.\n");
  19415. return FALSE;
  19416. }
  19417. else
  19418. {
  19419. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19420. {
  19421. if(strstr(buf, "result") != NULL)
  19422. {
  19423. sscanf(buf, "result: %d", &systemresult);
  19424. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19425. }
  19426. }
  19427. pclose(phpFP);
  19428. }
  19429. }
  19430. if(systemresult != 1)
  19431. {
  19432. DEBUG_WARN("PHP PUT upload fail.\n");
  19433. return FALSE;
  19434. }
  19435. return TRUE;
  19436. }
  19437. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19438. {
  19439. int result = FALSE;
  19440. char ftpbuf[200];
  19441. int systemresult;
  19442. /*
  19443. // Domaind name transfer to IP address
  19444. struct hostent* server;
  19445. char *IPbuffer;
  19446. server = gethostbyname(location);
  19447. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19448. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19449. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19450. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19451. systemresult = system(ftpbuf);
  19452. if(systemresult != 0)
  19453. {
  19454. DEBUG_INFO("ftpput error!\n");
  19455. }
  19456. else
  19457. {
  19458. result = TRUE;
  19459. DEBUG_INFO("ftpput OK!\n");
  19460. }
  19461. return result;
  19462. }
  19463. int GetOcppServerURL()
  19464. {
  19465. int result = FALSE;
  19466. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19467. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19468. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19469. struct yuarel url;
  19470. char urlStr[512];
  19471. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19472. {
  19473. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19474. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19475. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19476. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19477. if(yuarel_parse(&url, urlStr) != -1)
  19478. {
  19479. sprintf(OcppProtocol, "%s", url.scheme);
  19480. sprintf(OcppHost, "%s", url.host);
  19481. if(url.path == NULL)
  19482. OcppTempPath[0] = '\0';
  19483. else
  19484. {
  19485. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19486. {
  19487. sprintf(OcppTempPath, "%s/", url.path);
  19488. }
  19489. else
  19490. {
  19491. sprintf(OcppTempPath, "%s", url.path);
  19492. }
  19493. }
  19494. if(url.port == 0)
  19495. {
  19496. if(strcmp(OcppProtocol, "wss") == 0)
  19497. OcppPort = 443;
  19498. else
  19499. OcppPort = 80;
  19500. }
  19501. else
  19502. OcppPort = url.port;
  19503. result = TRUE;
  19504. }
  19505. }
  19506. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19507. {
  19508. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19509. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19510. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19511. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19512. if(yuarel_parse(&url, urlStr) != -1)
  19513. {
  19514. sprintf(OcppProtocol, "%s", url.scheme);
  19515. sprintf(OcppHost, "%s", url.host);
  19516. if(url.path == NULL)
  19517. OcppTempPath[0] = '\0';
  19518. else
  19519. sprintf(OcppTempPath, "%s", url.path);
  19520. if(url.port == 0)
  19521. {
  19522. if(strcmp(OcppProtocol, "wss") == 0)
  19523. OcppPort = 443;
  19524. else
  19525. OcppPort = 80;
  19526. }
  19527. else
  19528. OcppPort = url.port;
  19529. result = TRUE;
  19530. }
  19531. }
  19532. else
  19533. {
  19534. strcpy(OcppHost,"");
  19535. }
  19536. return result;
  19537. }
  19538. int GetOcppPath()
  19539. {
  19540. int result = FALSE;
  19541. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19542. {
  19543. if(OcppTempPath == NULL)
  19544. {
  19545. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19546. }
  19547. else
  19548. {
  19549. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19550. }
  19551. result = TRUE;
  19552. goto End;
  19553. }
  19554. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19555. {
  19556. if(OcppTempPath == NULL)
  19557. {
  19558. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19559. }
  19560. else
  19561. {
  19562. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19563. }
  19564. result = TRUE;
  19565. goto End;
  19566. }
  19567. else
  19568. {
  19569. strcpy(OcppPath,"");
  19570. }
  19571. End:
  19572. return result;
  19573. }
  19574. int GetOcppPort()
  19575. {
  19576. return OcppPort;
  19577. }
  19578. int GetOcppConnStatus(void)
  19579. {
  19580. return ShmOCPP16Data->OcppConnStatus;
  19581. }
  19582. void SetOcppConnStatus(uint8_t status)
  19583. {
  19584. ShmOCPP16Data->OcppConnStatus = status;
  19585. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19586. }
  19587. int GetHeartBeatWithNOResponse(void)
  19588. {
  19589. return HeartBeatWithNOResponse;
  19590. }
  19591. void SetHeartBeatWithNOResponse(void)
  19592. {
  19593. HeartBeatWithNOResponse = 0;
  19594. }
  19595. void GetStartTransactionIdTag(int gun_index)
  19596. {
  19597. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19598. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19599. }
  19600. int GetStartTransactionId(int gun_index)
  19601. {
  19602. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19603. }
  19604. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19605. {
  19606. char ch;
  19607. FILE *fptr1;
  19608. int temptransactionId;
  19609. char str[100]={0};
  19610. temptransactionId = 0;
  19611. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19612. {
  19613. DEBUG_INFO("IdTag is empty.\n");
  19614. return temptransactionId;
  19615. }
  19616. /*------ Read the file ----------------*/
  19617. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19618. if (!fptr1)
  19619. {
  19620. DEBUG_INFO("QueueTransactionId file open error.\n");
  19621. //printf(" File not found or unable to open the input file!!\n");
  19622. return temptransactionId;
  19623. }
  19624. ch=fgetc(fptr1);
  19625. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19626. rewind(fptr1);
  19627. if(ch!=EOF)
  19628. {
  19629. // printf("%c",ch);
  19630. while (fgets(str, 100, fptr1) != NULL)
  19631. {
  19632. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19633. if(str[0]=='\0')
  19634. {
  19635. break;
  19636. }
  19637. char *revbuf[8] = {0}; // Variable store string split
  19638. int num = 0;// Quantity after string split
  19639. DEBUG_INFO("Transaction queue data= %s\n", str);
  19640. splitstring(str,",",revbuf,&num); // String split
  19641. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19642. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19643. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19644. DEBUG_INFO("------------------------------\n");
  19645. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19646. {
  19647. if(isStopTransaction)
  19648. {
  19649. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19650. {
  19651. temptransactionId = atoi(revbuf[2]);
  19652. //break;
  19653. }
  19654. }
  19655. else
  19656. {
  19657. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19658. {
  19659. temptransactionId = atoi(revbuf[2]);
  19660. //break;
  19661. }
  19662. }
  19663. }
  19664. }
  19665. }
  19666. else
  19667. DEBUG_INFO("EOF\n");
  19668. fclose(fptr1);
  19669. /*------- End of reading ---------------*/
  19670. return temptransactionId;
  19671. }
  19672. void SetTransactionIdZero(int transactionId)
  19673. {
  19674. char ch;
  19675. FILE *fptr1, *fptr2;
  19676. int temptransactionId = 0;
  19677. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19678. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19679. if (!fptr1)
  19680. {
  19681. //printf(" File not found or unable to open the input file!!\n");
  19682. return ;
  19683. }
  19684. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19685. if (!fptr2)
  19686. {
  19687. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19688. fclose(fptr1);
  19689. return ;
  19690. }
  19691. ch=fgetc(fptr1);
  19692. rewind(fptr1);
  19693. if(ch!=EOF)
  19694. {
  19695. // copy all contents to the temporary file except the specific line
  19696. while (fgets(str, 100, fptr1) != NULL)
  19697. {
  19698. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19699. if(str[0]=='\0')
  19700. {
  19701. break;
  19702. }
  19703. char *revbuf[8] = {0};
  19704. int num = 0;
  19705. strcpy(strtemp, str);
  19706. splitstring(str,",",revbuf,&num);
  19707. if(revbuf[2][0] != '\0')
  19708. {
  19709. temptransactionId = atoi(revbuf[2]);
  19710. if(transactionId != temptransactionId)
  19711. {
  19712. fprintf(fptr2, "%s\n", strtemp);
  19713. }
  19714. }
  19715. }
  19716. }
  19717. fclose(fptr1);
  19718. fclose(fptr2);
  19719. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19720. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19721. /*------ Read the file ----------------*/
  19722. }
  19723. int InternetDisconnect(void)
  19724. {
  19725. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19726. }
  19727. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19728. void storeTempStopTransaction(int gun_index)
  19729. {
  19730. char guid[37]={0};
  19731. int tempIndex = 0;
  19732. char TempStopTransaction[256];
  19733. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19734. DEBUG_INFO("storeTempStopTransaction...\n");
  19735. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19736. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19737. //=========================== Stop Transaction Time ===============================================
  19738. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  19739. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19740. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19741. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19742. {
  19743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19744. {
  19745. tempIndex = ((gun_index==2) ? 1: 0);
  19746. }
  19747. else
  19748. {
  19749. tempIndex = gun_index;
  19750. }
  19751. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19752. {
  19753. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19754. {
  19755. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19756. }
  19757. }// END OF CHAdeMO_QUANTITY
  19758. }
  19759. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19760. {
  19761. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19762. {
  19763. tempIndex = ((gun_index==2) ? 1: 0);
  19764. }
  19765. else
  19766. {
  19767. tempIndex = gun_index;
  19768. }
  19769. for (int index = 0; index < CCS_QUANTITY; index++)
  19770. {
  19771. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19772. {
  19773. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19774. }
  19775. }// END OF CCS_QUANTITY
  19776. }
  19777. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19778. {
  19779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19780. {
  19781. tempIndex = ((gun_index==2) ? 1: 0);
  19782. }
  19783. else
  19784. {
  19785. tempIndex = gun_index;
  19786. }
  19787. for (int index = 0; index < GB_QUANTITY; index++)
  19788. {
  19789. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19790. {
  19791. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19792. }
  19793. }// END OF GB_QUANTITY
  19794. }
  19795. else if(gunType[gun_index] == GUN_TYPE_DO)
  19796. {
  19797. tempIndex = gun_index;
  19798. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19799. {
  19800. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19801. {
  19802. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19803. }
  19804. }
  19805. }
  19806. else
  19807. {
  19808. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19809. {
  19810. tempIndex = 2;
  19811. }
  19812. else
  19813. {
  19814. tempIndex = gun_index;
  19815. }
  19816. for (int index = 0; index < AC_QUANTITY; index++)
  19817. {
  19818. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19819. {
  19820. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19821. }
  19822. }// END OF AC_QUANTITY
  19823. }
  19824. //======================================== Message create ==============================================
  19825. json_object *StopTransaction = json_object_new_object();
  19826. json_object *transactionDatas = json_object_new_array();
  19827. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19828. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19829. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19830. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19831. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19832. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19833. meterValueBufferQuery(gun_index, transactionDatas);
  19834. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19835. random_uuid(guid);
  19836. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19837. ,MESSAGE_TYPE_CALL
  19838. ,guid
  19839. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19840. json_object_put(StopTransaction);
  19841. // Check File "TempStopTransaction" Exist
  19842. if((access(TempStopTransaction,F_OK))!=-1)
  19843. {
  19844. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19845. fclose(fopen(TempStopTransaction, "w"));
  19846. }
  19847. else
  19848. {
  19849. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19850. FILE *log = fopen(TempStopTransaction, "w+");
  19851. if(log == NULL)
  19852. {
  19853. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19854. return ;
  19855. }
  19856. else
  19857. {
  19858. fclose(log);
  19859. }
  19860. }
  19861. //Add TempStopTransaction | Update TempStopTransaction
  19862. // open file for writing
  19863. FILE *outfile;
  19864. outfile = fopen (TempStopTransaction, "a");
  19865. //DEBUG_INFO("data = %s\n", queuedata);
  19866. fputs(queuedata, outfile);
  19867. fputs("\n", outfile);
  19868. fclose (outfile);
  19869. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19870. OCPP_updatePeriodEnergy(gun_index);
  19871. }
  19872. void checkTempStopTransaction(int gun_index)
  19873. {
  19874. FILE *fptr1;
  19875. char ch;
  19876. char str[QUEUE_MESSAGE_LENGTH]={0};
  19877. char guid[37]={0};
  19878. char tempdata[65]={0};
  19879. char connectorStr[2]={0};
  19880. char TempStopTransaction[256];
  19881. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19882. fptr1 = fopen(TempStopTransaction, "r");
  19883. //TempStopTransaction格式: 槍號,StopTransaction封包
  19884. if (!fptr1)
  19885. {
  19886. //printf(" File not found or unable to open the input file!!\n");
  19887. return ;
  19888. }
  19889. ch=fgetc(fptr1);
  19890. //printf(" Now the content of the file %s is : \n",fname);
  19891. rewind(fptr1);
  19892. if(ch!=EOF)
  19893. {
  19894. // copy all contents to the temporary file except the specific line
  19895. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19896. {
  19897. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19898. if(str[0]=='\0')
  19899. {
  19900. break;
  19901. }
  19902. //TempStopTransaction格式: 槍號,StopTransaction封包
  19903. strncpy(connectorStr, str, 1);
  19904. if(atoi(connectorStr) != (gun_index+1))
  19905. {
  19906. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19907. fclose(fptr1);
  19908. return ;
  19909. }
  19910. //random_uuid(guid);
  19911. strncpy(guid, str+6, 36); //copy guid
  19912. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19913. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19914. {
  19915. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19916. }
  19917. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19918. OCPP_insert_transaction_msg(NO, str);
  19919. memset(str,0,ARRAY_SIZE(str));
  19920. }
  19921. }
  19922. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19923. fclose(fptr1);
  19924. remove(TempStopTransaction); // remove the original file
  19925. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19926. }
  19927. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19928. {
  19929. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19930. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19931. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19932. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19933. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19934. }
  19935. void FillTransactionId(int ConnectorId, int TransactionId)
  19936. {
  19937. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19938. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  19939. }
  19940. int GetWebSocketPingInterval(void)
  19941. {
  19942. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19943. }
  19944. int GetServerSign(void)
  19945. {
  19946. return server_sign;
  19947. }
  19948. uint8_t GetOcppSecurityProfile()
  19949. {
  19950. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19951. }
  19952. void MergeCertificates()
  19953. {
  19954. char cmdBuf[2048]={0};
  19955. if(access(ROOTCA_CS,F_OK) != -1)
  19956. {
  19957. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  19958. }
  19959. else
  19960. {
  19961. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  19962. }
  19963. system(cmdBuf);
  19964. }
  19965. void GetOcppChargerBoxId(uint8_t *data)
  19966. {
  19967. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19968. }
  19969. void GetOcppSecurityPassword(uint8_t *data)
  19970. {
  19971. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19972. }
  19973. void SetOcppVersion(uint8_t *version)
  19974. {
  19975. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19976. DEBUG_INFO("ocpp version: %s\n", version);
  19977. if(strstr((char*)version, "ocpp1.6") != NULL)
  19978. {
  19979. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19980. }
  19981. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19982. {
  19983. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19984. system("pkill OcppBackend");
  19985. }
  19986. }
  19987. void SetServerSign(int value)
  19988. {
  19989. server_sign = value;
  19990. }
  19991. int GetBootNotificationInterval(void)
  19992. {
  19993. return BootNotificationInterval;
  19994. }
  19995. int GetInternetConn(void)
  19996. {
  19997. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19998. }
  19999. int GetBackendConnectionTimeout(void)
  20000. {
  20001. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20002. }
  20003. int isConnectorInitMode(int gun_index)
  20004. {
  20005. int tempIndex = 0;
  20006. int result = TRUE;
  20007. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20008. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20009. {
  20010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20011. {
  20012. tempIndex = ((gun_index==2) ? 1: 0);
  20013. }
  20014. else
  20015. {
  20016. tempIndex = gun_index;
  20017. }
  20018. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20019. {
  20020. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20021. {
  20022. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20023. } //end of the same index
  20024. }//end of for CHAdeMO_QUANTITY
  20025. }
  20026. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20027. {
  20028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20029. {
  20030. tempIndex = ((gun_index==2) ? 1: 0);
  20031. }
  20032. else
  20033. {
  20034. tempIndex = gun_index;
  20035. }
  20036. for (int index = 0; index < CCS_QUANTITY; index++)
  20037. {
  20038. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20039. {
  20040. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20041. } //end of the same index
  20042. } // end of for CCS_QUANTITY
  20043. }
  20044. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20045. {
  20046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20047. {
  20048. tempIndex = ((gun_index==2) ? 1: 0);
  20049. }
  20050. else
  20051. {
  20052. tempIndex = gun_index;
  20053. }
  20054. for (int index = 0; index < GB_QUANTITY; index++)
  20055. {
  20056. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20057. {
  20058. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20059. } //end of the same index
  20060. } // end of for GB_QUANTITY
  20061. }
  20062. else if(gunType[gun_index] == GUN_TYPE_DO)
  20063. {
  20064. tempIndex = gun_index;
  20065. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20066. {
  20067. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20068. {
  20069. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20070. } //end of the same index
  20071. }
  20072. }
  20073. else
  20074. {
  20075. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20076. {
  20077. tempIndex = 2;
  20078. }
  20079. else
  20080. {
  20081. tempIndex = gun_index;
  20082. }
  20083. for (int index = 0; index < AC_QUANTITY; index++)
  20084. {
  20085. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20086. {
  20087. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20088. }//end of the same index
  20089. }//end of for AC_QUANTITY
  20090. }
  20091. return result;
  20092. }
  20093. void refreshProcDogTimer()
  20094. {
  20095. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20096. }
  20097. void InitialSystemValue(void)
  20098. {
  20099. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20100. locallistVersion=0;
  20101. BootNotificationInterval = 0;
  20102. authorizeRetryTimes = 0;
  20103. GunStatusInterval = 10;
  20104. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20105. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20106. //Hear Beat
  20107. HeartBeatWithNOResponse = 0;
  20108. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20109. FirstHeartBeat = 0;
  20110. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20111. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20112. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20113. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20114. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20115. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20116. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20117. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20118. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20119. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20120. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20121. //Status && ConnectorPlugIn Setting
  20122. Connector0PreviousSystemStatus = 99;
  20123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20124. {
  20125. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20126. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20127. }
  20128. for (int index = 0; index < CCS_QUANTITY; index++)
  20129. {
  20130. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20131. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20132. }
  20133. for (int index = 0; index < GB_QUANTITY; index++)
  20134. {
  20135. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20136. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20137. }
  20138. for (int index = 0; index < AC_QUANTITY; index++)
  20139. {
  20140. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20141. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20142. }
  20143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20144. {
  20145. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20146. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20147. }
  20148. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20149. {
  20150. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20151. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20152. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20153. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20154. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20155. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20156. }
  20157. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20158. refreshStartTimer(&clientTime.Heartbeat);
  20159. sleep(1);
  20160. }
  20161. void LWS_Send(char *str)
  20162. {
  20163. //=====================================================
  20164. // Check InternetConn 0: disconnected, 1: connected
  20165. //====================================================
  20166. if(GetOcppConnStatus() == 0)
  20167. {
  20168. DEBUG_INFO("offline now !!!\n");
  20169. return;
  20170. }
  20171. // Only disable isWebsocketSendable operation initiated by charger
  20172. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20173. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20174. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20175. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20176. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20177. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20178. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20179. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20180. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20181. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20182. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20183. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20184. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20185. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20186. {
  20187. isWebsocketSendable = 0;
  20188. }
  20189. pthread_mutex_lock(&lock_send);
  20190. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20191. sprintf((char *)SendBuffer, "%s", str);
  20192. SendBufLen = strlen(str);
  20193. pthread_mutex_unlock(&lock_send);
  20194. lws_callback_on_writable(wsi_client);
  20195. //lws_service(context, 0);
  20196. //sleep(1);
  20197. }
  20198. void LWS_SendNow(char *str)
  20199. {
  20200. //=====================================================
  20201. // Check InternetConn 0: disconnected, 1: connected
  20202. //====================================================
  20203. if(GetOcppConnStatus() == 0)
  20204. {
  20205. DEBUG_INFO("offline now !!!\n");
  20206. return;
  20207. }
  20208. // Only disable isWebsocketSendable operation initiated by charger
  20209. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20210. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20211. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20212. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20213. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20214. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20215. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20216. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20217. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20218. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20219. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20220. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20221. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20222. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20223. {
  20224. isWebsocketSendable = 0;
  20225. }
  20226. pthread_mutex_lock(&lock_send);
  20227. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20228. sprintf((char *)SendBuffer, "%s", str);
  20229. SendBufLen = strlen(str);
  20230. pthread_mutex_unlock(&lock_send);
  20231. lws_callback_on_writable(wsi_client);
  20232. lws_service(context, 0);
  20233. //sleep(1);
  20234. }