MessageHandler.c 993 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132
  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. //check Transaction active
  11462. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11463. {
  11464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11465. {
  11466. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11467. }
  11468. else
  11469. {
  11470. tempIndex = connectorIdInt -1;
  11471. }
  11472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11473. {
  11474. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11475. {
  11476. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11477. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11478. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11479. {
  11480. //Reserved
  11481. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11482. }
  11483. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11484. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11485. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11486. {
  11487. //Reserved
  11488. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11489. {
  11490. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11491. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11492. goto end;
  11493. }
  11494. }
  11495. else
  11496. {
  11497. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11498. {
  11499. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11500. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11501. goto end;
  11502. }
  11503. }//END FOR ELSE
  11504. }
  11505. }// END FOR CHAdeMO_QUANTITY
  11506. }
  11507. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11508. {
  11509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11510. {
  11511. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11512. }
  11513. else
  11514. {
  11515. tempIndex = connectorIdInt -1;
  11516. }
  11517. for (int index = 0; index < CCS_QUANTITY; index++)
  11518. {
  11519. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11520. {
  11521. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11522. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11523. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11524. {
  11525. //Reserved
  11526. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11527. }
  11528. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11529. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11530. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11531. {
  11532. //Reserved
  11533. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11534. {
  11535. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11536. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11537. goto end;
  11538. }
  11539. }
  11540. else
  11541. {
  11542. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11543. {
  11544. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11545. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11546. goto end;
  11547. }
  11548. }// END FOR ELSE
  11549. }
  11550. }// END FOR CCS_QUANTITY
  11551. }
  11552. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11553. {
  11554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11555. {
  11556. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11557. }
  11558. else
  11559. {
  11560. tempIndex = connectorIdInt -1;
  11561. }
  11562. for (int index = 0; index < GB_QUANTITY; index++)
  11563. {
  11564. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11565. {
  11566. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11567. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11568. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11569. {
  11570. //Reserved
  11571. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11572. }
  11573. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11574. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11575. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11576. {
  11577. //Reserved
  11578. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11579. {
  11580. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11581. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11582. goto end;
  11583. }
  11584. }
  11585. else
  11586. {
  11587. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11588. {
  11589. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11590. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11591. goto end;
  11592. }
  11593. }// END FOR ELSE
  11594. }
  11595. } // END FOR GB_QUANTITY
  11596. }
  11597. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11598. {
  11599. tempIndex = connectorIdInt -1;
  11600. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11601. {
  11602. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11603. {
  11604. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11605. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11606. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11607. {
  11608. //Reserved
  11609. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11610. }
  11611. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11612. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11613. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11614. {
  11615. //Reserved
  11616. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11617. {
  11618. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11619. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11620. goto end;
  11621. }
  11622. }
  11623. else
  11624. {
  11625. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11626. {
  11627. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11628. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11629. goto end;
  11630. }
  11631. }// END FOR ELSE
  11632. }
  11633. } // END FOR GB_QUANTITY
  11634. }
  11635. else
  11636. {
  11637. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11638. {
  11639. tempIndex = 2;
  11640. }
  11641. else
  11642. {
  11643. tempIndex = connectorIdInt -1;
  11644. }
  11645. for (int index = 0; index < AC_QUANTITY; index++)
  11646. {
  11647. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11648. {
  11649. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11650. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11651. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11652. {
  11653. //Reserved
  11654. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11655. }
  11656. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11657. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11658. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11659. {
  11660. //Reserved
  11661. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11662. {
  11663. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11664. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11665. goto end;
  11666. }
  11667. }
  11668. else
  11669. {
  11670. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11671. {
  11672. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11673. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11674. goto end;
  11675. }
  11676. }//END FOR ELSE
  11677. }
  11678. }// END FOR AC_QUANTITY
  11679. }
  11680. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11681. {
  11682. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11683. {
  11684. // Save profile to file
  11685. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11686. system(cmdBuf);
  11687. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11688. fp = fopen(cmdBuf, "w");
  11689. 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));
  11690. fclose(fp);
  11691. }
  11692. else
  11693. {
  11694. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11695. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11696. goto end;
  11697. }
  11698. }
  11699. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11700. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11701. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11702. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11703. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11704. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11705. }
  11706. else
  11707. {
  11708. uint8_t isHasIdleConnector = FALSE;
  11709. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11710. {
  11711. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11712. {
  11713. isHasIdleConnector = TRUE;
  11714. break;
  11715. }
  11716. }
  11717. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11718. {
  11719. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11720. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11721. {
  11722. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11723. {
  11724. // Save profile to file
  11725. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11726. system(cmdBuf);
  11727. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11728. fp = fopen(cmdBuf, "w");
  11729. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11730. fclose(fp);
  11731. refreshStartTimer(&clientTime.RemoteStartWait);
  11732. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11733. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11734. }
  11735. else
  11736. {
  11737. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11738. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11739. }
  11740. }
  11741. else
  11742. {
  11743. refreshStartTimer(&clientTime.RemoteStartWait);
  11744. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11745. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11746. }
  11747. }
  11748. else
  11749. {
  11750. DEBUG_INFO("There is not any connector is idle.\n");
  11751. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11752. }
  11753. }
  11754. }
  11755. else
  11756. {
  11757. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11758. }
  11759. end:
  11760. json_object_put(RemoteStartTransaction);
  11761. sendRemoteStartConfirmation(uuid, comfirmstr);
  11762. return result;
  11763. }
  11764. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11765. {
  11766. mtrace();
  11767. int result = FAIL;
  11768. int match = FALSE;
  11769. int GunNO = 0;
  11770. int tempIndex = 0;
  11771. int transactionIdInt=0;
  11772. int transactionIdIsNULL= TRUE;
  11773. char comfirmstr[20];
  11774. json_object *RemoteStopTransaction;
  11775. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11776. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11777. if(server_pending == TRUE)
  11778. {
  11779. return 0;
  11780. }
  11781. RemoteStopTransaction = json_tokener_parse(payload);
  11782. if(!is_error(RemoteStopTransaction))
  11783. {
  11784. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11785. {
  11786. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11787. transactionIdIsNULL = FALSE;
  11788. }
  11789. }
  11790. json_object_put(RemoteStopTransaction);
  11791. if(transactionIdIsNULL == FALSE)
  11792. {
  11793. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11794. {
  11795. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11796. {
  11797. //check Transaction active
  11798. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11799. {
  11800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11801. {
  11802. tempIndex = ((gun_index==2) ? 1: 0);
  11803. }
  11804. else
  11805. {
  11806. tempIndex = gun_index;
  11807. }
  11808. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11809. {
  11810. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11811. {
  11812. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11813. {
  11814. match = TRUE;
  11815. GunNO = gun_index;
  11816. }
  11817. }
  11818. }// END FOR CHAdeMO_QUANTITY
  11819. }
  11820. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11821. {
  11822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11823. {
  11824. tempIndex = ((gun_index==2) ? 1: 0);
  11825. }
  11826. else
  11827. {
  11828. tempIndex = gun_index;
  11829. }
  11830. for (int index = 0; index < CCS_QUANTITY; index++)
  11831. {
  11832. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11833. {
  11834. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11835. {
  11836. match = TRUE;
  11837. GunNO = gun_index;
  11838. }
  11839. }
  11840. }// END FOR CCS_QUANTITY
  11841. }
  11842. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11843. {
  11844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11845. {
  11846. tempIndex = ((gun_index==2) ? 1: 0);
  11847. }
  11848. else
  11849. {
  11850. tempIndex = gun_index;
  11851. }
  11852. for (int index = 0; index < GB_QUANTITY; index++)
  11853. {
  11854. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11855. {
  11856. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11857. {
  11858. match = TRUE;
  11859. GunNO = gun_index;
  11860. }
  11861. }
  11862. }// END FOR GB_QUANTITY
  11863. }
  11864. else if(gunType[gun_index] == GUN_TYPE_DO)
  11865. {
  11866. tempIndex = gun_index;
  11867. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11868. {
  11869. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11870. {
  11871. 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
  11872. {
  11873. match = TRUE;
  11874. GunNO = gun_index;
  11875. }
  11876. }
  11877. }// END FOR GB_QUANTITY
  11878. }
  11879. else
  11880. {
  11881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11882. {
  11883. tempIndex = 2;
  11884. }
  11885. else
  11886. {
  11887. tempIndex = gun_index;
  11888. }
  11889. for (int index = 0; index < AC_QUANTITY; index++)
  11890. {
  11891. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11892. {
  11893. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11894. {
  11895. match = TRUE;
  11896. GunNO = gun_index;
  11897. }
  11898. }
  11899. }// END FOR CHAdeMO_QUANTITY
  11900. } // END FOR AC ELSE
  11901. }// CHECK IF ResponseTransactionId == transactionIdInt
  11902. }//END FOR
  11903. if( match == TRUE)
  11904. {
  11905. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11906. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11907. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11908. }
  11909. else
  11910. {
  11911. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11912. }
  11913. }
  11914. else
  11915. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11916. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11917. return result;
  11918. }
  11919. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11920. {
  11921. mtrace();
  11922. int result = FAIL;
  11923. int connectorIdInt=0, reservationIdInt=0;
  11924. int tempIndex = 0;
  11925. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11926. char comfirmstr[20]={0};
  11927. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11928. int c = 0;
  11929. char *loc;
  11930. //char *ptr;
  11931. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11932. strcpy(sstrtemp, stringtrimspace(payload));
  11933. //***(1)connectorId ****/
  11934. c=0;
  11935. loc = strstr(sstrtemp, "connectorId");
  11936. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11937. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11938. {
  11939. sstr[c] = loc[strlen("connectorId")+2+c];
  11940. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11941. c++;
  11942. }
  11943. sstr[c] = '\0';
  11944. connectorIdInt = atoi(sstr);
  11945. //***(2)expiryDate ****/
  11946. loc = strstr(sstrtemp, "expiryDate");
  11947. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11948. c = 0;
  11949. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11950. {
  11951. sstr[c] = loc[3+strlen("expiryDate")+c];
  11952. c++;
  11953. }
  11954. sstr[c] = '\0';
  11955. strcpy(expiryDatestr, sstr);
  11956. //***(3)idTag ****/
  11957. loc = strstr(sstrtemp, "idTag");
  11958. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11959. c = 0;
  11960. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11961. {
  11962. sstr[c] = loc[3+strlen("idTag")+c];
  11963. c++;
  11964. }
  11965. sstr[c] = '\0';
  11966. strcpy(idTagstr, sstr);
  11967. //***(4)parentIdTag ****/
  11968. loc = strstr(sstrtemp, "parentIdTag");
  11969. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11970. c = 0;
  11971. if(loc == NULL)
  11972. {
  11973. strcpy(parentIdTagstr, "");
  11974. }
  11975. else
  11976. {
  11977. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11978. {
  11979. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11980. c++;
  11981. }
  11982. sstr[c] = '\0';
  11983. strcpy(parentIdTagstr, sstr);
  11984. }
  11985. //***(5)reservationId ****/
  11986. c=0;
  11987. loc = strstr(sstrtemp, "reservationId");
  11988. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11989. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11990. {
  11991. sstr[c] = loc[strlen("reservationId")+2+c];
  11992. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11993. c++;
  11994. }
  11995. sstr[c] = '\0';
  11996. reservationIdInt = atoi(sstr);
  11997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11998. /*
  11999. enum SYSTEM_STATUS
  12000. {
  12001. SYS_MODE_BOOTING = 0,
  12002. SYS_MODE_IDLE = 1,
  12003. SYS_MODE_AUTHORIZING = 2,
  12004. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12005. SYS_MODE_REASSIGN = 4,
  12006. SYS_MODE_PREPARING = 5,
  12007. SYS_MODE_PREPARE_FOR_EV = 6,
  12008. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12009. SYS_MODE_CHARGING = 8,
  12010. SYS_MODE_TERMINATING = 9,
  12011. SYS_MODE_COMPLETE = 10,
  12012. SYS_MODE_ALARM = 11,
  12013. SYS_MODE_FAULT = 12,
  12014. SYS_MODE_RESERVATION = 13,
  12015. SYS_MODE_BOOKING = 14,
  12016. SYS_MODE_MAINTAIN = 15,
  12017. SYS_MODE_DEBUG = 16,
  12018. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12019. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12020. SYS_MODE_UPDATE = 19
  12021. };
  12022. */
  12023. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12024. {
  12025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12026. goto end;
  12027. }
  12028. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12029. {
  12030. //check Transaction active
  12031. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12032. {
  12033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12034. {
  12035. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12036. }
  12037. else
  12038. {
  12039. tempIndex = connectorIdInt -1;
  12040. }
  12041. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12042. {
  12043. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12044. {
  12045. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12046. {
  12047. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12048. {
  12049. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12050. {
  12051. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12052. {
  12053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12054. }
  12055. else
  12056. {
  12057. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12059. }
  12060. }
  12061. 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'))
  12062. {
  12063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12064. }
  12065. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12066. {
  12067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12068. }
  12069. else
  12070. {
  12071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12072. }
  12073. }
  12074. 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
  12075. {
  12076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12077. }
  12078. }
  12079. else
  12080. {
  12081. //replace reservation
  12082. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12084. }
  12085. }
  12086. } // END FOR CHAdeMO_QUANTITY
  12087. }
  12088. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12089. {
  12090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12091. {
  12092. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12093. }
  12094. else
  12095. {
  12096. tempIndex = connectorIdInt -1;
  12097. }
  12098. for (int index = 0; index < CCS_QUANTITY; index++)
  12099. {
  12100. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12101. {
  12102. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12103. {
  12104. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12105. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12106. {
  12107. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12108. {
  12109. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12110. {
  12111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12112. }
  12113. else
  12114. {
  12115. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12117. }
  12118. }
  12119. 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'))
  12120. {
  12121. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12122. }
  12123. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12124. {
  12125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12126. }
  12127. else
  12128. {
  12129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12130. }
  12131. }
  12132. 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
  12133. {
  12134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12135. }
  12136. }
  12137. else
  12138. {
  12139. //replace reservation
  12140. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12142. }
  12143. }
  12144. } // END FOR CCS_QUANTITY
  12145. }
  12146. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12147. {
  12148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12149. {
  12150. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12151. }
  12152. else
  12153. {
  12154. tempIndex = connectorIdInt -1;
  12155. }
  12156. for (int index = 0; index < GB_QUANTITY; index++)
  12157. {
  12158. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12159. {
  12160. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12161. {
  12162. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12163. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12164. {
  12165. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12166. {
  12167. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12168. {
  12169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12170. }
  12171. else
  12172. {
  12173. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12174. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12175. }
  12176. }
  12177. 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'))
  12178. {
  12179. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12180. }
  12181. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12182. {
  12183. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12184. }
  12185. else
  12186. {
  12187. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12188. }
  12189. }
  12190. 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
  12191. {
  12192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12193. }
  12194. }
  12195. else
  12196. {
  12197. //replace reservation
  12198. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12200. }
  12201. }
  12202. }// END FOR GB_QUANTITY
  12203. }
  12204. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12205. {
  12206. tempIndex = connectorIdInt -1;
  12207. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12208. {
  12209. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12210. {
  12211. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12212. {
  12213. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12214. 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
  12215. {
  12216. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12217. {
  12218. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12219. {
  12220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12221. }
  12222. else
  12223. {
  12224. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12226. }
  12227. }
  12228. 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'))
  12229. {
  12230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12231. }
  12232. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12233. {
  12234. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12235. }
  12236. else
  12237. {
  12238. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12239. }
  12240. }
  12241. 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
  12242. {
  12243. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12244. }
  12245. }
  12246. else
  12247. {
  12248. //replace reservation
  12249. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12250. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12251. }
  12252. }
  12253. }// END FOR GB_QUANTITY
  12254. }
  12255. else
  12256. {
  12257. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12258. {
  12259. tempIndex = 2;
  12260. }
  12261. else
  12262. {
  12263. tempIndex = (connectorIdInt -1);
  12264. }
  12265. for (int index = 0; index < AC_QUANTITY; index++)
  12266. {
  12267. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12268. {
  12269. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12270. {
  12271. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12272. {
  12273. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12274. {
  12275. 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))
  12276. {
  12277. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12278. }
  12279. else
  12280. {
  12281. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12282. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12283. }
  12284. }
  12285. 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'))
  12286. {
  12287. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12288. }
  12289. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12290. {
  12291. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12292. }
  12293. else
  12294. {
  12295. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12296. }
  12297. }
  12298. 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
  12299. {
  12300. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12301. }
  12302. }
  12303. else
  12304. {
  12305. //replace reservation
  12306. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12307. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12308. }
  12309. }
  12310. } // END FOR AC_QUANTITY
  12311. }
  12312. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12313. }
  12314. else if(connectorIdInt == 0)
  12315. {
  12316. //check Transaction active
  12317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12318. {
  12319. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12320. {
  12321. 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'))
  12322. {
  12323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12324. goto end;
  12325. }
  12326. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12327. {
  12328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12329. goto end;
  12330. }
  12331. 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
  12332. {
  12333. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12334. goto end;
  12335. }
  12336. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12337. {
  12338. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12339. goto end;
  12340. }
  12341. }
  12342. }// END FOR CHAdeMO_QUANTITY
  12343. for (int index = 0; index < CCS_QUANTITY; index++)
  12344. {
  12345. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12346. {
  12347. 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'))
  12348. {
  12349. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12350. goto end;
  12351. }
  12352. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12353. {
  12354. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12355. goto end;
  12356. }
  12357. 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
  12358. {
  12359. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12360. goto end;
  12361. }
  12362. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12363. {
  12364. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12365. goto end;
  12366. }
  12367. }
  12368. } // END FOR CCS_QUANTITY
  12369. for (int index = 0; index < GB_QUANTITY; index++)
  12370. {
  12371. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12372. {
  12373. 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'))
  12374. {
  12375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12376. goto end;
  12377. }
  12378. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12379. {
  12380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12381. goto end;
  12382. }
  12383. 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
  12384. {
  12385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12386. goto end;
  12387. }
  12388. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12389. {
  12390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12391. goto end;
  12392. }
  12393. }
  12394. } // END FOR GB_QUANTITY
  12395. for (int index = 0; index < AC_QUANTITY; index++)
  12396. {
  12397. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12398. {
  12399. 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'))
  12400. {
  12401. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12402. goto end;
  12403. }
  12404. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12405. {
  12406. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12407. goto end;
  12408. }
  12409. 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
  12410. {
  12411. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12412. goto end;
  12413. }
  12414. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12415. {
  12416. 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))
  12417. {
  12418. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12419. goto end;
  12420. }
  12421. }
  12422. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12423. {
  12424. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12425. goto end;
  12426. }
  12427. }
  12428. }// END FOR AC_QUANTITY
  12429. //The connectorId is 0
  12430. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12432. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12433. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12434. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12435. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12436. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12437. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12438. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12439. result = TRUE;
  12440. return result;
  12441. }
  12442. else
  12443. {
  12444. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12445. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12446. }
  12447. if(strcmp(comfirmstr,"Accepted") == 0)
  12448. {
  12449. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12450. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12451. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12452. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12453. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12454. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12455. result = TRUE;
  12456. return result;
  12457. }
  12458. end:
  12459. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12460. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12461. return result;
  12462. }
  12463. int handleResetRequest(char *uuid, char *payload)
  12464. {
  12465. mtrace();
  12466. int result = FAIL;
  12467. char sstr[10]={0},sstrtemp[30]={ 0 };
  12468. char typestr[10]={0};
  12469. char comfirmstr[20]={0};
  12470. int c = 0;
  12471. char *loc;
  12472. DEBUG_INFO("handleResetRequest...\n");
  12473. strcpy(sstrtemp, stringtrimspace(payload));
  12474. loc = strstr(sstrtemp, "type");
  12475. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12476. c = 0;
  12477. while (loc[3+strlen("type")+c] != '\"')
  12478. {
  12479. sstr[c] = loc[3+strlen("type")+c];
  12480. c++;
  12481. }
  12482. sstr[c] = '\0';
  12483. strcpy(typestr,sstr);
  12484. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12485. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12486. {
  12487. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12488. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12489. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12490. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12491. }
  12492. else
  12493. {
  12494. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12495. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12496. result = PASS;
  12497. }
  12498. sendResetConfirmation(uuid, comfirmstr);
  12499. return result;
  12500. }
  12501. int handleSendLocalListRequest(char *uuid, char *payload)
  12502. {
  12503. mtrace();
  12504. int result = FAIL;
  12505. char comfirmstr[20];
  12506. int checkState_Faulted = FALSE;
  12507. json_object *SendLocalList;
  12508. DEBUG_INFO("handleSendLocalListRequest...\n");
  12509. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12510. {
  12511. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12512. goto end;
  12513. }
  12514. //check Charge Point state
  12515. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12516. {
  12517. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12518. {
  12519. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12520. }
  12521. }
  12522. for (int index = 0; index < CCS_QUANTITY; index++)
  12523. {
  12524. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12525. {
  12526. checkState_Faulted = TRUE; //OCPP Status
  12527. }
  12528. }
  12529. for (int index = 0; index < GB_QUANTITY; index++)
  12530. {
  12531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12532. {
  12533. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12534. }
  12535. }
  12536. //check Charge Point state
  12537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12538. {
  12539. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12540. {
  12541. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12542. }
  12543. }
  12544. //check Charge Point state
  12545. for (int index = 0; index < AC_QUANTITY; index++)
  12546. {
  12547. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12548. {
  12549. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12550. }
  12551. }
  12552. if(checkState_Faulted == TRUE)
  12553. {
  12554. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12555. goto end;
  12556. }
  12557. // Parsing payload
  12558. SendLocalList = json_tokener_parse(payload);
  12559. if(!is_error(SendLocalList))
  12560. {
  12561. // Required data
  12562. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12563. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12564. // Optional data
  12565. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12566. {
  12567. //Check UpdateType
  12568. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12569. {
  12570. //Local list full update
  12571. DEBUG_INFO("Local list full update.\n");
  12572. locallistVersion = 0;
  12573. OCPP_getListVerion();
  12574. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12575. {
  12576. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12577. goto end;
  12578. }
  12579. OCPP_cleanLocalList();
  12580. }
  12581. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12582. {
  12583. //Local list different update
  12584. DEBUG_INFO("Local list different update.\n");
  12585. locallistVersion = 0;
  12586. OCPP_getListVerion();
  12587. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12588. {
  12589. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12590. goto end;
  12591. }
  12592. }
  12593. else
  12594. {
  12595. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12596. goto end;
  12597. }
  12598. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12599. {
  12600. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12601. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12602. goto end;
  12603. }
  12604. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12605. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12606. {
  12607. 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"))));
  12608. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12609. {
  12610. 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"))));
  12611. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12612. 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"))));
  12613. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12614. 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"))));
  12615. }
  12616. // Add to db
  12617. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12618. {
  12619. //Local list full update
  12620. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12621. idx,
  12622. ShmOCPP16Data->SendLocalList.ListVersion,
  12623. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12624. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12625. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12626. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12627. // update list
  12628. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12629. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12630. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12631. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12632. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12633. }
  12634. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12635. {
  12636. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12637. idx,
  12638. ShmOCPP16Data->SendLocalList.ListVersion,
  12639. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12640. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12641. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12642. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12643. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12644. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12645. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12646. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12647. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12648. }
  12649. }
  12650. }
  12651. else
  12652. {
  12653. //Check UpdateType
  12654. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12655. {
  12656. //Local list full update
  12657. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12658. OCPP_cleanLocalList();
  12659. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12660. goto end;
  12661. }
  12662. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12663. {
  12664. //Local list different update
  12665. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12666. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12667. goto end;
  12668. }
  12669. }
  12670. result = PASS;
  12671. }
  12672. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12673. end:
  12674. json_object_put(SendLocalList);
  12675. sendSendLocalListConfirmation(uuid, comfirmstr);
  12676. return result;
  12677. }
  12678. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12679. {
  12680. mtrace();
  12681. int result = FAIL;
  12682. struct StructSetChargingProfile SetProfileReq = {0};
  12683. int tempchargingProfileIdInt;
  12684. int tempstackLevelInt;
  12685. int chargingSchedulePeriodCount = 0;
  12686. char comfirmstr[20]={0};
  12687. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12688. char rmFileCmd[128]={0};
  12689. int profileQuantity = 0;
  12690. int replaceableProfileCnt = 0;
  12691. json_object *SetChargingProfile;
  12692. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12693. SetChargingProfile = json_tokener_parse(payload);
  12694. if(!is_error(SetChargingProfile))
  12695. {
  12696. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12697. {
  12698. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12699. }
  12700. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12701. {
  12702. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12703. {
  12704. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12705. }
  12706. else
  12707. {
  12708. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12709. DEBUG_WARN("Cannot find chargingProfileId field.");
  12710. goto end;
  12711. }
  12712. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12713. {
  12714. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12715. }
  12716. else
  12717. {
  12718. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12719. DEBUG_WARN("Cannot find stackLevel field.");
  12720. goto end;
  12721. }
  12722. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12723. {
  12724. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12725. }
  12726. else
  12727. {
  12728. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12729. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12730. goto end;
  12731. }
  12732. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12733. {
  12734. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12735. }
  12736. else
  12737. {
  12738. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12739. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12740. goto end;
  12741. }
  12742. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12743. {
  12744. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12745. }
  12746. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12747. {
  12748. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12749. }
  12750. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12751. {
  12752. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12753. }
  12754. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12755. {
  12756. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12757. }
  12758. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12759. {
  12760. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12761. {
  12762. 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")));
  12763. }
  12764. else
  12765. {
  12766. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12767. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12768. goto end;
  12769. }
  12770. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12771. {
  12772. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12773. }
  12774. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12775. {
  12776. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12777. }
  12778. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12779. {
  12780. 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")));
  12781. }
  12782. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12783. {
  12784. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12785. if(chargingSchedulePeriodCount <= 10)
  12786. {
  12787. 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++)
  12788. {
  12789. 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)
  12790. {
  12791. 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"));
  12792. }
  12793. else
  12794. {
  12795. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12796. DEBUG_WARN("Cannot find startPeriod field.");
  12797. goto end;
  12798. }
  12799. 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)
  12800. {
  12801. 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"));
  12802. }
  12803. else
  12804. {
  12805. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12806. DEBUG_WARN("Cannot find limit field.");
  12807. goto end;
  12808. }
  12809. 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)
  12810. {
  12811. 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"));
  12812. }
  12813. }
  12814. }
  12815. }
  12816. else
  12817. {
  12818. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12819. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12820. goto end;
  12821. }
  12822. }
  12823. else
  12824. {
  12825. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12826. DEBUG_WARN("Cannot find chargingSchedule field.");
  12827. goto end;
  12828. }
  12829. }
  12830. }
  12831. // Profile periods quantity check
  12832. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12833. {
  12834. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12835. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12836. goto end;
  12837. }
  12838. // Check invalid limit
  12839. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12840. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12841. {
  12842. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12843. {
  12844. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12845. {
  12846. 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)))) ||
  12847. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12848. {
  12849. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12850. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12851. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12852. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12853. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12854. goto end;
  12855. }
  12856. }
  12857. }
  12858. else
  12859. {
  12860. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12861. {
  12862. 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) ||
  12863. (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)))
  12864. {
  12865. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12866. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12867. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12868. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12869. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12870. goto end;
  12871. }
  12872. }
  12873. }
  12874. }
  12875. // Profile purpose info check
  12876. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12877. {
  12878. FILE *fp;
  12879. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12880. if(SetProfileReq.ConnectorId != 0)
  12881. {
  12882. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12883. DEBUG_WARN("Profile connector id is not 0.\n");
  12884. goto end;
  12885. }
  12886. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12887. if (!fp)
  12888. {
  12889. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12890. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12891. }
  12892. else
  12893. {
  12894. char *line = NULL;
  12895. size_t len = 0;
  12896. while(getline(&line, &len, fp) != -1)
  12897. {
  12898. json_object *obj = NULL;
  12899. obj = json_tokener_parse(line);
  12900. if(is_error(obj))
  12901. {
  12902. DEBUG_ERROR("Parse txProfile from file error.\n");
  12903. }
  12904. else
  12905. {
  12906. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12907. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12908. {
  12909. profileQuantity += 1;
  12910. }
  12911. else
  12912. replaceableProfileCnt += 1;
  12913. }
  12914. }
  12915. }
  12916. fclose(fp);
  12917. }
  12918. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12919. {
  12920. FILE *fp;
  12921. char filename[128]={0};
  12922. int tmpProfileQuantity;
  12923. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12924. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12925. {
  12926. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12927. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12928. goto end;
  12929. }
  12930. if(SetProfileReq.ConnectorId == 0)
  12931. {
  12932. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12933. {
  12934. tmpProfileQuantity = 0;
  12935. memset(filename, 0, ARRAY_SIZE(filename));
  12936. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12937. fp = fopen(filename, "r");
  12938. if (!fp)
  12939. {
  12940. DEBUG_INFO("%s does not create.\n", filename);
  12941. fp = fopen(filename, "w+");
  12942. }
  12943. else
  12944. {
  12945. char *line = NULL;
  12946. size_t len = 0;
  12947. while(getline(&line, &len, fp) != -1)
  12948. {
  12949. json_object *obj = NULL;
  12950. obj = json_tokener_parse(line);
  12951. if(is_error(obj))
  12952. {
  12953. DEBUG_ERROR("Parse txProfile from file error.\n");
  12954. }
  12955. else
  12956. {
  12957. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12958. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12959. {
  12960. tmpProfileQuantity += 1;
  12961. }
  12962. else
  12963. replaceableProfileCnt += 1;
  12964. }
  12965. }
  12966. }
  12967. fclose(fp);
  12968. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12969. }
  12970. }
  12971. else
  12972. {
  12973. memset(filename, 0, ARRAY_SIZE(filename));
  12974. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12975. fp = fopen(filename, "r");
  12976. if (!fp)
  12977. {
  12978. DEBUG_INFO("%s does not create.\n", filename);
  12979. fp = fopen(filename, "w+");
  12980. }
  12981. else
  12982. {
  12983. char *line = NULL;
  12984. size_t len = 0;
  12985. while(getline(&line, &len, fp) != -1)
  12986. {
  12987. json_object *obj = NULL;
  12988. obj = json_tokener_parse(line);
  12989. if(is_error(obj))
  12990. {
  12991. DEBUG_ERROR("Parse txProfile from file error.\n");
  12992. }
  12993. else
  12994. {
  12995. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12996. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12997. {
  12998. profileQuantity += 1;
  12999. }
  13000. else
  13001. replaceableProfileCnt += 1;
  13002. }
  13003. }
  13004. }
  13005. fclose(fp);
  13006. }
  13007. }
  13008. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13009. {
  13010. int isMatchTransactiodId= FALSE;
  13011. FILE *fp;
  13012. char filename[128]={0};
  13013. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13014. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13015. if(SetProfileReq.ConnectorId == 0)
  13016. {
  13017. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13018. DEBUG_WARN("Profile connector id is 0.\n");
  13019. goto end;
  13020. }
  13021. int tempIndex = 0;
  13022. //check Transaction active
  13023. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13024. {
  13025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13026. {
  13027. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13028. }
  13029. else
  13030. {
  13031. tempIndex = SetProfileReq.ConnectorId -1;
  13032. }
  13033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13034. {
  13035. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13036. {
  13037. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13038. {
  13039. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13040. {
  13041. isMatchTransactiodId = TRUE;
  13042. break;
  13043. }
  13044. }
  13045. }
  13046. }
  13047. }
  13048. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13049. {
  13050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13051. {
  13052. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13053. }
  13054. else
  13055. {
  13056. tempIndex = SetProfileReq.ConnectorId -1;
  13057. }
  13058. for (int index = 0; index < CCS_QUANTITY; index++)
  13059. {
  13060. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13061. {
  13062. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13063. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13064. {
  13065. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13066. {
  13067. isMatchTransactiodId = TRUE;
  13068. break;
  13069. }
  13070. }
  13071. }
  13072. }
  13073. }
  13074. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13075. {
  13076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13077. {
  13078. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13079. }
  13080. else
  13081. {
  13082. tempIndex = SetProfileReq.ConnectorId -1;
  13083. }
  13084. for (int index = 0; index < GB_QUANTITY; index++)
  13085. {
  13086. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13087. {
  13088. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13089. {
  13090. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13091. {
  13092. isMatchTransactiodId = TRUE;
  13093. break;
  13094. }
  13095. }
  13096. }
  13097. }
  13098. }
  13099. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13100. {
  13101. tempIndex = SetProfileReq.ConnectorId -1;
  13102. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13103. {
  13104. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13105. {
  13106. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13107. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13108. {
  13109. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13110. {
  13111. isMatchTransactiodId = TRUE;
  13112. break;
  13113. }
  13114. }
  13115. }
  13116. }
  13117. }
  13118. else
  13119. {
  13120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13121. {
  13122. tempIndex = 2;
  13123. }
  13124. else
  13125. {
  13126. tempIndex = (SetProfileReq.ConnectorId -1);
  13127. }
  13128. for (int index = 0; index < AC_QUANTITY; index++)
  13129. {
  13130. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13131. {
  13132. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13133. {
  13134. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13135. {
  13136. isMatchTransactiodId = TRUE;
  13137. break;
  13138. }
  13139. }
  13140. }
  13141. }
  13142. }
  13143. //check Transaction active
  13144. if(isMatchTransactiodId == FALSE)
  13145. {
  13146. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13147. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13148. goto end;
  13149. }
  13150. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13151. {
  13152. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13153. DEBUG_WARN("Connector id is over max gun number.\n");
  13154. goto end;
  13155. }
  13156. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13157. fp = fopen(filename, "r");
  13158. if (!fp)
  13159. {
  13160. DEBUG_INFO("%s does not create.\n", filename);
  13161. fp = fopen(filename, "w+");
  13162. }
  13163. else
  13164. {
  13165. char *line = NULL;
  13166. size_t len = 0;
  13167. while(getline(&line, &len, fp) != -1)
  13168. {
  13169. json_object *obj = NULL;
  13170. obj = json_tokener_parse(line);
  13171. if(is_error(obj))
  13172. {
  13173. DEBUG_ERROR("Parse txProfile from file error.\n");
  13174. }
  13175. else
  13176. {
  13177. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13178. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13179. {
  13180. profileQuantity += 1;
  13181. }
  13182. else
  13183. replaceableProfileCnt += 1;
  13184. }
  13185. }
  13186. }
  13187. fclose(fp);
  13188. }
  13189. // Check ChargeProfileMaxStackLevel
  13190. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13191. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13192. {
  13193. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13194. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13195. goto end;
  13196. }
  13197. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13198. {
  13199. FILE *fp;
  13200. char dataLine[4096]={0};
  13201. char fnametemp[128]={0};
  13202. int tmpProfileQuantity;
  13203. //Check ChargePointMaxProfile.json exit
  13204. profileQuantity = 0;
  13205. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13206. {
  13207. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13208. //Check Charging Profile Count
  13209. tmpProfileQuantity = 0;
  13210. while(fscanf(fp, "%s", dataLine) != EOF)
  13211. {
  13212. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13213. {
  13214. profileQuantity += 1;
  13215. tmpProfileQuantity += 1;
  13216. }
  13217. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13218. }
  13219. fclose(fp);
  13220. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13221. }
  13222. //Check TxDefaultProfile_%d.json
  13223. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13224. {
  13225. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13226. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13227. if((access(fnametemp,F_OK))!=-1)
  13228. {
  13229. fp = fopen(fnametemp, "r");
  13230. //Check Charging Profile Count
  13231. tmpProfileQuantity = 0;
  13232. while(fscanf(fp, "%s", dataLine) != EOF)
  13233. {
  13234. //DEBUG_INFO("word=%s\n",word);
  13235. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13236. {
  13237. profileQuantity += 1;
  13238. tmpProfileQuantity += 1;
  13239. }
  13240. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13241. }
  13242. fclose(fp);
  13243. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13244. }
  13245. }
  13246. //Check TxProfile_%d.json
  13247. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13248. {
  13249. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13250. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13251. if((access(fnametemp,F_OK))!=-1)
  13252. {
  13253. fp = fopen(fnametemp, "r");
  13254. //Check Charging Profile Count
  13255. tmpProfileQuantity = 0;
  13256. while(fscanf(fp, "%s", dataLine) != EOF)
  13257. {
  13258. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13259. {
  13260. profileQuantity += 1;
  13261. tmpProfileQuantity += 1;
  13262. }
  13263. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13264. }
  13265. fclose(fp);
  13266. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13267. }
  13268. }
  13269. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13270. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13271. // To check total Profile quantity
  13272. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13273. {
  13274. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13275. {
  13276. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13277. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13278. goto end;
  13279. }
  13280. }
  13281. else
  13282. {
  13283. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13284. {
  13285. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13286. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13287. goto end;
  13288. }
  13289. }
  13290. }
  13291. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13292. //**********************************Write to File********************************************************/
  13293. {
  13294. FILE *infile;
  13295. FILE *outfile;
  13296. char dataLine[4096]={0};
  13297. char filename[128]={0};
  13298. int chkChar=0;
  13299. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13300. {
  13301. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13302. {
  13303. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13304. }
  13305. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13306. {
  13307. if(SetProfileReq.ConnectorId==0)
  13308. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13309. else
  13310. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13311. }
  13312. else
  13313. {
  13314. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13315. }
  13316. infile = fopen (filename, "r");
  13317. outfile = fopen (tempfile, "w");
  13318. chkChar = fgetc(infile);
  13319. rewind(infile);
  13320. if(chkChar == EOF)
  13321. {
  13322. // Profile is empty
  13323. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13324. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13325. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13326. fclose(infile);
  13327. fclose(outfile);
  13328. sprintf(rmFileCmd,"rm -f %s",filename);
  13329. system(rmFileCmd);
  13330. rename(tempfile, filename);
  13331. }
  13332. else
  13333. {
  13334. // Profile is not empty
  13335. int ChargingProfileAdded = FALSE;
  13336. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13337. {
  13338. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13339. json_object *tmpChargingProfile;
  13340. tmpChargingProfile = json_tokener_parse(dataLine);
  13341. if(!is_error(SetChargingProfile))
  13342. {
  13343. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13344. {
  13345. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13346. {
  13347. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13348. }
  13349. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13350. {
  13351. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13352. }
  13353. }
  13354. }
  13355. json_object_put(tmpChargingProfile);
  13356. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13357. {
  13358. if(ChargingProfileAdded == FALSE)
  13359. {
  13360. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13361. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13362. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13363. ChargingProfileAdded = TRUE;
  13364. }
  13365. }
  13366. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13367. {
  13368. if(ChargingProfileAdded == FALSE)
  13369. {
  13370. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13371. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13372. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13373. ChargingProfileAdded = TRUE;
  13374. }
  13375. }
  13376. else
  13377. {
  13378. fprintf(outfile,"%s\n",dataLine);
  13379. if(ChargingProfileAdded == FALSE)
  13380. {
  13381. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13382. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13383. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13384. ChargingProfileAdded = TRUE;
  13385. }
  13386. }
  13387. } // end of while loop
  13388. fclose(infile);
  13389. fclose(outfile);
  13390. sprintf(rmFileCmd,"rm -f %s",filename);
  13391. system(rmFileCmd);
  13392. rename(tempfile, filename);
  13393. }
  13394. }
  13395. sleep(1);
  13396. result = TRUE;
  13397. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13398. }
  13399. end:
  13400. json_object_put(SetChargingProfile);
  13401. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13402. {
  13403. if(SetProfileReq.ConnectorId == 0)
  13404. {
  13405. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13406. {
  13407. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13408. }
  13409. }
  13410. else
  13411. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13412. }
  13413. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13414. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13415. return result;
  13416. }
  13417. int handleTriggerMessageRequest(char *uuid, char *payload)
  13418. {
  13419. mtrace();
  13420. int result = FAIL;
  13421. int connectorIdIsNULL = FALSE;
  13422. int connectorIdInt =0;
  13423. char sstr[40]={0},sstrtemp[100]={ 0 };
  13424. char requestedMessagestr[40]={0};
  13425. char comfirmstr[20]={0};
  13426. int c = 0;
  13427. char *loc;
  13428. DEBUG_INFO("handleTriggerMessageRequest\n");
  13429. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13430. strcpy(sstrtemp, stringtrimspace(payload));
  13431. c = 0;
  13432. loc = strstr(sstrtemp, "requestedMessage");
  13433. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13434. {
  13435. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13436. c++;
  13437. }
  13438. sstr[c] = '\0';
  13439. strcpy(requestedMessagestr, sstr);
  13440. c = 0;
  13441. loc = strstr(sstrtemp, "connectorId");
  13442. if(loc == NULL)
  13443. {
  13444. connectorIdIsNULL = TRUE;
  13445. }
  13446. else
  13447. {
  13448. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13449. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13450. {
  13451. sstr[c] = loc[strlen("connectorId")+2+c];
  13452. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13453. c++;
  13454. }
  13455. sstr[c] = '\0';
  13456. connectorIdInt = atoi(sstr);
  13457. }
  13458. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13459. {
  13460. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13461. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13462. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13463. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13464. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13465. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13466. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13467. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13468. {
  13469. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13470. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13471. return TRUE;
  13472. }
  13473. else
  13474. {
  13475. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13476. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13477. }
  13478. }
  13479. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13480. {
  13481. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13482. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13483. return TRUE;
  13484. }
  13485. //==========================
  13486. // Trigger message
  13487. //==========================
  13488. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13489. {
  13490. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13491. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13492. {
  13493. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13494. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13495. }
  13496. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13497. }
  13498. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13499. {
  13500. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13501. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13502. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13503. }
  13504. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13505. {
  13506. //sendBootNotificationRequest();
  13507. server_sign = FALSE;
  13508. }
  13509. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13510. {
  13511. refreshStartTimer(&clientTime.Heartbeat);
  13512. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13513. }
  13514. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13515. {
  13516. if(connectorIdIsNULL == FALSE)
  13517. {
  13518. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13519. {
  13520. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13521. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13522. }
  13523. }
  13524. else
  13525. {
  13526. for(int idx=0;idx< gunTotalNumber;idx++)
  13527. {
  13528. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13529. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13530. }
  13531. }
  13532. }
  13533. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13534. {
  13535. if(connectorIdIsNULL == FALSE)
  13536. {
  13537. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13538. {
  13539. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13540. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13541. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13542. }
  13543. }
  13544. else
  13545. {
  13546. for(int idx=0;idx< gunTotalNumber;idx++)
  13547. {
  13548. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13549. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13550. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13551. }
  13552. }
  13553. }
  13554. return result;
  13555. }
  13556. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13557. {
  13558. mtrace();
  13559. int result = FAIL;
  13560. int connectorIdInt =0;
  13561. char comfirmstr[20]={0};
  13562. int tempIndex = 0;
  13563. json_object *UnlockConnector;
  13564. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13565. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13566. UnlockConnector = json_tokener_parse(payload);
  13567. if(!is_error(UnlockConnector))
  13568. {
  13569. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13570. {
  13571. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13572. }
  13573. }
  13574. json_object_put(UnlockConnector);
  13575. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13576. if(gunTotalNumber == 0)
  13577. {
  13578. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13579. goto end;
  13580. }
  13581. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13582. {
  13583. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13584. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13585. goto end;
  13586. }
  13587. else
  13588. {
  13589. //check Transaction active
  13590. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13591. {
  13592. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13593. {
  13594. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13595. }
  13596. else
  13597. {
  13598. tempIndex = connectorIdInt -1;
  13599. }
  13600. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13601. {
  13602. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13603. {
  13604. //stop Transaction
  13605. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13606. }
  13607. }
  13608. }
  13609. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13610. {
  13611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13612. {
  13613. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13614. }
  13615. else
  13616. {
  13617. tempIndex = connectorIdInt -1;
  13618. }
  13619. for (int index = 0; index < CCS_QUANTITY; index++)
  13620. {
  13621. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13622. {
  13623. //stop Transaction
  13624. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13625. }
  13626. }
  13627. }
  13628. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13629. {
  13630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13631. {
  13632. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13633. }
  13634. else
  13635. {
  13636. tempIndex = connectorIdInt -1;
  13637. }
  13638. for (int index = 0; index < GB_QUANTITY; index++)
  13639. {
  13640. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13641. {
  13642. //stop Transaction
  13643. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13644. }
  13645. }
  13646. }
  13647. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13648. {
  13649. tempIndex = connectorIdInt -1;
  13650. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13651. {
  13652. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13653. {
  13654. //stop Transaction
  13655. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13656. }
  13657. }
  13658. }
  13659. else
  13660. {
  13661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13662. {
  13663. tempIndex = 2;
  13664. }
  13665. else
  13666. {
  13667. tempIndex = connectorIdInt-1;
  13668. }
  13669. for (int index = 0; index < AC_QUANTITY; index++)
  13670. {
  13671. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13672. {
  13673. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13674. }
  13675. }
  13676. }
  13677. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13678. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13679. result = TRUE;
  13680. return result;
  13681. }
  13682. end:
  13683. //json_object_put(obj); --- remove temporally
  13684. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13685. return result;
  13686. }
  13687. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13688. {
  13689. mtrace();
  13690. int result = FAIL;
  13691. pthread_t t;
  13692. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13693. sendUpdateFirmwareConfirmation(uuid);
  13694. if(!interLock.isUpdateFirmwareGoing)
  13695. {
  13696. interLock.isUpdateFirmwareGoing = 1;
  13697. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13698. sleep(1);
  13699. }
  13700. else
  13701. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13702. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13703. return result;
  13704. }
  13705. void *UpdateFirmwareProcess(void *data)
  13706. {
  13707. pthread_detach(pthread_self());
  13708. mtrace();
  13709. int retriesInt =0, retryIntervalInt=0;
  13710. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13711. int port=0;
  13712. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13713. int isSuccess = 0;
  13714. char ftpbuf[1024];
  13715. char temp[1024];
  13716. char * pch;
  13717. json_object *UpdateFirmware;
  13718. UpdateFirmware = json_tokener_parse(data);
  13719. if(!is_error(UpdateFirmware))
  13720. {
  13721. // Required data
  13722. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13723. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13724. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13725. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13726. // Optional data
  13727. if(json_object_object_get(UpdateFirmware, "retries"))
  13728. {
  13729. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13730. }
  13731. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13732. {
  13733. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13734. }
  13735. }
  13736. json_object_put(UpdateFirmware);
  13737. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13738. memset(path, 0, ARRAY_SIZE(path));
  13739. // Wait retrieveData
  13740. if(strlen(retrieveDatestr) > 10)
  13741. {
  13742. do
  13743. {
  13744. sleep(1);
  13745. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13746. }
  13747. // Ready to download
  13748. system("rm -f /mnt/*");
  13749. if(strncmp(locationstr,"http", 4) == 0)
  13750. {
  13751. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13752. sprintf(ftppath,"/%s", path);
  13753. DEBUG_INFO("locationstr: %s\n", locationstr);
  13754. DEBUG_INFO("protocol: %s\n",protocol);
  13755. DEBUG_INFO("host: %s\n",host);
  13756. DEBUG_INFO("path: %s\n",path);
  13757. DEBUG_INFO("ftppath: %s\n",ftppath);
  13758. int ftppathlen=strlen(ftppath);
  13759. int i=1;
  13760. char filenametemp[50];
  13761. while(i < ftppathlen)
  13762. {
  13763. int len=ftppathlen-i;
  13764. if(ftppath[len]== 47) // '/' ascll code: 47
  13765. {
  13766. DEBUG_INFO("compare '/' all right\n");
  13767. break;
  13768. }
  13769. i=i+1;
  13770. }
  13771. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13772. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13773. filenametemp[i+1] = 0;
  13774. do
  13775. {
  13776. sleep(1);
  13777. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13778. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13779. sleep(1);
  13780. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13781. if(!isSuccess)
  13782. {
  13783. sleep(1);
  13784. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13785. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13786. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13787. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13788. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13789. }
  13790. else
  13791. {
  13792. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13793. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13794. }
  13795. retriesInt--;
  13796. }while((isSuccess == 0)&&(retriesInt >= 0));
  13797. }
  13798. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13799. {
  13800. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13801. memset(temp, 0, ARRAY_SIZE(temp));
  13802. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13803. strcpy(ftpbuf, locationstr);
  13804. int ftppathlen=strlen(ftpbuf);
  13805. int i=1;
  13806. char filenametemp[50];
  13807. while(i < ftppathlen)
  13808. {
  13809. int len=ftppathlen-i;
  13810. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13811. {
  13812. DEBUG_INFO(" compare '/' all right\n");
  13813. break;
  13814. }
  13815. i=i+1;
  13816. }
  13817. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13818. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13819. filenametemp[i+1] = 0;
  13820. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13821. pch=strchr(temp,'@');
  13822. if(pch==NULL)
  13823. {
  13824. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13825. protocol, host, &port, path);
  13826. strcpy(user,"anonymous");
  13827. strcpy(password,"");
  13828. }
  13829. else
  13830. {
  13831. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13832. protocol, user, host, &port, path);
  13833. }
  13834. sscanf(host,"%[^/]%s",host1, path1);
  13835. sprintf(ftppath,"%s:/%s", host,path);
  13836. if(port == 0)
  13837. {
  13838. port = 21;
  13839. }
  13840. do
  13841. {
  13842. sleep(1);
  13843. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13844. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13845. sleep(1);
  13846. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13847. if(!isSuccess)
  13848. {
  13849. //BulldogUtil.sleepMs(interval*1000);
  13850. DEBUG_INFO("Update firmware request and download file fail.\n");
  13851. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13852. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13853. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13854. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13855. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13856. }
  13857. else
  13858. {
  13859. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13860. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13861. }
  13862. retriesInt--;
  13863. }while((!isSuccess)&&(retriesInt >= 0));
  13864. }
  13865. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13866. {
  13867. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13868. memset(temp, 0, ARRAY_SIZE(temp));
  13869. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13870. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13871. int ftppathlen=strlen(ftpbuf);
  13872. int i=1;
  13873. char filenametemp[50];
  13874. while(i < ftppathlen)
  13875. {
  13876. int len=ftppathlen-i;
  13877. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13878. {
  13879. DEBUG_INFO(" compare '/' all right\n");
  13880. break;
  13881. }
  13882. i=i+1;
  13883. }
  13884. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13885. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13886. filenametemp[i+1] = 0;
  13887. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13888. pch=strchr(temp,'@');
  13889. if(pch==NULL)
  13890. {
  13891. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13892. protocol, host, &port, path);
  13893. strcpy(user,"anonymous");
  13894. strcpy(password,"");
  13895. }
  13896. else
  13897. {
  13898. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13899. protocol, user, password, host, &port, path);
  13900. }
  13901. sscanf(host,"%[^/]%s",host1, path1);
  13902. sprintf(ftppath,"%s", path1);
  13903. //DEBUG_INFO("protocol =%s\n",protocol);
  13904. //DEBUG_INFO("user =%s\n",user);
  13905. //DEBUG_INFO("password =%s\n",password);
  13906. //DEBUG_INFO("host1 =%s\n",host1);
  13907. //DEBUG_INFO("port =%d\n",port);
  13908. //DEBUG_INFO("path1 =%s\n",path1);
  13909. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13910. //ftpFile(host, user, password, port, ftppath, fname);
  13911. //download firmware pthred
  13912. if(port == 0)
  13913. {
  13914. port = 21;
  13915. }
  13916. do
  13917. {
  13918. sleep(1);
  13919. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13920. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13921. sleep(1);
  13922. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13923. if(!isSuccess)
  13924. {
  13925. //BulldogUtil.sleepMs(interval*1000);
  13926. DEBUG_INFO("Update firmware request and download file fail.\n");
  13927. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13928. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13929. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13930. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13931. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13932. }
  13933. else
  13934. {
  13935. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13936. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13937. }
  13938. retriesInt--;
  13939. }while((!isSuccess)&&(retriesInt >= 0));
  13940. }
  13941. else
  13942. {
  13943. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13944. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13945. sleep(1);
  13946. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13947. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13948. }
  13949. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13950. {
  13951. sleep(3);
  13952. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13953. }
  13954. interLock.isUpdateFirmwareGoing = 0;
  13955. pthread_exit(NULL);
  13956. }
  13957. int handleCertificateSignedRequest(char *uuid, char *payload)
  13958. {
  13959. mtrace();
  13960. int result = PASS;
  13961. json_object *CertificateSigned;
  13962. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13963. CertificateSigned = json_tokener_parse(payload);
  13964. if(!is_error(CertificateSigned))
  13965. {
  13966. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13967. }
  13968. json_object_put(CertificateSigned);
  13969. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  13970. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13971. fclose(fp);
  13972. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13973. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13974. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  13975. {
  13976. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13977. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  13978. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  13979. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  13980. }
  13981. else
  13982. {
  13983. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  13984. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  13985. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  13986. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  13987. }
  13988. sendCertificateSignedConfirmation(uuid);
  13989. return result;
  13990. }
  13991. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13992. {
  13993. mtrace();
  13994. int result = PASS;
  13995. json_object *DeleteCertificate;
  13996. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13997. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13998. DeleteCertificate = json_tokener_parse(payload);
  13999. if(!is_error(DeleteCertificate))
  14000. {
  14001. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14002. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14003. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14004. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14005. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14006. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14007. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14008. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14009. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  14010. {
  14011. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  14012. }
  14013. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  14014. {
  14015. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  14016. }
  14017. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  14018. {
  14019. ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  14020. }
  14021. char temp[256] = {0};
  14022. char compareData[256] = {0};
  14023. int isMatch = TRUE;
  14024. // Check CentralSystemRootCertificate
  14025. if(access(ROOTCA_CS,F_OK) != -1)
  14026. {
  14027. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14028. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14029. for(int i = 0; compareData[i]; i++)
  14030. {
  14031. compareData[i] = tolower(compareData[i]);
  14032. }
  14033. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14034. isMatch = FALSE;
  14035. if(isMatch == TRUE)
  14036. {
  14037. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14038. for(int i = 0; compareData[i]; i++)
  14039. {
  14040. compareData[i] = tolower(compareData[i]);
  14041. }
  14042. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14043. isMatch = FALSE;
  14044. }
  14045. if(isMatch == TRUE)
  14046. {
  14047. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14048. for(int i = 0; compareData[i]; i++)
  14049. {
  14050. compareData[i] = tolower(compareData[i]);
  14051. }
  14052. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14053. isMatch = FALSE;
  14054. }
  14055. if(isMatch == TRUE)
  14056. {
  14057. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  14058. sprintf(temp, "rm -f %s", ROOTCA_CS);
  14059. system(temp);
  14060. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14061. goto End;
  14062. }
  14063. }
  14064. // Check ManufacturerRootCertificate
  14065. if(access(ROOTCA_MF,F_OK) != -1)
  14066. {
  14067. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  14068. isMatch = TRUE;
  14069. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  14070. for(int i = 0; compareData[i]; i++)
  14071. {
  14072. compareData[i] = tolower(compareData[i]);
  14073. }
  14074. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14075. isMatch = FALSE;
  14076. if(isMatch == TRUE)
  14077. {
  14078. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  14079. for(int i = 0; compareData[i]; i++)
  14080. {
  14081. compareData[i] = tolower(compareData[i]);
  14082. }
  14083. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14084. isMatch = FALSE;
  14085. }
  14086. if(isMatch == TRUE)
  14087. {
  14088. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  14089. for(int i = 0; compareData[i]; i++)
  14090. {
  14091. compareData[i] = tolower(compareData[i]);
  14092. }
  14093. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14094. isMatch = FALSE;
  14095. }
  14096. if(isMatch == TRUE)
  14097. {
  14098. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  14099. sprintf(temp, "rm -f %s", ROOTCA_MF);
  14100. system(temp);
  14101. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14102. goto End;
  14103. }
  14104. }
  14105. // Check certCP
  14106. if(access(CERTIFICATE_CP,F_OK) != -1)
  14107. {
  14108. DEBUG_INFO("Checking certCP...\n");
  14109. isMatch = TRUE;
  14110. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  14111. for(int i = 0; compareData[i]; i++)
  14112. {
  14113. compareData[i] = tolower(compareData[i]);
  14114. }
  14115. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14116. isMatch = FALSE;
  14117. if(isMatch == TRUE)
  14118. {
  14119. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  14120. for(int i = 0; compareData[i]; i++)
  14121. {
  14122. compareData[i] = tolower(compareData[i]);
  14123. }
  14124. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14125. isMatch = FALSE;
  14126. }
  14127. if(isMatch == TRUE)
  14128. {
  14129. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  14130. for(int i = 0; compareData[i]; i++)
  14131. {
  14132. compareData[i] = tolower(compareData[i]);
  14133. }
  14134. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14135. isMatch = FALSE;
  14136. }
  14137. if(isMatch == TRUE)
  14138. {
  14139. DEBUG_INFO("Deleting certCP...\n");
  14140. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14141. system(temp);
  14142. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14143. goto End;
  14144. }
  14145. }
  14146. }
  14147. End:
  14148. json_object_put(DeleteCertificate);
  14149. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14150. sendDeleteCertificateConfirmation(uuid);
  14151. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14152. return result;
  14153. }
  14154. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14155. {
  14156. mtrace();
  14157. int result = PASS;
  14158. json_object *ExtendedTriggerMessage;
  14159. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14160. ExtendedTriggerMessage = json_tokener_parse(payload);
  14161. if(!is_error(ExtendedTriggerMessage))
  14162. {
  14163. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14164. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14165. {
  14166. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14167. }
  14168. else
  14169. {
  14170. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14171. }
  14172. }
  14173. json_object_put(ExtendedTriggerMessage);
  14174. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14175. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14176. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14177. {
  14178. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14179. }
  14180. else
  14181. {
  14182. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14183. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14184. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14185. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14186. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14187. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14188. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14189. {
  14190. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14191. }
  14192. else
  14193. {
  14194. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14195. }
  14196. }
  14197. sendExtendedTriggerMessageConfirmation(uuid);
  14198. //==========================
  14199. // Trigger message
  14200. //==========================
  14201. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14202. {
  14203. //sendBootNotificationRequest();
  14204. server_sign = FALSE;
  14205. }
  14206. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14207. {
  14208. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14209. }
  14210. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14211. {
  14212. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14213. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14214. {
  14215. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14216. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14217. }
  14218. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14219. }
  14220. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14221. {
  14222. refreshStartTimer(&clientTime.Heartbeat);
  14223. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14224. }
  14225. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14226. {
  14227. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14228. {
  14229. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14230. }
  14231. else
  14232. {
  14233. for(int idx=0;idx< gunTotalNumber;idx++)
  14234. {
  14235. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14236. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14237. }
  14238. }
  14239. }
  14240. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14241. {
  14242. char cmdBuf[1024]={0};
  14243. 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);
  14244. system(cmdBuf);
  14245. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14246. }
  14247. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14248. {
  14249. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14250. {
  14251. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14252. }
  14253. else
  14254. {
  14255. for(int idx=0;idx< gunTotalNumber;idx++)
  14256. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14257. }
  14258. }
  14259. return result;
  14260. }
  14261. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14262. {
  14263. mtrace();
  14264. int result = PASS;
  14265. json_object *GetInstalledCertificateIds;
  14266. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14267. GetInstalledCertificateIds = json_tokener_parse(payload);
  14268. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14269. if(!is_error(GetInstalledCertificateIds))
  14270. {
  14271. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14272. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14273. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14274. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  14275. // Check CentralSystemRootCertificate
  14276. if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL)
  14277. {
  14278. if(access(ROOTCA_CS,F_OK) != -1)
  14279. {
  14280. char parseData[512] = {0};
  14281. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14282. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14283. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  14284. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14285. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14286. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14287. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14288. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14289. }
  14290. else
  14291. {
  14292. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  14293. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14294. }
  14295. }
  14296. // Check ManufacturerRootCertificate
  14297. else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
  14298. {
  14299. if(access(ROOTCA_MF,F_OK) != -1)
  14300. {
  14301. char parseData[512] = {0};
  14302. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14303. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14304. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  14305. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14306. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14307. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14308. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14309. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14310. }
  14311. else
  14312. {
  14313. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  14314. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14315. }
  14316. }
  14317. else
  14318. {
  14319. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14320. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14321. }
  14322. }
  14323. json_object_put(GetInstalledCertificateIds);
  14324. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14325. sendGetInstalledCertificateIdsConfirmation(uuid);
  14326. return result;
  14327. }
  14328. void* GetLogProcess(void* data)
  14329. {
  14330. pthread_detach(pthread_self());
  14331. mtrace();
  14332. 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};
  14333. int port=0;
  14334. int isSuccess = FALSE;
  14335. char cmdBuf[2048];
  14336. struct tm *tmNow;
  14337. time_t CurrentTime;
  14338. struct tm tmStart;
  14339. struct tm tmStop;
  14340. CurrentTime = time(NULL);
  14341. tmNow=localtime(&CurrentTime);
  14342. uint16_t targetYear, targetMonth;
  14343. json_object *GetLog;
  14344. DEBUG_INFO("GetLogProcess...\n");
  14345. GetLog = json_tokener_parse(data);
  14346. if(!is_error(GetLog))
  14347. {
  14348. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14349. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14350. if(json_object_object_get(GetLog, "retries") != NULL)
  14351. {
  14352. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14353. }
  14354. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14355. {
  14356. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14357. }
  14358. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14359. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14360. {
  14361. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14362. }
  14363. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14364. {
  14365. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14366. }
  14367. }
  14368. json_object_put(GetLog);
  14369. // Pack log to compress file
  14370. 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) &&
  14371. (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))
  14372. {
  14373. // Pack system log
  14374. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14375. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14376. targetYear = tmStart.tm_year;
  14377. targetMonth = tmStart.tm_mon;
  14378. do
  14379. {
  14380. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14381. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14382. if(targetMonth+1>=13)
  14383. {
  14384. targetYear += 1;
  14385. targetMonth = 1;
  14386. }
  14387. else
  14388. {
  14389. targetMonth += 1;
  14390. }
  14391. }while((targetYear < (tmNow->tm_year+1900)) ||
  14392. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14393. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14394. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14395. system(cmdBuf);
  14396. // Pack charging & event log
  14397. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14398. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14399. targetYear = tmStart.tm_year;
  14400. targetMonth = tmStart.tm_mon;
  14401. do
  14402. {
  14403. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14404. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14405. if(targetMonth+1>=13)
  14406. {
  14407. targetYear += 1;
  14408. targetMonth = 1;
  14409. }
  14410. else
  14411. {
  14412. targetMonth += 1;
  14413. }
  14414. }while((targetYear < (tmNow->tm_year+1900)) ||
  14415. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14416. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14417. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14418. system(cmdBuf);
  14419. // Combine log file
  14420. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14421. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14422. }
  14423. else
  14424. {
  14425. system("exec /root/logPackTools 'log' 6");
  14426. }
  14427. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14428. system(cmdBuf);
  14429. checkUploadLog();
  14430. //****************location*******************/
  14431. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14432. {
  14433. DEBUG_INFO("location is <Empty>!\n");
  14434. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14435. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14436. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14437. goto end;
  14438. }
  14439. memset(protocol, 0, ARRAY_SIZE(protocol));
  14440. memset(user, 0, ARRAY_SIZE(user) );
  14441. memset(password, 0, ARRAY_SIZE(password));
  14442. memset(host, 0, ARRAY_SIZE(host));
  14443. memset(path, 0, ARRAY_SIZE(path));
  14444. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14445. memset(host1, 0, ARRAY_SIZE(host1));
  14446. memset(path1, 0, ARRAY_SIZE(path1));
  14447. /*location: ftp://user:password@host:port/path*/
  14448. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14449. if((access(fnamePlusPath,F_OK))!=-1)
  14450. {
  14451. DEBUG_INFO("fnamePlusPath exist.\n");
  14452. }
  14453. else
  14454. {
  14455. DEBUG_INFO("fnamePlusPath not exist!\n");
  14456. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14457. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14458. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14459. goto end;
  14460. }
  14461. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14462. {
  14463. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14464. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14465. protocol, host, &port, path);
  14466. strcpy(user,"anonymous");
  14467. strcpy(password,"");
  14468. }
  14469. else
  14470. {
  14471. //DEBUG_INFO("pch=%s\n", pch);
  14472. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14473. protocol, user, password, host, &port, path);
  14474. }
  14475. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14476. {
  14477. DEBUG_INFO("protocol is not ftp/http ! \n");
  14478. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14479. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14480. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14481. goto end;
  14482. }
  14483. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14484. {
  14485. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14486. sprintf(ftppath,"/%s", path);
  14487. do
  14488. {
  14489. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14490. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14491. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14492. sleep(3);
  14493. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14494. if(!isSuccess)
  14495. {
  14496. DEBUG_INFO("Diagnostics fail.\n");
  14497. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14498. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14499. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14500. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14501. }
  14502. else
  14503. {
  14504. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14505. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14506. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14507. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14508. }
  14509. ShmOCPP16Data->GetLog.retries--;
  14510. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14511. }
  14512. else
  14513. {
  14514. sscanf(host,"%[^/]%s",host1, path1);
  14515. if(strlen(path) > 0)
  14516. sprintf(ftppath,"/%s", path);
  14517. else
  14518. sprintf(ftppath,"/%s", path1);
  14519. int ftppathlen=strlen(ftppath);
  14520. int i=1;
  14521. char filenametemp[50];
  14522. while(i < ftppathlen)
  14523. {
  14524. int len=ftppathlen-i;
  14525. if(ftppath[len]== 47) // '/' ascll code: 47
  14526. {
  14527. DEBUG_INFO("find '/' all right\n");
  14528. break;
  14529. }
  14530. i=i+1;
  14531. }
  14532. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14533. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14534. filenametemp[i+1] = 0;
  14535. if(port == 0)
  14536. port = 21;
  14537. do
  14538. {
  14539. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14540. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14541. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14542. sleep(3);
  14543. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14544. if(!isSuccess)
  14545. {
  14546. DEBUG_INFO("Diagnostics fail.\n");
  14547. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14548. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14549. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14550. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14551. }
  14552. else
  14553. {
  14554. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14555. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14556. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14557. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14558. }
  14559. ShmOCPP16Data->GetLog.retries--;
  14560. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14561. }
  14562. end:
  14563. system("rm -f /mnt/*");
  14564. sleep(5);
  14565. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14566. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14567. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14568. interLock.isGetDiagnosticGoing = 0;
  14569. pthread_exit(NULL);
  14570. }
  14571. int handleGetLogRequest(char *uuid, char *payload)
  14572. {
  14573. mtrace();
  14574. int result = PASS;
  14575. time_t CurrentTime;
  14576. struct tm *tm;
  14577. DEBUG_INFO("handleGetLogRequest...\n");
  14578. pthread_t th_Status;
  14579. CurrentTime = time(NULL);
  14580. tm = localtime(&CurrentTime);
  14581. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14582. 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);
  14583. if(!interLock.isGetDiagnosticGoing)
  14584. {
  14585. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14586. interLock.isGetDiagnosticGoing = 1;
  14587. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14588. sleep(1);
  14589. }
  14590. else
  14591. {
  14592. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14593. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14594. }
  14595. sendGetLogConfirmation(uuid);
  14596. return result;
  14597. }
  14598. int handleInstallCertificateRequest(char *uuid, char *payload)
  14599. {
  14600. mtrace();
  14601. int result = PASS;
  14602. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14603. json_object *InstallCertificate;
  14604. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14605. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14606. InstallCertificate = json_tokener_parse(payload);
  14607. if(!is_error(InstallCertificate))
  14608. {
  14609. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14610. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14611. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14612. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14613. char temp[1024];
  14614. FILE *fp = fopen(tempCert, "w");
  14615. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14616. fclose(fp);
  14617. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14618. char strExpDate[30];
  14619. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14620. fp = popen(temp, "r");
  14621. if(fp)
  14622. {
  14623. while(fgets(temp, sizeof(temp), fp) != NULL)
  14624. {
  14625. if(strstr(temp, "notAfter=") != NULL)
  14626. {
  14627. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14628. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14629. break;
  14630. }
  14631. }
  14632. }
  14633. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14634. struct tm tmExpDate;
  14635. struct timeb tbExpDate;
  14636. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14637. tbExpDate.time = mktime(&tmExpDate);
  14638. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14639. {
  14640. DEBUG_INFO("The enddate is already expired...\n");
  14641. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14642. goto End;
  14643. }
  14644. // Verify certificate with rootCA
  14645. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14646. fp = popen(temp, "r");
  14647. if(fp)
  14648. {
  14649. while(fgets(temp, sizeof(temp), fp) != NULL)
  14650. {
  14651. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14652. {
  14653. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14654. break;
  14655. }
  14656. else
  14657. {
  14658. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14659. }
  14660. }
  14661. }
  14662. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14663. {
  14664. //=====================================================
  14665. // Verify if the certificate is valid or not. (OCSP?)
  14666. //=====================================================
  14667. /*
  14668. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14669. // Get ocsp url
  14670. char ocspUrl[512];
  14671. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14672. fp = popen(temp, "r");
  14673. if(fp)
  14674. {
  14675. while(fgets(temp, sizeof(temp), fp) != NULL)
  14676. {
  14677. if(strstr(temp, "://") != NULL)
  14678. {
  14679. strcpy(ocspUrl, temp);
  14680. break;
  14681. }
  14682. }
  14683. }
  14684. // Get certificate chain for issuer
  14685. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14686. *
  14687. // Execute OCSP
  14688. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14689. fp = popen(temp, "r");
  14690. if(fp)
  14691. {
  14692. while(fgets(temp, sizeof(temp), fp) != NULL)
  14693. {
  14694. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14695. {
  14696. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14697. break;
  14698. }
  14699. }
  14700. }
  14701. system("rm -f /Storage/OCPP/tempChain.pem");
  14702. pclose(fp);
  14703. */
  14704. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14705. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14706. {
  14707. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14708. goto End;
  14709. }
  14710. else
  14711. DEBUG_INFO("OCSP verifying...PASS.\n");
  14712. }
  14713. else
  14714. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14715. }
  14716. End:
  14717. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14718. {
  14719. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14720. {
  14721. if(access(ROOTCA_CS,F_OK) != -1)
  14722. {
  14723. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14724. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14725. rename(tempCert, ROOTCA_CS);
  14726. }
  14727. else
  14728. {
  14729. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14730. rename(tempCert, ROOTCA_CS);
  14731. }
  14732. }
  14733. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14734. {
  14735. if(access(ROOTCA_MF,F_OK) != -1)
  14736. {
  14737. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14738. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14739. rename(tempCert, ROOTCA_MF);
  14740. }
  14741. else
  14742. {
  14743. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14744. rename(tempCert, ROOTCA_MF);
  14745. }
  14746. }
  14747. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14748. }
  14749. sendInstallCertificateConfirmation(uuid);
  14750. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14751. {
  14752. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14753. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14754. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14755. }
  14756. json_object_put(InstallCertificate);
  14757. return result;
  14758. }
  14759. void *SignedUpdateFirmwareProcess(void *data)
  14760. {
  14761. pthread_detach(pthread_self());
  14762. mtrace();
  14763. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14764. int port=0;
  14765. int isSuccess = 0;
  14766. char ftpbuf[1024];
  14767. char temp[1024];
  14768. char * pch;
  14769. char firmwareFileName[50];
  14770. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14771. json_object *SignedUpdateFirmware;
  14772. SignedUpdateFirmware = json_tokener_parse(data);
  14773. if(!is_error(SignedUpdateFirmware))
  14774. {
  14775. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14776. {
  14777. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14778. }
  14779. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14780. {
  14781. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14782. }
  14783. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14784. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14785. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14786. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14787. {
  14788. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14789. }
  14790. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14791. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14792. }
  14793. json_object_put(SignedUpdateFirmware);
  14794. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14795. memset(path, 0, ARRAY_SIZE(path));
  14796. // Wait retrieveData
  14797. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14798. {
  14799. do
  14800. {
  14801. sleep(1);
  14802. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14803. }
  14804. // Ready to download
  14805. system("rm -f /mnt/*");
  14806. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14807. {
  14808. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14809. sprintf(ftppath,"/%s", path);
  14810. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14811. DEBUG_INFO("protocol: %s\n",protocol);
  14812. DEBUG_INFO("host: %s\n",host);
  14813. DEBUG_INFO("path: %s\n",path);
  14814. DEBUG_INFO("ftppath: %s\n",ftppath);
  14815. int ftppathlen=strlen(ftppath);
  14816. int i=1;
  14817. while(i < ftppathlen)
  14818. {
  14819. int len=ftppathlen-i;
  14820. if(ftppath[len]== 47) // '/' ascll code: 47
  14821. {
  14822. DEBUG_INFO("compare '/' all right\n");
  14823. break;
  14824. }
  14825. i=i+1;
  14826. }
  14827. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14828. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14829. firmwareFileName[i+1] = 0;
  14830. do
  14831. {
  14832. sleep(1);
  14833. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14834. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14835. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14836. sleep(1);
  14837. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14838. if(!isSuccess)
  14839. {
  14840. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14841. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14842. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14843. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14844. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14845. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14846. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14847. }
  14848. else
  14849. {
  14850. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14851. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14852. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14853. }
  14854. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14855. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14856. }
  14857. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14858. {
  14859. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14860. memset(temp, 0, ARRAY_SIZE(temp));
  14861. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14862. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14863. int ftppathlen=strlen(ftpbuf);
  14864. int i=1;
  14865. while(i < ftppathlen)
  14866. {
  14867. int len=ftppathlen-i;
  14868. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14869. {
  14870. DEBUG_INFO(" compare '/' all right\n");
  14871. break;
  14872. }
  14873. i=i+1;
  14874. }
  14875. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14876. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14877. firmwareFileName[i+1] = 0;
  14878. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14879. pch=strchr(temp,'@');
  14880. if(pch==NULL)
  14881. {
  14882. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14883. protocol, host, &port, path);
  14884. strcpy(user,"anonymous");
  14885. strcpy(password,"");
  14886. }
  14887. else
  14888. {
  14889. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14890. protocol, user, host, &port, path);
  14891. }
  14892. sscanf(host,"%[^/]%s",host1, path1);
  14893. sprintf(ftppath,"%s:/%s", host,path);
  14894. if(port == 0)
  14895. {
  14896. port = 21;
  14897. }
  14898. do
  14899. {
  14900. sleep(1);
  14901. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14902. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14903. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14904. sleep(1);
  14905. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14906. if(!isSuccess)
  14907. {
  14908. sleep(1);
  14909. DEBUG_INFO("Update firmware request and download file fail.\n");
  14910. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14911. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14912. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14913. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14914. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14915. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14916. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14917. }
  14918. else
  14919. {
  14920. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14921. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14922. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14923. }
  14924. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14925. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14926. }
  14927. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14928. {
  14929. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14930. memset(temp, 0, ARRAY_SIZE(temp));
  14931. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14932. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14933. int ftppathlen=strlen(ftpbuf);
  14934. int i=1;
  14935. while(i < ftppathlen)
  14936. {
  14937. int len=ftppathlen-i;
  14938. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14939. {
  14940. DEBUG_INFO(" compare '/' all right\n");
  14941. break;
  14942. }
  14943. i=i+1;
  14944. }
  14945. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14946. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14947. firmwareFileName[i+1] = 0;
  14948. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14949. pch=strchr(temp,'@');
  14950. if(pch==NULL)
  14951. {
  14952. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14953. protocol, host, &port, path);
  14954. strcpy(user,"anonymous");
  14955. strcpy(password,"");
  14956. }
  14957. else
  14958. {
  14959. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14960. protocol, user, password, host, &port, path);
  14961. }
  14962. sscanf(host,"%[^/]%s",host1, path1);
  14963. sprintf(ftppath,"%s", path1);
  14964. //DEBUG_INFO("protocol =%s\n",protocol);
  14965. //DEBUG_INFO("user =%s\n",user);
  14966. //DEBUG_INFO("password =%s\n",password);
  14967. //DEBUG_INFO("host1 =%s\n",host1);
  14968. //DEBUG_INFO("port =%d\n",port);
  14969. //DEBUG_INFO("path1 =%s\n",path1);
  14970. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14971. //ftpFile(host, user, password, port, ftppath, fname);
  14972. //download firmware pthred
  14973. if(port == 0)
  14974. {
  14975. port = 21;
  14976. }
  14977. do
  14978. {
  14979. sleep(1);
  14980. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14981. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14982. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14983. sleep(1);
  14984. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14985. if(!isSuccess)
  14986. {
  14987. //BulldogUtil.sleepMs(interval*1000);
  14988. DEBUG_INFO("Update firmware request and download file fail.\n");
  14989. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14990. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14991. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14992. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14993. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14994. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14995. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14996. }
  14997. else
  14998. {
  14999. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15000. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15001. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15002. }
  15003. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15004. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15005. }
  15006. else
  15007. {
  15008. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15009. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15010. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15011. sleep(1);
  15012. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15013. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15014. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15015. }
  15016. // Verify firmware image signature
  15017. struct stat st;
  15018. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15019. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15020. fclose(fp);
  15021. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15022. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15023. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15024. fclose(fp);
  15025. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15026. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15027. if(st.st_size == 0)
  15028. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15029. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15030. {
  15031. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15032. fp = popen(temp, "r");
  15033. if(fp)
  15034. {
  15035. while(fgets(temp, sizeof(temp), fp) != NULL)
  15036. {
  15037. if(strstr(temp, "Verified OK") != NULL)
  15038. {
  15039. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15040. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15041. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15042. }
  15043. else
  15044. {
  15045. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15046. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15047. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15048. sleep(1);
  15049. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15050. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15051. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15052. sleep(1);
  15053. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15054. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15055. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15056. }
  15057. break;
  15058. }
  15059. }
  15060. pclose(fp);
  15061. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15062. }
  15063. interLock.isUpdateFirmwareGoing = 0;
  15064. pthread_exit(NULL);
  15065. }
  15066. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15067. {
  15068. mtrace();
  15069. int result = PASS;
  15070. pthread_t t;
  15071. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15072. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15073. sendSignedUpdateFirmwareConfirmation(uuid);
  15074. if(!interLock.isUpdateFirmwareGoing)
  15075. {
  15076. interLock.isUpdateFirmwareGoing = 1;
  15077. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15078. sleep(1);
  15079. }
  15080. else
  15081. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15082. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15083. return result;
  15084. }
  15085. int handleUnknownRequest(char *uuid, char *payload)
  15086. {
  15087. mtrace();
  15088. int result = PASS;
  15089. DEBUG_INFO("handleUnknownRequest...\n");
  15090. sendUnknownConfirmation(uuid);
  15091. return result;
  15092. }
  15093. //==========================================
  15094. // Handle server response routine
  15095. //==========================================
  15096. void handleAuthorizeResponse(char *payload, int gun_index)
  15097. {
  15098. mtrace();
  15099. char expiryDatestr[36]={0};
  15100. char parentIdTagstr[21]={0};
  15101. char statusstr[20]={0};
  15102. int expiryDateISNULL=FALSE;
  15103. int parentIdTagISNULL=FALSE;
  15104. DEBUG_INFO("handleAuthorizeResponse...\n");
  15105. json_object *Authorize;
  15106. Authorize = json_tokener_parse(payload);
  15107. if(!is_error(Authorize))
  15108. {
  15109. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15110. {
  15111. // Required data
  15112. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15113. // Optional data
  15114. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15115. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15116. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15117. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15118. }
  15119. }
  15120. json_object_put(Authorize);
  15121. if(expiryDateISNULL == FALSE)
  15122. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15123. if(parentIdTagISNULL == FALSE)
  15124. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15125. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15126. //Update idTag information to authorization cache if supproted
  15127. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15128. {
  15129. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15130. }
  15131. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15132. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15133. authorizeRetryTimes = 0;
  15134. }
  15135. void handleBootNotificationResponse(char *payload, int gun_index)
  15136. {
  15137. mtrace();
  15138. char statusStr[12]={0};
  15139. char currentTimeStr[30]={0};
  15140. int intervalInt = 0;
  15141. DEBUG_INFO("handleBootNotificationResponse...\n");
  15142. json_object *BootNotification;
  15143. BootNotification = json_tokener_parse(payload);
  15144. if(!is_error(BootNotification))
  15145. {
  15146. // Required data
  15147. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15148. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15149. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15150. }
  15151. json_object_put(BootNotification);
  15152. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15153. BootNotificationInterval = intervalInt;
  15154. //write back to ShmOCPP16Data->BootNotification
  15155. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15156. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15157. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15158. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15159. {
  15160. BootNotificationInterval = 0;
  15161. if((intervalInt == 0) || (intervalInt >= 10))
  15162. {
  15163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15164. HeartBeatWaitTime = intervalInt;
  15165. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15166. }
  15167. server_sign = TRUE;
  15168. server_pending =FALSE;
  15169. }
  15170. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15171. {
  15172. server_pending = TRUE;
  15173. }
  15174. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15175. srand(time(NULL));
  15176. refreshStartTimer(&clientTime.Heartbeat);
  15177. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15178. SetOcppConnStatus(TRUE);
  15179. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15180. }
  15181. void handleDataTransferResponse(char *payload, int gun_index)
  15182. {
  15183. json_object *DataTransfer = json_tokener_parse(payload);
  15184. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15185. if(!is_error(DataTransfer))
  15186. {
  15187. // Required data
  15188. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15189. // Optional data
  15190. if(json_object_object_get(DataTransfer, "data") != NULL)
  15191. {
  15192. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15193. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15194. if(!is_error(Data))
  15195. {
  15196. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15197. {
  15198. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15199. {
  15200. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15201. }
  15202. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15203. {
  15204. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15205. {
  15206. 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")));
  15207. }
  15208. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15209. {
  15210. 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")));
  15211. }
  15212. }
  15213. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15214. }
  15215. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15216. {
  15217. if(json_object_object_get(Data, "status") != NULL)
  15218. {
  15219. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15220. }
  15221. if(json_object_object_get(Data, "exiResponse") != NULL)
  15222. {
  15223. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15224. }
  15225. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15226. }
  15227. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15228. {
  15229. if(json_object_object_get(Data, "status") != NULL)
  15230. {
  15231. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15232. }
  15233. if(json_object_object_get(Data, "ocspResult") != NULL)
  15234. {
  15235. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15236. }
  15237. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15238. }
  15239. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15240. {
  15241. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15242. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15243. }
  15244. else
  15245. {
  15246. if(json_object_object_get(Data, "msgId") != NULL)
  15247. {
  15248. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15249. {
  15250. 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")));
  15251. }
  15252. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15253. {
  15254. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15255. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15256. }
  15257. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyFeeAct") != NULL)
  15258. {
  15259. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15260. {
  15261. 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")));
  15262. if(json_object_object_get(Data, "occupancySN") != NULL)
  15263. 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")));
  15264. if(json_object_object_get(Data, "startTime") != NULL)
  15265. 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")));
  15266. if(json_object_object_get(Data, "duration") != NULL)
  15267. 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"));
  15268. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15269. 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"));
  15270. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].OccupancyFeeActReq = 0;
  15271. }
  15272. else
  15273. {
  15274. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15275. {
  15276. if(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq)
  15277. {
  15278. strcpy((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].response_status, "Rejected");
  15279. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq = 0;
  15280. }
  15281. }
  15282. }
  15283. }
  15284. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15285. {
  15286. if(json_object_object_get(Data, "occupancySN") != NULL)
  15287. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15288. }
  15289. }
  15290. }
  15291. }
  15292. json_object_put(Data);
  15293. }
  15294. }
  15295. json_object_put(DataTransfer);
  15296. }
  15297. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15298. {
  15299. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15300. //struct json_object *obj;
  15301. // obj = json_tokener_parse(payload);
  15302. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15303. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15304. //No fields are defined.
  15305. }
  15306. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15307. {
  15308. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15309. //struct json_object *obj;
  15310. // obj = json_tokener_parse(payload);
  15311. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15312. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15313. //No fields are defined.
  15314. }
  15315. void handleHeartbeatResponse(char *payload, int gun_index)
  15316. {
  15317. mtrace();
  15318. DEBUG_INFO("handleHeartbeatResponse...\n");
  15319. json_object *Heartbeat;
  15320. Heartbeat = json_tokener_parse(payload);
  15321. if(!is_error(Heartbeat))
  15322. {
  15323. // Required data
  15324. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15325. }
  15326. json_object_put(Heartbeat);
  15327. if(FirstHeartBeat == 0)
  15328. {
  15329. FirstHeartBeat = 1;
  15330. DEBUG_INFO("FirstHeartBeat \n");
  15331. }
  15332. HeartBeatWithNOResponse = 0;
  15333. refreshStartTimer(&clientTime.Heartbeat);
  15334. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15335. }
  15336. void handleMeterValuesResponse(char *payload, int gun_index)
  15337. {
  15338. mtrace();
  15339. DEBUG_INFO("handleMeterValuesResponse...\n");
  15340. isQueueSendable = 1;
  15341. }
  15342. void handleStartTransactionResponse(char *payload, int gun_index)
  15343. {
  15344. mtrace();
  15345. //int transactionIdInt = 0;
  15346. FILE *outfile;
  15347. char data[100]={0};
  15348. DEBUG_INFO("handleStartTransactionResponse...\n");
  15349. json_object *StartTransaction;
  15350. StartTransaction = json_tokener_parse(payload);
  15351. if(!is_error(StartTransaction))
  15352. {
  15353. // Required data
  15354. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15355. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15356. // Optional data
  15357. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15358. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15359. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15360. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15361. }
  15362. json_object_put(StartTransaction);
  15363. OCPP_updatePeriodEnergy(gun_index);
  15364. //-----------Start : write to the Queue TransactionId file -----------------//
  15365. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15366. {}
  15367. else
  15368. {
  15369. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15370. if(log == NULL)
  15371. {
  15372. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15373. return ;
  15374. }
  15375. else
  15376. {
  15377. fclose(log);
  15378. }
  15379. }
  15380. // open file for writing
  15381. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15382. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15383. {
  15384. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15385. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15386. fputs(data, outfile);
  15387. fclose (outfile);
  15388. DEBUG_INFO("Update QueueTransactionId done...\n");
  15389. }
  15390. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15391. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15392. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15393. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15394. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15395. isQueueSendable = 1;
  15396. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15397. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15398. }
  15399. void handleStatusNotificationResponse(char *payload, int gun_index)
  15400. {
  15401. mtrace();
  15402. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15403. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15404. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15405. if(gun_index != 99)
  15406. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15407. }
  15408. void handleStopTransactionnResponse(char *payload, int gun_index)
  15409. {
  15410. mtrace();
  15411. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15412. json_object *StopTransaction;
  15413. StopTransaction = json_tokener_parse(payload);
  15414. if(!is_error(StopTransaction))
  15415. {
  15416. // Optional data
  15417. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15418. {
  15419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15420. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15421. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15422. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15423. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15424. }
  15425. }
  15426. json_object_put(StopTransaction);
  15427. isQueueSendable = 1;
  15428. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15429. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15430. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15431. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15432. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15433. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15434. }
  15435. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15436. {
  15437. mtrace();
  15438. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15439. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15440. }
  15441. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15442. {
  15443. mtrace();
  15444. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15445. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15446. }
  15447. void handleSignCertificateResponse(char *payload, int gun_index)
  15448. {
  15449. mtrace();
  15450. DEBUG_INFO("handleSignCertificateResponse...\n");
  15451. json_object *SignCertificate;
  15452. SignCertificate = json_tokener_parse(payload);
  15453. if(!is_error(SignCertificate))
  15454. {
  15455. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15456. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15457. }
  15458. json_object_put(SignCertificate);
  15459. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15460. }
  15461. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15462. {
  15463. mtrace();
  15464. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15465. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15466. }
  15467. //==========================================
  15468. // Handle Error routine
  15469. //==========================================
  15470. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15471. {
  15472. mtrace();
  15473. #ifdef SystemLogMessage
  15474. DEBUG_INFO("errorCode: %s\n", errorCode);
  15475. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15476. DEBUG_INFO("errorDetails: %s\n", payload);
  15477. #endif
  15478. }
  15479. //===============================================
  15480. // Common routine
  15481. //===============================================
  15482. int initialConfigurationTable(void)
  15483. {
  15484. //clock_t start_t, end_t, total_t;
  15485. FILE *fp;
  15486. FILE *outfile;
  15487. char str[512]={0};
  15488. char sstr[256]={0};
  15489. int c = 0;
  15490. char *loc;
  15491. int confVersion = 23;
  15492. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15493. //start_t = clock();
  15494. //printf("Starting of the program, start_t = %ld\n", start_t);
  15495. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15496. // Check configuration file size is correct
  15497. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15498. {
  15499. struct stat st;
  15500. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15501. if(st.st_size < 3100)
  15502. {
  15503. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15504. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15505. }
  15506. }
  15507. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15508. {
  15509. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15510. if(outfile == NULL)
  15511. {
  15512. DEBUG_INFO("Error opening file\n");
  15513. return FALSE;
  15514. }
  15515. /*Core Profile*/
  15516. //AllowOfflineTxForUnknownId
  15517. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15521. //AuthorizationCacheEnabled
  15522. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15526. //AuthorizeRemoteTxRequests
  15527. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15531. //BlinkRepeat
  15532. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15536. //ClockAlignedDataInterval
  15537. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15541. //ConnectionTimeOut
  15542. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15544. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15546. else
  15547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15549. //GetConfigurationMaxKeys
  15550. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15554. // HeartbeatInterval
  15555. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15559. // LightIntensity
  15560. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15564. // LocalAuthorizeOffline
  15565. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15569. // LocalPreAuthorize
  15570. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15574. // MaxEnergyOnInvalidId
  15575. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15579. // MeterValuesAlignedData
  15580. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15582. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15583. 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" );
  15584. else
  15585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15587. // MeterValuesAlignedDataMaxLength
  15588. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15592. else
  15593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15595. // MeterValuesSampledData
  15596. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15598. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15599. 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" );
  15600. else
  15601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15603. // MeterValuesSampledDataMaxLength
  15604. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15606. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15608. else
  15609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15611. // MeterValueSampleInterval
  15612. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15616. // MinimumStatusDuration
  15617. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15620. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15622. // NumberOfConnectors
  15623. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15626. {
  15627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15628. }
  15629. else
  15630. {
  15631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15632. }
  15633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15634. // ResetRetries
  15635. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15639. // ConnectorPhaseRotation
  15640. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15644. // ConnectorPhaseRotationMaxLength
  15645. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15649. // StopTransactionOnEVSideDisconnect
  15650. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15654. // StopTransactionOnInvalidId
  15655. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15659. // StopTxnAlignedData
  15660. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15664. // StopTxnAlignedDataMaxLength
  15665. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15667. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15668. {
  15669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 8);
  15670. }
  15671. else
  15672. {
  15673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 10);
  15674. }
  15675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15676. // StopTxnSampledData
  15677. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15681. // StopTxnSampledDataMaxLength
  15682. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15684. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15685. {
  15686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 8);
  15687. }
  15688. else
  15689. {
  15690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 10);
  15691. }
  15692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15693. // SupportedFeatureProfiles
  15694. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15698. // SupportedFeatureProfilesMaxLength
  15699. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15703. // TransactionMessageAttempts
  15704. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15707. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15709. // TransactionMessageRetryInterval
  15710. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15713. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15715. // UnlockConnectorOnEVSideDisconnect
  15716. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15720. // WebSocketPingInterval
  15721. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15725. // QueueOffLineMeterValues
  15726. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15730. // AuthorizationKey
  15731. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15735. // SecurityProfile
  15736. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15740. // DefaultPrice
  15741. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15745. // CustomDisplayCostAndPrice
  15746. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15750. // CustomIdleFeeAfterStop
  15751. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15755. // TimeOffset
  15756. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15760. // NextTimeOffsetTransitionDateTime
  15761. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15765. // TimeOffsetNextTransition
  15766. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15770. // SystemUptimeSec
  15771. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15775. // FreeVend
  15776. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15780. // FreeVendIdtag
  15781. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15785. // OcppServer
  15786. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15788. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15790. // MaintainServer
  15791. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15793. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15795. // StatusNotificationPeriodically
  15796. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15800. // StatusNotificationInterval
  15801. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15805. // PreAuthAmount
  15806. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15810. // isEnableLocalPowerSharing
  15811. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15815. // PowerSharingServerIP
  15816. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15818. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15820. // EVCCID_PREFIX
  15821. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15825. // OffLineMaxChargingPower
  15826. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15830. // Configuration Version
  15831. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15835. // Charging profile refresh interval
  15836. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15840. // CpoName
  15841. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15845. // Ocpp Software certificated version
  15846. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15850. //* Local Auth List Management Profile*/
  15851. #if 0
  15852. //For OCTT Test Case
  15853. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15856. #endif
  15857. #if 1
  15858. //LocalAuthListEnabled
  15859. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15863. #endif
  15864. //LocalAuthListMaxLength
  15865. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15869. //SendLocalListMaxLength
  15870. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15874. //ReserveConnectorZeroSupported
  15875. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15879. //* Smart Charging Profile */
  15880. //ChargeProfileMaxStackLevel
  15881. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15885. // ChargingScheduleAllowedChargingRateUnit
  15886. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15890. // ChargingScheduleMaxPeriods
  15891. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15895. // ConnectorSwitch3to1PhaseSupported
  15896. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15900. // MaxChargingProfilesInstalled
  15901. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15905. fclose(outfile);
  15906. }
  15907. else
  15908. {
  15909. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15910. char keystr[60]={0};
  15911. char readonlystr[10]={0};
  15912. char valuestr[256]={0};
  15913. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15914. if(fp == NULL) {
  15915. DEBUG_INFO("Error opening file");
  15916. return FALSE;
  15917. }
  15918. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15919. {
  15920. //DEBUG_INFO("Get Configuration \n");
  15921. if(strlen(str) > 0)
  15922. {
  15923. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15924. //*************************key*********************************/
  15925. if(strstr(str, "key") != NULL)
  15926. {
  15927. loc = strstr(str, "key");
  15928. c = 0;
  15929. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15930. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15931. {
  15932. sstr[c] = loc[strlen("key")+3+c];
  15933. c++;
  15934. }
  15935. sstr[c] = '\0';
  15936. strcpy(keystr,sstr);
  15937. }
  15938. //*************************readonly*********************************/
  15939. if(strstr(str, "readonly") != NULL)
  15940. {
  15941. loc = strstr(str, "readonly");
  15942. c = 0;
  15943. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15944. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  15945. {
  15946. sstr[c] = loc[strlen("readonly")+2+c];
  15947. c++;
  15948. }
  15949. sstr[c] = '\0';
  15950. strcpy(readonlystr,sstr);
  15951. }
  15952. //*************************value*********************************/
  15953. if(strstr(str, "value") != NULL)
  15954. {
  15955. loc = strstr(str, "value");
  15956. c = 0;
  15957. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15958. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15959. {
  15960. sstr[c] = loc[strlen("value")+3+c];
  15961. c++;
  15962. }
  15963. sstr[c] = '\0';
  15964. strcpy(valuestr,sstr);
  15965. }
  15966. // DEBUG_INFO("keystr=%s\n",keystr);
  15967. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15968. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15969. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15970. {
  15971. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15972. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15974. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15975. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15976. }
  15977. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15978. {
  15979. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15980. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  15982. }
  15983. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  15984. {
  15985. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  15987. }
  15988. if(strcmp(keystr, "BlinkRepeat") == 0)
  15989. {
  15990. //Charger.BlinkRepeat = Integer.parseInt(value);
  15991. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  15993. }
  15994. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  15995. {
  15996. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  15998. }
  15999. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16000. {
  16001. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16003. }
  16004. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16005. {
  16006. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16008. }
  16009. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16010. {
  16011. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16013. HeartBeatWaitTime = atoi(valuestr);
  16014. }
  16015. if(strcmp(keystr, "LightIntensity") == 0)
  16016. {
  16017. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16019. }
  16020. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16021. {
  16022. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16024. }
  16025. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16026. {
  16027. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16029. }
  16030. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16031. {
  16032. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16034. }
  16035. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16036. {
  16037. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16039. }
  16040. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16041. {
  16042. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16044. }
  16045. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16046. {
  16047. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16049. }
  16050. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16051. {
  16052. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16054. }
  16055. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16056. {
  16057. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16059. }
  16060. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16061. {
  16062. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16064. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16065. }
  16066. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16067. {
  16068. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16070. }
  16071. if(strcmp(keystr, "ResetRetries") == 0)
  16072. {
  16073. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16075. }
  16076. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16077. {
  16078. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16080. }
  16081. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16082. {
  16083. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16085. }
  16086. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16087. {
  16088. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16090. }
  16091. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16092. {
  16093. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16095. }
  16096. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16097. {
  16098. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16100. }
  16101. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16102. {
  16103. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16105. }
  16106. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16107. {
  16108. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16110. }
  16111. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16112. {
  16113. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16115. }
  16116. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16117. {
  16118. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16120. }
  16121. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16122. {
  16123. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16125. }
  16126. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16127. {
  16128. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16130. TransactionMessageAttemptsValue = atoi(valuestr);
  16131. }
  16132. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16133. {
  16134. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16136. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16137. }
  16138. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16139. {
  16140. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16142. }
  16143. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16144. {
  16145. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16147. }
  16148. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16149. {
  16150. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16152. }
  16153. if(strcmp(keystr, "AuthorizationKey") == 0)
  16154. {
  16155. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16156. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16158. }
  16159. if(strcmp(keystr, "SecurityProfile") == 0)
  16160. {
  16161. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16163. }
  16164. if(strcmp(keystr, "DefaultPrice") == 0)
  16165. {
  16166. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16168. }
  16169. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16170. {
  16171. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16173. }
  16174. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16175. {
  16176. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16178. }
  16179. if(strcmp(keystr, "TimeOffset") == 0)
  16180. {
  16181. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16183. }
  16184. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16185. {
  16186. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16188. }
  16189. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16190. {
  16191. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16193. }
  16194. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16195. {
  16196. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16198. }
  16199. if(strcmp(keystr, "FreeVend") == 0)
  16200. {
  16201. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16203. }
  16204. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16205. {
  16206. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16208. }
  16209. if(strcmp(keystr, "OcppServer") == 0)
  16210. {
  16211. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16212. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16213. }
  16214. if(strcmp(keystr, "MaintainServer") == 0)
  16215. {
  16216. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16217. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16218. }
  16219. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16220. {
  16221. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16223. }
  16224. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16225. {
  16226. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16228. }
  16229. if(strcmp(keystr, "PreAuthAmount") == 0)
  16230. {
  16231. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16233. }
  16234. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16235. {
  16236. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16238. }
  16239. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16240. {
  16241. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16242. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16243. }
  16244. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16245. {
  16246. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16248. }
  16249. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16250. {
  16251. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16253. }
  16254. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16255. {
  16256. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16258. }
  16259. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16260. {
  16261. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16263. }
  16264. if(strcmp(keystr, "CpoName") == 0)
  16265. {
  16266. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16268. }
  16269. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16270. {
  16271. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16273. }
  16274. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16275. {
  16276. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16278. }
  16279. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16280. {
  16281. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16283. }
  16284. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16285. {
  16286. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16288. }
  16289. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16290. {
  16291. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16293. }
  16294. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16295. {
  16296. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16298. }
  16299. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16300. {
  16301. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16303. }
  16304. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16305. {
  16306. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16308. }
  16309. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16310. {
  16311. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16313. }
  16314. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16315. {
  16316. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16318. }
  16319. }
  16320. }
  16321. fclose(fp);
  16322. }
  16323. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16324. {
  16325. return PASS;
  16326. }
  16327. else
  16328. {
  16329. return FAIL;
  16330. }
  16331. }
  16332. void StoreConfigurationTable(void)
  16333. {
  16334. FILE *outfile;
  16335. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16336. if(outfile == NULL)
  16337. {
  16338. DEBUG_INFO("Error opening file");
  16339. return ;
  16340. }
  16341. /*Core Profile*/
  16342. //AllowOfflineTxForUnknownId
  16343. /*
  16344. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16345. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16348. */
  16349. //DEBUG_INFO("data=%s\n",data);
  16350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16351. //AuthorizationCacheEnabled
  16352. /*
  16353. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16356. */
  16357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16358. //AuthorizeRemoteTxRequests
  16359. /*
  16360. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16363. */
  16364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16365. //BlinkRepeat
  16366. /*
  16367. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16370. */
  16371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16372. //ClockAlignedDataInterval
  16373. /*
  16374. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16377. */
  16378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16379. //ConnectionTimeOut
  16380. /*
  16381. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16384. */
  16385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16386. //GetConfigurationMaxKeys
  16387. /*
  16388. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16391. */
  16392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16393. // HeartbeatInterval
  16394. /*
  16395. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16398. */
  16399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16400. // LightIntensity
  16401. /*
  16402. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16405. */
  16406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16407. // LocalAuthorizeOffline
  16408. /*
  16409. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16412. */
  16413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16414. // LocalPreAuthorize
  16415. /*
  16416. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16419. */
  16420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16421. // MaxEnergyOnInvalidId
  16422. /*
  16423. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16426. */
  16427. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16429. // MeterValuesAlignedData
  16430. /*
  16431. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16434. */
  16435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16436. // MeterValuesAlignedDataMaxLength
  16437. /*
  16438. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16441. */
  16442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16443. // MeterValuesSampledData
  16444. /*
  16445. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16448. */
  16449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16450. // MeterValuesSampledDataMaxLength
  16451. /*
  16452. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16455. */
  16456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16457. // MeterValueSampleInterval
  16458. /*
  16459. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16462. */
  16463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16464. // MinimumStatusDuration
  16465. /*
  16466. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16469. */
  16470. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16471. // NumberOfConnectors
  16472. /*
  16473. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16475. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16476. {
  16477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16478. }
  16479. else
  16480. {
  16481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16482. }
  16483. */
  16484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16485. // ResetRetries
  16486. /*
  16487. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16490. */
  16491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16492. // ConnectorPhaseRotation
  16493. /*
  16494. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16497. */
  16498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16499. // ConnectorPhaseRotationMaxLength
  16500. /*
  16501. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16504. */
  16505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16506. // StopTransactionOnEVSideDisconnect
  16507. /*
  16508. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16511. */
  16512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16513. // StopTransactionOnInvalidId
  16514. /*
  16515. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16518. */
  16519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16520. // StopTxnAlignedData
  16521. /*
  16522. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16525. */
  16526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16527. // StopTxnAlignedDataMaxLength
  16528. /*
  16529. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16532. */
  16533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16534. // StopTxnSampledData
  16535. /*
  16536. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16539. */
  16540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16541. // StopTxnSampledDataMaxLength
  16542. /*
  16543. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16546. */
  16547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16548. // SupportedFeatureProfiles
  16549. /*
  16550. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16553. */
  16554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16555. // SupportedFeatureProfilesMaxLength
  16556. /*
  16557. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16560. */
  16561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16562. // TransactionMessageAttempts
  16563. /*
  16564. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16567. */
  16568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16569. // TransactionMessageRetryInterval
  16570. /*
  16571. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16574. */
  16575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16576. // UnlockConnectorOnEVSideDisconnect
  16577. /*
  16578. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16581. */
  16582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16583. // WebSocketPingInterval
  16584. /*
  16585. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16588. */
  16589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16590. // QueueOffLineMeterValues
  16591. /*
  16592. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16595. */
  16596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16597. // AuthorizationKey
  16598. /*
  16599. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16602. */
  16603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16604. // SecurityProfile
  16605. /*
  16606. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16609. */
  16610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16611. // DefaultPrice
  16612. /*
  16613. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16616. */
  16617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16618. // CustomDisplayCostAndPrice
  16619. /*
  16620. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16623. */
  16624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16625. // CustomIdleFeeAfterStop
  16626. /*
  16627. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16630. */
  16631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16632. // TimeOffset
  16633. /*
  16634. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16637. */
  16638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16639. // NextTimeOffsetTransitionDateTime
  16640. /*
  16641. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16644. */
  16645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16646. // TimeOffsetNextTransition
  16647. /*
  16648. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16651. */
  16652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16653. // SystemUptimeSec
  16654. /*
  16655. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16658. */
  16659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16660. // FreeVend
  16661. /*
  16662. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16665. */
  16666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16667. // FreeVendIdtag
  16668. /*
  16669. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16672. */
  16673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16674. // OcppServer
  16675. /*
  16676. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16679. */
  16680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16681. // MaintainServer
  16682. /*
  16683. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16686. */
  16687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16688. // StatusNotificationPeriodically
  16689. /*
  16690. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16693. */
  16694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16695. // StatusNotificationInterval
  16696. /*
  16697. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16700. */
  16701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16702. // PreAuthAmount
  16703. /*
  16704. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16707. */
  16708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16709. // isEnableLocalPowerSharing
  16710. /*
  16711. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16714. */
  16715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16716. // PowerSharingServerIP
  16717. /*
  16718. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16721. */
  16722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16723. // EVCCID_PREFIX
  16724. /*
  16725. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16728. */
  16729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16730. // OffLineMaxChargingPower
  16731. /*
  16732. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16735. */
  16736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16737. // ConfigurationVersion
  16738. /*
  16739. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16742. */
  16743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16744. // CharingProfileRefreshInterval
  16745. /*
  16746. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16749. */
  16750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16751. // CpoName
  16752. /*
  16753. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16756. */
  16757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16758. // OcppSoftwareVersion
  16759. /*
  16760. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16763. */
  16764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16765. //* Local Auth List Management Profile*/
  16766. //LocalAuthListEnabled
  16767. /*
  16768. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16771. */
  16772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16773. //LocalAuthListMaxLength
  16774. /*
  16775. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16778. */
  16779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16780. //SendLocalListMaxLength
  16781. /*
  16782. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16785. */
  16786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16787. //ReserveConnectorZeroSupported
  16788. /*
  16789. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16792. */
  16793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16794. //* Smart Charging Profile */
  16795. //ChargeProfileMaxStackLevel
  16796. /*
  16797. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16800. */
  16801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16802. // ChargingScheduleAllowedChargingRateUnit
  16803. /*
  16804. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16807. */
  16808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16809. // ChargingScheduleMaxPeriods
  16810. /*
  16811. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16814. */
  16815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16816. // ConnectorSwitch3to1PhaseSupported
  16817. /*
  16818. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16821. */
  16822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16823. // MaxChargingProfilesInstalled
  16824. /*
  16825. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16828. */
  16829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16830. fclose(outfile);
  16831. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16832. }
  16833. void getKeyValue(char *keyReq)
  16834. {
  16835. int isEmpty = FALSE;
  16836. int isKnowKey = FALSE;
  16837. DEBUG_INFO("keyReq = %s\n", keyReq);
  16838. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16839. isEmpty = TRUE;
  16840. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16841. {
  16842. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16845. {
  16846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16847. }
  16848. else
  16849. {
  16850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16851. }
  16852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16853. isKnowKey = TRUE;
  16854. }
  16855. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16856. {
  16857. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16860. {
  16861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16862. }
  16863. else
  16864. {
  16865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16866. }
  16867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16868. isKnowKey = TRUE;
  16869. }
  16870. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16871. {
  16872. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16875. {
  16876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16877. }
  16878. else
  16879. {
  16880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16881. }
  16882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16883. isKnowKey = TRUE;
  16884. }
  16885. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16886. {
  16887. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16890. {
  16891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16892. }
  16893. else
  16894. {
  16895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16896. }
  16897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16898. isKnowKey = TRUE;
  16899. }
  16900. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16901. {
  16902. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16905. {
  16906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16907. }
  16908. else
  16909. {
  16910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16911. }
  16912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16913. isKnowKey = TRUE;
  16914. }
  16915. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16916. {
  16917. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16920. {
  16921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  16922. }
  16923. else
  16924. {
  16925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  16926. }
  16927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  16928. isKnowKey = TRUE;
  16929. }
  16930. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  16931. {
  16932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  16933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  16934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16935. {
  16936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  16937. }
  16938. else
  16939. {
  16940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  16941. }
  16942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  16943. isKnowKey = TRUE;
  16944. }
  16945. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  16946. {
  16947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  16948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  16949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16950. {
  16951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  16952. }
  16953. else
  16954. {
  16955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  16956. }
  16957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  16958. isKnowKey = TRUE;
  16959. }
  16960. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  16961. {
  16962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  16963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  16964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16965. {
  16966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  16967. }
  16968. else
  16969. {
  16970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  16971. }
  16972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  16973. isKnowKey = TRUE;
  16974. }
  16975. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  16976. {
  16977. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  16978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  16979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16980. {
  16981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  16982. }
  16983. else
  16984. {
  16985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  16986. }
  16987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  16988. isKnowKey = TRUE;
  16989. }
  16990. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  16991. {
  16992. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  16993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  16994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16995. {
  16996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  16997. }
  16998. else
  16999. {
  17000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17001. }
  17002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17003. isKnowKey = TRUE;
  17004. }
  17005. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17006. {
  17007. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17010. {
  17011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17012. }
  17013. else
  17014. {
  17015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17016. }
  17017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17018. isKnowKey = TRUE;
  17019. }
  17020. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17021. {
  17022. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17025. {
  17026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17027. }
  17028. else
  17029. {
  17030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17031. }
  17032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17033. isKnowKey = TRUE;
  17034. }
  17035. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17036. {
  17037. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17039. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17040. {
  17041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17042. }
  17043. else
  17044. {
  17045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17046. }
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17048. isKnowKey = TRUE;
  17049. }
  17050. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17051. {
  17052. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17055. {
  17056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17057. }
  17058. else
  17059. {
  17060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17061. }
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17063. isKnowKey = TRUE;
  17064. }
  17065. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17066. {
  17067. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17070. {
  17071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17072. }
  17073. else
  17074. {
  17075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17076. }
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17078. isKnowKey = TRUE;
  17079. }
  17080. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17081. {
  17082. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17085. {
  17086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17087. }
  17088. else
  17089. {
  17090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17091. }
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17093. isKnowKey = TRUE;
  17094. }
  17095. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17096. {
  17097. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17100. {
  17101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17102. }
  17103. else
  17104. {
  17105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17106. }
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17108. isKnowKey = TRUE;
  17109. }
  17110. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17111. {
  17112. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17115. {
  17116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17117. }
  17118. else
  17119. {
  17120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17121. }
  17122. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17124. isKnowKey = TRUE;
  17125. }
  17126. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17127. {
  17128. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17131. {
  17132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17133. }
  17134. else
  17135. {
  17136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17137. }
  17138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17139. isKnowKey = TRUE;
  17140. }
  17141. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17142. {
  17143. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17146. {
  17147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17148. }
  17149. else
  17150. {
  17151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17152. }
  17153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17154. isKnowKey = TRUE;
  17155. }
  17156. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17157. {
  17158. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17161. {
  17162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17163. }
  17164. else
  17165. {
  17166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17167. }
  17168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17169. isKnowKey = TRUE;
  17170. }
  17171. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17172. {
  17173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17176. {
  17177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17178. }
  17179. else
  17180. {
  17181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17182. }
  17183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17184. isKnowKey = TRUE;
  17185. }
  17186. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17187. {
  17188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17191. {
  17192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17193. }
  17194. else
  17195. {
  17196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17197. }
  17198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17199. isKnowKey = TRUE;
  17200. }
  17201. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17202. {
  17203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17206. {
  17207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17208. }
  17209. else
  17210. {
  17211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17212. }
  17213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17214. isKnowKey = TRUE;
  17215. }
  17216. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17217. {
  17218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17221. {
  17222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17223. }
  17224. else
  17225. {
  17226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17227. }
  17228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17229. isKnowKey = TRUE;
  17230. }
  17231. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17232. {
  17233. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17236. {
  17237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17238. }
  17239. else
  17240. {
  17241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17242. }
  17243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17244. isKnowKey = TRUE;
  17245. }
  17246. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17247. {
  17248. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17251. {
  17252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17253. }
  17254. else
  17255. {
  17256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17257. }
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17259. isKnowKey = TRUE;
  17260. }
  17261. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17262. {
  17263. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17266. {
  17267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17268. }
  17269. else
  17270. {
  17271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17272. }
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17274. isKnowKey = TRUE;
  17275. }
  17276. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17277. {
  17278. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17281. {
  17282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17283. }
  17284. else
  17285. {
  17286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17287. }
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17289. isKnowKey = TRUE;
  17290. }
  17291. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17292. {
  17293. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17296. {
  17297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17298. }
  17299. else
  17300. {
  17301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17302. }
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17304. isKnowKey = TRUE;
  17305. }
  17306. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17307. {
  17308. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17311. {
  17312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17313. }
  17314. else
  17315. {
  17316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17317. }
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17319. isKnowKey = TRUE;
  17320. }
  17321. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17322. {
  17323. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17326. {
  17327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17328. }
  17329. else
  17330. {
  17331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17332. }
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17334. isKnowKey = TRUE;
  17335. }
  17336. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17337. {
  17338. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17341. {
  17342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17343. }
  17344. else
  17345. {
  17346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17347. }
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17349. isKnowKey = TRUE;
  17350. }
  17351. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17352. {
  17353. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17356. {
  17357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17358. }
  17359. else
  17360. {
  17361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17362. }
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17364. isKnowKey = TRUE;
  17365. }
  17366. /*
  17367. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17368. {
  17369. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17372. {
  17373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17374. }
  17375. else
  17376. {
  17377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17378. }
  17379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17380. isKnowKey = TRUE;
  17381. }*/
  17382. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17383. {
  17384. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17387. {
  17388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17389. }
  17390. else
  17391. {
  17392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17393. }
  17394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17395. isKnowKey = TRUE;
  17396. }
  17397. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17398. {
  17399. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17402. {
  17403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17404. }
  17405. else
  17406. {
  17407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17408. }
  17409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17410. isKnowKey = TRUE;
  17411. }
  17412. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17413. {
  17414. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17417. {
  17418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17419. }
  17420. else
  17421. {
  17422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17423. }
  17424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17425. isKnowKey = TRUE;
  17426. }
  17427. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17428. {
  17429. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17432. {
  17433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17434. }
  17435. else
  17436. {
  17437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17438. }
  17439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17440. isKnowKey = TRUE;
  17441. }
  17442. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17443. {
  17444. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17446. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17447. {
  17448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17449. }
  17450. else
  17451. {
  17452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17453. }
  17454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17455. isKnowKey = TRUE;
  17456. }
  17457. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17458. {
  17459. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17462. {
  17463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17464. }
  17465. else
  17466. {
  17467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17468. }
  17469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17470. isKnowKey = TRUE;
  17471. }
  17472. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17473. {
  17474. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17477. {
  17478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17479. }
  17480. else
  17481. {
  17482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17483. }
  17484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17485. isKnowKey = TRUE;
  17486. }
  17487. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17488. {
  17489. struct sysinfo s_info;
  17490. int error = sysinfo(&s_info);
  17491. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17494. {
  17495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17496. }
  17497. else
  17498. {
  17499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17500. }
  17501. if(error != 0)
  17502. {
  17503. DEBUG_WARN("System uptime get error: %d\n", error);
  17504. }
  17505. else
  17506. {
  17507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17508. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17509. }
  17510. isKnowKey = TRUE;
  17511. }
  17512. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17513. {
  17514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17517. {
  17518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17519. }
  17520. else
  17521. {
  17522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17523. }
  17524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17525. isKnowKey = TRUE;
  17526. }
  17527. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17528. {
  17529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17532. {
  17533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17534. }
  17535. else
  17536. {
  17537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17538. }
  17539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17540. isKnowKey = TRUE;
  17541. }
  17542. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17543. {
  17544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17547. {
  17548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17549. }
  17550. else
  17551. {
  17552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17553. }
  17554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17555. isKnowKey = TRUE;
  17556. }
  17557. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17558. {
  17559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17562. {
  17563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17564. }
  17565. else
  17566. {
  17567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17568. }
  17569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17570. isKnowKey = TRUE;
  17571. }
  17572. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17573. {
  17574. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17577. {
  17578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17579. }
  17580. else
  17581. {
  17582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17583. }
  17584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17585. isKnowKey = TRUE;
  17586. }
  17587. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17588. {
  17589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17592. {
  17593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17594. }
  17595. else
  17596. {
  17597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17598. }
  17599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17600. isKnowKey = TRUE;
  17601. }
  17602. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17603. {
  17604. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17607. {
  17608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17609. }
  17610. else
  17611. {
  17612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17613. }
  17614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17615. isKnowKey = TRUE;
  17616. }
  17617. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17618. {
  17619. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17622. {
  17623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17624. }
  17625. else
  17626. {
  17627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17628. }
  17629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17630. isKnowKey = TRUE;
  17631. }
  17632. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17633. {
  17634. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17637. {
  17638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17639. }
  17640. else
  17641. {
  17642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17643. }
  17644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17645. isKnowKey = TRUE;
  17646. }
  17647. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17648. {
  17649. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17652. {
  17653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17654. }
  17655. else
  17656. {
  17657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17658. }
  17659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17660. isKnowKey = TRUE;
  17661. }
  17662. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17663. {
  17664. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17667. {
  17668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17669. }
  17670. else
  17671. {
  17672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17673. }
  17674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17675. isKnowKey = TRUE;
  17676. }
  17677. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17678. {
  17679. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17682. {
  17683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17684. }
  17685. else
  17686. {
  17687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17688. }
  17689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17690. isKnowKey = TRUE;
  17691. }
  17692. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17693. {
  17694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17697. {
  17698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17699. }
  17700. else
  17701. {
  17702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17703. }
  17704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17705. isKnowKey = TRUE;
  17706. }
  17707. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17708. {
  17709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17712. {
  17713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17714. }
  17715. else
  17716. {
  17717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17718. }
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17720. isKnowKey = TRUE;
  17721. }
  17722. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17723. {
  17724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17727. {
  17728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17729. }
  17730. else
  17731. {
  17732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17733. }
  17734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17735. isKnowKey = TRUE;
  17736. }
  17737. #if 1
  17738. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17739. {
  17740. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17742. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17743. {
  17744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17745. }
  17746. else
  17747. {
  17748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17749. }
  17750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17751. isKnowKey = TRUE;
  17752. }
  17753. #endif
  17754. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17755. {
  17756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17758. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17759. {
  17760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17761. }
  17762. else
  17763. {
  17764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17765. }
  17766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17767. isKnowKey = TRUE;
  17768. }
  17769. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17770. {
  17771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17773. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17774. {
  17775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17776. }
  17777. else
  17778. {
  17779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17780. }
  17781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17782. isKnowKey = TRUE;
  17783. }
  17784. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17785. {
  17786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17788. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17789. {
  17790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17791. }
  17792. else
  17793. {
  17794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17795. }
  17796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17797. isKnowKey = TRUE;
  17798. }
  17799. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17800. {
  17801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17803. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17804. {
  17805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17806. }
  17807. else
  17808. {
  17809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17810. }
  17811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17812. isKnowKey = TRUE;
  17813. }
  17814. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17815. {
  17816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17818. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17819. {
  17820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17821. }
  17822. else
  17823. {
  17824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17825. }
  17826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17827. isKnowKey = TRUE;
  17828. }
  17829. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17830. {
  17831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17833. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17834. {
  17835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17836. }
  17837. else
  17838. {
  17839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17840. }
  17841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17842. isKnowKey = TRUE;
  17843. }
  17844. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17845. {
  17846. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17848. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17849. {
  17850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17851. }
  17852. else
  17853. {
  17854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17855. }
  17856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17857. isKnowKey = TRUE;
  17858. }
  17859. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17860. {
  17861. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17863. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17864. {
  17865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17866. }
  17867. else
  17868. {
  17869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17870. }
  17871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17872. isKnowKey = TRUE;
  17873. }
  17874. //=========================================================
  17875. if(!isEmpty && !isKnowKey)
  17876. {
  17877. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17878. strcpy(unknownkey[UnknownKeynum], keyReq);
  17879. UnknownKeynum = UnknownKeynum + 1;
  17880. }
  17881. }
  17882. void processUnkownKey(void)
  17883. {
  17884. DEBUG_INFO("processUnkownKey...\n");
  17885. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17886. for(int index=0; index < UnknownKeynum; index++)
  17887. {
  17888. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17889. {
  17890. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17891. }
  17892. }
  17893. }
  17894. int setKeyValue(char *key, char *value)
  17895. {
  17896. int isSuccess = NotSupported;
  17897. int check_ascii=0;
  17898. char str[501]={0};
  17899. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17900. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17901. {
  17902. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17904. {
  17905. strcpy(str, (const char*)value);
  17906. for(int i = 0; str[i]; i++){
  17907. str[i] = tolower(str[i]);
  17908. }
  17909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17910. isSuccess = ConfigurationStatus_Accepted;
  17911. }
  17912. else
  17913. {
  17914. isSuccess = ConfigurationStatus_Rejected;
  17915. }
  17916. }
  17917. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  17918. {
  17919. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  17920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17921. {
  17922. strcpy(str, (const char*)value);
  17923. for(int i = 0; str[i]; i++){
  17924. str[i] = tolower(str[i]);
  17925. }
  17926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17927. isSuccess = ConfigurationStatus_Accepted;
  17928. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  17929. }
  17930. else
  17931. {
  17932. isSuccess = ConfigurationStatus_Rejected;
  17933. }
  17934. }
  17935. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  17936. {
  17937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17938. {
  17939. strcpy(str, (const char*)value);
  17940. for(int i = 0; str[i]; i++)
  17941. {
  17942. str[i] = tolower(str[i]);
  17943. }
  17944. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  17945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17946. isSuccess = ConfigurationStatus_Accepted;
  17947. }
  17948. else
  17949. {
  17950. isSuccess = ConfigurationStatus_Rejected;
  17951. }
  17952. }
  17953. if(strcmp(key, "BlinkRepeat") == 0)
  17954. {
  17955. //Charger.BlinkRepeat = Integer.parseInt(value);
  17956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17957. {
  17958. check_ascii = value[0];
  17959. if( (check_ascii < 48) || (check_ascii > 57) )
  17960. {
  17961. isSuccess = ConfigurationStatus_Rejected;
  17962. }
  17963. else
  17964. {
  17965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  17966. isSuccess = ConfigurationStatus_Accepted;
  17967. }
  17968. }
  17969. else
  17970. {
  17971. isSuccess = ConfigurationStatus_Rejected;
  17972. }
  17973. }
  17974. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  17975. {
  17976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17977. {
  17978. check_ascii = value[0];
  17979. if( (check_ascii < 48) || (check_ascii > 57) )
  17980. {
  17981. isSuccess = ConfigurationStatus_Rejected;
  17982. }
  17983. else
  17984. {
  17985. if((atoi(value) == 0) || (atoi(value) >= 5))
  17986. {
  17987. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  17988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  17989. isSuccess = ConfigurationStatus_Accepted;
  17990. }
  17991. else
  17992. isSuccess = ConfigurationStatus_Rejected;
  17993. }
  17994. }
  17995. else
  17996. {
  17997. isSuccess = ConfigurationStatus_Rejected;
  17998. }
  17999. }
  18000. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18001. {
  18002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18003. {
  18004. check_ascii = value[0];
  18005. if( (check_ascii < 48) || (check_ascii > 57) )
  18006. {
  18007. isSuccess = ConfigurationStatus_Rejected;
  18008. }
  18009. else
  18010. {
  18011. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18013. isSuccess = ConfigurationStatus_Accepted;
  18014. }
  18015. }
  18016. else
  18017. {
  18018. isSuccess = ConfigurationStatus_Rejected;
  18019. }
  18020. }
  18021. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18022. {
  18023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18024. {
  18025. check_ascii = value[0];
  18026. if( (check_ascii < 48) || (check_ascii > 57) )
  18027. {
  18028. isSuccess = ConfigurationStatus_Rejected;
  18029. }
  18030. else
  18031. {
  18032. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18034. isSuccess = ConfigurationStatus_Accepted;
  18035. }
  18036. }
  18037. else
  18038. {
  18039. isSuccess = ConfigurationStatus_Rejected;
  18040. }
  18041. }
  18042. if(strcmp(key, "HeartbeatInterval") == 0)
  18043. {
  18044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18045. {
  18046. check_ascii = value[0];
  18047. if( (check_ascii < 48) || (check_ascii > 57) )
  18048. {
  18049. isSuccess = ConfigurationStatus_Rejected;
  18050. }
  18051. else
  18052. {
  18053. if((atoi(value) == 0) || (atoi(value) >= 10))
  18054. {
  18055. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18057. HeartBeatWaitTime = atoi(value);
  18058. isSuccess = ConfigurationStatus_Accepted;
  18059. }
  18060. else
  18061. {
  18062. isSuccess = ConfigurationStatus_Rejected;
  18063. }
  18064. }
  18065. }
  18066. else
  18067. {
  18068. isSuccess = ConfigurationStatus_Rejected;
  18069. }
  18070. }
  18071. if(strcmp(key, "LightIntensity") == 0)
  18072. {
  18073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18074. {
  18075. check_ascii = value[0];
  18076. if( (check_ascii < 48) || (check_ascii > 57) )
  18077. {
  18078. isSuccess = ConfigurationStatus_Rejected;
  18079. }
  18080. else
  18081. {
  18082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18083. isSuccess = ConfigurationStatus_Accepted;
  18084. }
  18085. }
  18086. else
  18087. {
  18088. isSuccess = ConfigurationStatus_Rejected;
  18089. }
  18090. }
  18091. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18092. {
  18093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18094. {
  18095. strcpy(str, (const char*)value);
  18096. for(int i = 0; str[i]; i++)
  18097. {
  18098. str[i] = tolower(str[i]);
  18099. }
  18100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18101. isSuccess = ConfigurationStatus_Accepted;
  18102. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18103. }
  18104. else
  18105. {
  18106. isSuccess = ConfigurationStatus_Rejected;
  18107. }
  18108. }
  18109. if(strcmp(key, "LocalPreAuthorize") == 0)
  18110. {
  18111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18112. {
  18113. strcpy(str, (const char*)value);
  18114. for(int i = 0; str[i]; i++)
  18115. {
  18116. str[i] = tolower(str[i]);
  18117. }
  18118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18119. isSuccess = ConfigurationStatus_Accepted;
  18120. }
  18121. else
  18122. {
  18123. isSuccess = ConfigurationStatus_Rejected;
  18124. }
  18125. }
  18126. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18127. {
  18128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18129. {
  18130. check_ascii = value[0];
  18131. if( (check_ascii < 48) || (check_ascii > 57) )
  18132. {
  18133. isSuccess = ConfigurationStatus_Rejected;
  18134. }
  18135. else
  18136. {
  18137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18138. isSuccess = ConfigurationStatus_Accepted;
  18139. }
  18140. }
  18141. else
  18142. {
  18143. isSuccess = ConfigurationStatus_Rejected;
  18144. }
  18145. }
  18146. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18147. {
  18148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18149. {
  18150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18151. isSuccess = ConfigurationStatus_Accepted;
  18152. }
  18153. else
  18154. {
  18155. isSuccess = ConfigurationStatus_Rejected;
  18156. }
  18157. }
  18158. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18159. {
  18160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18161. {
  18162. check_ascii = value[0];
  18163. if( (check_ascii < 48) || (check_ascii > 57) )
  18164. {
  18165. isSuccess = ConfigurationStatus_Rejected;
  18166. }
  18167. else
  18168. {
  18169. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18171. isSuccess = ConfigurationStatus_Accepted;
  18172. }
  18173. }
  18174. else
  18175. {
  18176. isSuccess = ConfigurationStatus_Rejected;
  18177. }
  18178. }
  18179. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18180. {
  18181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18182. {
  18183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18184. isSuccess = ConfigurationStatus_Accepted;
  18185. }
  18186. else
  18187. {
  18188. isSuccess = ConfigurationStatus_Rejected;
  18189. }
  18190. }
  18191. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18192. {
  18193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18194. {
  18195. check_ascii = value[0];
  18196. if( (check_ascii < 48) || (check_ascii > 57) )
  18197. {
  18198. isSuccess = ConfigurationStatus_Rejected;
  18199. }
  18200. else
  18201. {
  18202. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18204. isSuccess = ConfigurationStatus_Accepted;
  18205. }
  18206. }
  18207. else
  18208. {
  18209. isSuccess = ConfigurationStatus_Rejected;
  18210. }
  18211. }
  18212. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18213. {
  18214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18215. {
  18216. check_ascii = value[0];
  18217. if( (check_ascii < 48) || (check_ascii > 57) )
  18218. {
  18219. isSuccess = ConfigurationStatus_Rejected;
  18220. }
  18221. else
  18222. {
  18223. if((atoi(value) == 0) || (atoi(value) >= 3))
  18224. {
  18225. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18227. isSuccess = ConfigurationStatus_Accepted;
  18228. }
  18229. else
  18230. {
  18231. isSuccess = ConfigurationStatus_Rejected;
  18232. }
  18233. }
  18234. }
  18235. else
  18236. {
  18237. isSuccess = ConfigurationStatus_Rejected;
  18238. }
  18239. }
  18240. if(strcmp(key, "MinimumStatusDuration") == 0)
  18241. {
  18242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18243. {
  18244. check_ascii = value[0];
  18245. if( (check_ascii < 48) || (check_ascii > 57) )
  18246. {
  18247. isSuccess = ConfigurationStatus_Rejected;
  18248. }
  18249. else
  18250. {
  18251. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18252. {
  18253. isSuccess = ConfigurationStatus_Rejected;
  18254. }
  18255. else
  18256. {
  18257. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18259. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18260. isSuccess = ConfigurationStatus_Accepted;
  18261. }
  18262. }
  18263. }
  18264. else
  18265. {
  18266. isSuccess = ConfigurationStatus_Rejected;
  18267. }
  18268. }
  18269. if(strcmp(key, "NumberOfConnectors") == 0)
  18270. {
  18271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18272. {
  18273. check_ascii = value[0];
  18274. if( (check_ascii < 48) || (check_ascii > 57) )
  18275. {
  18276. isSuccess = ConfigurationStatus_Rejected;
  18277. }
  18278. else
  18279. {
  18280. //Charger.ResetRetries = Integer.parseInt(value);
  18281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18282. isSuccess = ConfigurationStatus_Accepted;
  18283. }
  18284. }
  18285. else
  18286. {
  18287. isSuccess = ConfigurationStatus_Rejected;
  18288. }
  18289. }
  18290. if(strcmp(key, "ResetRetries") == 0)
  18291. {
  18292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18293. {
  18294. check_ascii = value[0];
  18295. if( (check_ascii < 48) || (check_ascii > 57) )
  18296. {
  18297. isSuccess = ConfigurationStatus_Rejected;
  18298. }
  18299. else
  18300. {
  18301. //Charger.ResetRetries = Integer.parseInt(value);
  18302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18303. isSuccess = ConfigurationStatus_Accepted;
  18304. }
  18305. }
  18306. else
  18307. {
  18308. isSuccess = ConfigurationStatus_Rejected;
  18309. }
  18310. }
  18311. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18312. {
  18313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18314. {
  18315. strcpy(str, (const char*)value);
  18316. for(int i = 0; str[i]; i++)
  18317. {
  18318. str[i] = tolower(str[i]);
  18319. }
  18320. if(strcmp(str, "notapplicable")== 0)
  18321. {
  18322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18323. isSuccess = ConfigurationStatus_Accepted;
  18324. }
  18325. else if(strcmp(str, "unknown")== 0)
  18326. {
  18327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18328. isSuccess = ConfigurationStatus_Accepted;
  18329. }
  18330. else if(strcmp(str, "rst")== 0)
  18331. {
  18332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18333. isSuccess = ConfigurationStatus_Accepted;
  18334. }
  18335. else if(strcmp(str, "rts")== 0)
  18336. {
  18337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18338. isSuccess = ConfigurationStatus_Accepted;
  18339. }
  18340. else if(strcmp(str, "srt")== 0)
  18341. {
  18342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18343. isSuccess = ConfigurationStatus_Accepted;
  18344. }
  18345. else if(strcmp(str, "str")== 0)
  18346. {
  18347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18348. isSuccess = ConfigurationStatus_Accepted;
  18349. }
  18350. else if(strcmp(str, "trs")== 0)
  18351. {
  18352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18353. isSuccess = ConfigurationStatus_Accepted;
  18354. }
  18355. else if(strcmp(str, "tsr")== 0)
  18356. {
  18357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18358. isSuccess = ConfigurationStatus_Accepted;
  18359. }
  18360. else
  18361. {
  18362. isSuccess = ConfigurationStatus_Rejected;
  18363. }
  18364. }
  18365. else
  18366. {
  18367. isSuccess = ConfigurationStatus_Rejected;
  18368. }
  18369. }
  18370. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18371. {
  18372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18373. {
  18374. check_ascii = value[0];
  18375. if( (check_ascii < 48) || (check_ascii > 57) )
  18376. {
  18377. isSuccess = ConfigurationStatus_Rejected;
  18378. }
  18379. else
  18380. {
  18381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18382. isSuccess = ConfigurationStatus_Accepted;
  18383. }
  18384. }
  18385. else
  18386. {
  18387. isSuccess = ConfigurationStatus_Rejected;
  18388. }
  18389. }
  18390. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18391. {
  18392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18393. {
  18394. strcpy(str, (const char*)value);
  18395. for(int i = 0; str[i]; i++)
  18396. {
  18397. str[i] = tolower(str[i]);
  18398. }
  18399. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18401. isSuccess = ConfigurationStatus_Accepted;
  18402. }
  18403. else
  18404. {
  18405. isSuccess = ConfigurationStatus_Rejected;
  18406. }
  18407. }
  18408. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18409. {
  18410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18411. {
  18412. strcpy(str, (const char*)value);
  18413. for(int i = 0; str[i]; i++)
  18414. {
  18415. str[i] = tolower(str[i]);
  18416. }
  18417. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18419. isSuccess = ConfigurationStatus_Accepted;
  18420. }
  18421. else
  18422. {
  18423. isSuccess = ConfigurationStatus_Rejected;
  18424. }
  18425. }
  18426. if(strcmp(key, "StopTxnAlignedData") == 0)
  18427. {
  18428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18429. {
  18430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18431. isSuccess = ConfigurationStatus_Accepted;
  18432. }
  18433. else
  18434. {
  18435. isSuccess = ConfigurationStatus_Rejected;
  18436. }
  18437. }
  18438. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18439. {
  18440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18441. {
  18442. check_ascii = value[0];
  18443. if( (check_ascii < 48) || (check_ascii > 57) )
  18444. {
  18445. isSuccess = ConfigurationStatus_Rejected;
  18446. }
  18447. else
  18448. {
  18449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18450. isSuccess = ConfigurationStatus_Accepted;
  18451. }
  18452. }
  18453. else
  18454. {
  18455. isSuccess = ConfigurationStatus_Rejected;
  18456. }
  18457. }
  18458. if(strcmp(key, "StopTxnSampledData") == 0)
  18459. {
  18460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18461. {
  18462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18463. isSuccess = ConfigurationStatus_Accepted;
  18464. }
  18465. else
  18466. {
  18467. isSuccess = ConfigurationStatus_Rejected;
  18468. }
  18469. }
  18470. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18471. {
  18472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18473. {
  18474. check_ascii = value[0];
  18475. if( (check_ascii < 48) || (check_ascii > 57) )
  18476. {
  18477. isSuccess = ConfigurationStatus_Rejected;
  18478. }
  18479. else
  18480. {
  18481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18482. isSuccess = ConfigurationStatus_Accepted;
  18483. }
  18484. }
  18485. else
  18486. {
  18487. isSuccess = ConfigurationStatus_Rejected;
  18488. }
  18489. }
  18490. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18491. {
  18492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18493. {
  18494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18495. isSuccess = ConfigurationStatus_Accepted;
  18496. }
  18497. else
  18498. {
  18499. isSuccess = ConfigurationStatus_Rejected;
  18500. }
  18501. }
  18502. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18503. {
  18504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18505. {
  18506. check_ascii = value[0];
  18507. if( (check_ascii < 48) || (check_ascii > 57) )
  18508. {
  18509. isSuccess = ConfigurationStatus_Rejected;
  18510. }
  18511. else
  18512. {
  18513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18514. isSuccess = ConfigurationStatus_Accepted;
  18515. }
  18516. }
  18517. else
  18518. {
  18519. isSuccess = ConfigurationStatus_Rejected;
  18520. }
  18521. }
  18522. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18523. {
  18524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18525. {
  18526. check_ascii = value[0];
  18527. if( (check_ascii < 48) || (check_ascii > 57) )
  18528. {
  18529. isSuccess = ConfigurationStatus_Rejected;
  18530. }
  18531. else
  18532. {
  18533. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18535. TransactionMessageAttemptsValue = atoi(value);
  18536. isSuccess = ConfigurationStatus_Accepted;
  18537. }
  18538. }
  18539. else
  18540. {
  18541. isSuccess = ConfigurationStatus_Rejected;
  18542. }
  18543. }
  18544. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18545. {
  18546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18547. {
  18548. check_ascii = value[0];
  18549. if( (check_ascii < 48) || (check_ascii > 57) )
  18550. {
  18551. isSuccess = ConfigurationStatus_Rejected;
  18552. }
  18553. else
  18554. {
  18555. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18557. TransactionMessageRetryIntervalValue = atoi(value);
  18558. isSuccess = ConfigurationStatus_Accepted;
  18559. }
  18560. }
  18561. else
  18562. {
  18563. isSuccess = ConfigurationStatus_Rejected;
  18564. }
  18565. }
  18566. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18567. {
  18568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18569. {
  18570. strcpy(str, (const char*)value);
  18571. for(int i = 0; str[i]; i++)
  18572. {
  18573. str[i] = tolower(str[i]);
  18574. }
  18575. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18577. isSuccess = ConfigurationStatus_Accepted;
  18578. }
  18579. else
  18580. {
  18581. isSuccess = ConfigurationStatus_Rejected;
  18582. }
  18583. }
  18584. if(strcmp(key, "WebSocketPingInterval") == 0)
  18585. {
  18586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18587. {
  18588. check_ascii = value[0];
  18589. if( (check_ascii < 48) || (check_ascii > 57) )
  18590. {
  18591. isSuccess = ConfigurationStatus_Rejected;
  18592. }
  18593. else
  18594. {
  18595. if((atoi(value) == 0) || (atoi(value) >= 10))
  18596. {
  18597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18598. isSuccess = ConfigurationStatus_Accepted;
  18599. }
  18600. else
  18601. isSuccess = ConfigurationStatus_Rejected;
  18602. }
  18603. }
  18604. else
  18605. {
  18606. isSuccess = ConfigurationStatus_Rejected;
  18607. }
  18608. }
  18609. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18610. {
  18611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18612. {
  18613. strcpy(str, (const char*)value);
  18614. for(int i = 0; str[i]; i++)
  18615. {
  18616. str[i] = tolower(str[i]);
  18617. }
  18618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18619. isSuccess = ConfigurationStatus_Accepted;
  18620. }
  18621. else
  18622. {
  18623. isSuccess = ConfigurationStatus_Rejected;
  18624. }
  18625. }
  18626. if(strcmp(key, "AuthorizationKey") == 0)
  18627. {
  18628. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18629. {
  18630. strcpy(str, (const char*)value);
  18631. int strlength = strlen(str);
  18632. char capture[3];
  18633. char stackItem = 0;
  18634. char password[21] = {0};
  18635. printf("String length: %d\n", strlength);
  18636. for(int idx=0; idx<(strlength/2); idx++)
  18637. {
  18638. capture[0] = str[(idx*2)];
  18639. capture[1] = str[(idx*2)+1];
  18640. capture[2] = 0;
  18641. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18642. sprintf(password,"%s%c", password, stackItem);
  18643. }
  18644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  18645. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18646. isSuccess = ConfigurationStatus_Accepted;
  18647. }
  18648. else
  18649. {
  18650. isSuccess = ConfigurationStatus_Rejected;
  18651. }
  18652. }
  18653. if(strcmp(key, "SecurityProfile") == 0)
  18654. {
  18655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18656. {
  18657. check_ascii = value[0];
  18658. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18659. {
  18660. isSuccess = ConfigurationStatus_Rejected;
  18661. }
  18662. else if(check_ascii == 0x33)
  18663. {
  18664. isSuccess = NotSupported;
  18665. }
  18666. else
  18667. {
  18668. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18669. {
  18670. if(((check_ascii - 0x30) == 1) ||
  18671. ((check_ascii - 0x30) == 2) ||
  18672. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18673. {
  18674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18675. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18676. isSuccess = ConfigurationStatus_Accepted;
  18677. }
  18678. else
  18679. isSuccess = ConfigurationStatus_Rejected;
  18680. }
  18681. else
  18682. isSuccess = ConfigurationStatus_Rejected;
  18683. }
  18684. }
  18685. else
  18686. {
  18687. isSuccess = ConfigurationStatus_Rejected;
  18688. }
  18689. }
  18690. if(strcmp(key, "DefaultPrice") == 0)
  18691. {
  18692. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18693. {
  18694. strcpy(str, (const char*)value);
  18695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18696. isSuccess = ConfigurationStatus_Accepted;
  18697. }
  18698. else
  18699. {
  18700. isSuccess = ConfigurationStatus_Rejected;
  18701. }
  18702. }
  18703. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18704. {
  18705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18706. {
  18707. strcpy(str, (const char*)value);
  18708. for(int i = 0; str[i]; i++)
  18709. {
  18710. str[i] = tolower(str[i]);
  18711. }
  18712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18713. isSuccess = ConfigurationStatus_Accepted;
  18714. }
  18715. else
  18716. {
  18717. isSuccess = ConfigurationStatus_Rejected;
  18718. }
  18719. }
  18720. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18721. {
  18722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18723. {
  18724. strcpy(str, (const char*)value);
  18725. for(int i = 0; str[i]; i++)
  18726. {
  18727. str[i] = tolower(str[i]);
  18728. }
  18729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18730. isSuccess = ConfigurationStatus_Accepted;
  18731. }
  18732. else
  18733. {
  18734. isSuccess = ConfigurationStatus_Rejected;
  18735. }
  18736. }
  18737. if(strcmp(key, "TimeOffset") == 0)
  18738. {
  18739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18740. {
  18741. strcpy(str, (const char*)value);
  18742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18743. isSuccess = ConfigurationStatus_Accepted;
  18744. }
  18745. else
  18746. {
  18747. isSuccess = ConfigurationStatus_Rejected;
  18748. }
  18749. }
  18750. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18751. {
  18752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18753. {
  18754. strcpy(str, (const char*)value);
  18755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18756. isSuccess = ConfigurationStatus_Accepted;
  18757. }
  18758. else
  18759. {
  18760. isSuccess = ConfigurationStatus_Rejected;
  18761. }
  18762. }
  18763. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18764. {
  18765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18766. {
  18767. strcpy(str, (const char*)value);
  18768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18769. isSuccess = ConfigurationStatus_Accepted;
  18770. }
  18771. else
  18772. {
  18773. isSuccess = ConfigurationStatus_Rejected;
  18774. }
  18775. }
  18776. if(strcmp(key, "SystemUptimeSec") == 0)
  18777. {
  18778. isSuccess = NotSupported;
  18779. }
  18780. if(strcmp(key, "FreeVend") == 0)
  18781. {
  18782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18783. {
  18784. strcpy(str, (const char*)value);
  18785. for(int i = 0; str[i]; i++)
  18786. {
  18787. str[i] = tolower(str[i]);
  18788. }
  18789. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18791. isSuccess = ConfigurationStatus_Accepted;
  18792. }
  18793. else
  18794. {
  18795. isSuccess = ConfigurationStatus_Rejected;
  18796. }
  18797. }
  18798. if(strcmp(key, "FreeVendIdtag") == 0)
  18799. {
  18800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18801. {
  18802. strcpy(str, (const char*)value);
  18803. if(strlen(str) <= 20)
  18804. {
  18805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18806. isSuccess = ConfigurationStatus_Accepted;
  18807. }
  18808. else
  18809. {
  18810. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18811. isSuccess = ConfigurationStatus_Rejected;
  18812. }
  18813. }
  18814. else
  18815. {
  18816. isSuccess = ConfigurationStatus_Rejected;
  18817. }
  18818. }
  18819. if(strcmp(key, "OcppServer") == 0)
  18820. {
  18821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18822. {
  18823. strcpy(str, (const char*)value);
  18824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18825. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18826. isSuccess = ConfigurationStatus_Accepted;
  18827. }
  18828. else
  18829. {
  18830. isSuccess = ConfigurationStatus_Rejected;
  18831. }
  18832. }
  18833. if(strcmp(key, "MaintainServer") == 0)
  18834. {
  18835. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18836. {
  18837. strcpy(str, (const char*)value);
  18838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18839. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18840. isSuccess = ConfigurationStatus_Accepted;
  18841. }
  18842. else
  18843. {
  18844. isSuccess = ConfigurationStatus_Rejected;
  18845. }
  18846. }
  18847. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18848. {
  18849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18850. {
  18851. strcpy(str, (const char*)value);
  18852. for(int i = 0; str[i]; i++)
  18853. {
  18854. str[i] = tolower(str[i]);
  18855. }
  18856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18857. isSuccess = ConfigurationStatus_Accepted;
  18858. }
  18859. else
  18860. {
  18861. isSuccess = ConfigurationStatus_Rejected;
  18862. }
  18863. }
  18864. if(strcmp(key, "StatusNotificationInterval") == 0)
  18865. {
  18866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18867. {
  18868. check_ascii = value[0];
  18869. if( (check_ascii < 48) || (check_ascii > 57) )
  18870. {
  18871. isSuccess = ConfigurationStatus_Rejected;
  18872. }
  18873. else
  18874. {
  18875. if((atoi(value) == 0) || (atoi(value) >= 10))
  18876. {
  18877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18878. isSuccess = ConfigurationStatus_Accepted;
  18879. }
  18880. else
  18881. isSuccess = ConfigurationStatus_Rejected;
  18882. }
  18883. }
  18884. else
  18885. {
  18886. isSuccess = ConfigurationStatus_Rejected;
  18887. }
  18888. }
  18889. if(strcmp(key, "PreAuthAmount") == 0)
  18890. {
  18891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18892. {
  18893. check_ascii = value[0];
  18894. if( (check_ascii < 48) || (check_ascii > 57) )
  18895. {
  18896. isSuccess = ConfigurationStatus_Rejected;
  18897. }
  18898. else
  18899. {
  18900. if(atof(value) >= 0)
  18901. {
  18902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18903. isSuccess = ConfigurationStatus_Accepted;
  18904. }
  18905. else
  18906. isSuccess = ConfigurationStatus_Rejected;
  18907. }
  18908. }
  18909. else
  18910. {
  18911. isSuccess = ConfigurationStatus_Rejected;
  18912. }
  18913. }
  18914. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  18915. {
  18916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  18917. {
  18918. check_ascii = value[0];
  18919. if( (check_ascii < 48) || (check_ascii > 57) )
  18920. {
  18921. isSuccess = ConfigurationStatus_Rejected;
  18922. }
  18923. else
  18924. {
  18925. if(atoi(value) >= 0)
  18926. {
  18927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  18928. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  18929. isSuccess = ConfigurationStatus_Accepted;
  18930. }
  18931. else
  18932. isSuccess = ConfigurationStatus_Rejected;
  18933. }
  18934. }
  18935. else
  18936. {
  18937. isSuccess = ConfigurationStatus_Rejected;
  18938. }
  18939. }
  18940. if(strcmp(key, "PowerSharingServerIP") == 0)
  18941. {
  18942. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  18943. {
  18944. strcpy(str, (const char*)value);
  18945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  18946. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  18947. isSuccess = ConfigurationStatus_Accepted;
  18948. }
  18949. else
  18950. {
  18951. isSuccess = ConfigurationStatus_Rejected;
  18952. }
  18953. }
  18954. if(strcmp(key, "EVCCID_PREFIX") == 0)
  18955. {
  18956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  18957. {
  18958. strcpy(str, (const char*)value);
  18959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  18960. isSuccess = ConfigurationStatus_Accepted;
  18961. }
  18962. else
  18963. {
  18964. isSuccess = ConfigurationStatus_Rejected;
  18965. }
  18966. }
  18967. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  18968. {
  18969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  18970. {
  18971. if(atoi(value) > modelnameInfo.ratedPower)
  18972. {
  18973. isSuccess = ConfigurationStatus_Rejected;
  18974. }
  18975. else{
  18976. strcpy(str, (const char*)value);
  18977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  18978. isSuccess = ConfigurationStatus_Accepted;
  18979. }
  18980. }
  18981. else
  18982. {
  18983. isSuccess = ConfigurationStatus_Rejected;
  18984. }
  18985. }
  18986. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  18987. {
  18988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  18989. {
  18990. if((atoi(value) != 0) && (atoi(value) < 5))
  18991. {
  18992. isSuccess = ConfigurationStatus_Rejected;
  18993. }
  18994. else{
  18995. strcpy(str, (const char*)value);
  18996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  18997. isSuccess = ConfigurationStatus_Accepted;
  18998. }
  18999. }
  19000. else
  19001. {
  19002. isSuccess = ConfigurationStatus_Rejected;
  19003. }
  19004. }
  19005. if(strcmp(key, "CpoName") == 0)
  19006. {
  19007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19008. {
  19009. strcpy(str, (const char*)value);
  19010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19011. isSuccess = ConfigurationStatus_Accepted;
  19012. }
  19013. else
  19014. {
  19015. isSuccess = ConfigurationStatus_Rejected;
  19016. }
  19017. }
  19018. #if 0
  19019. //For OCPP Test Case
  19020. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19021. {
  19022. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19023. {
  19024. strcpy(str, (const char*)value);
  19025. for(int i = 0; str[i]; i++)
  19026. {
  19027. str[i] = tolower(str[i]);
  19028. }
  19029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19030. isSuccess = ConfigurationStatus_Accepted;
  19031. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19032. }
  19033. else
  19034. {
  19035. isSuccess = ConfigurationStatus_Rejected;
  19036. }
  19037. }
  19038. #endif
  19039. #if 1
  19040. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19041. {
  19042. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19043. {
  19044. strcpy(str, (const char*)value);
  19045. for(int i = 0; str[i]; i++)
  19046. {
  19047. str[i] = tolower(str[i]);
  19048. }
  19049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19050. isSuccess = ConfigurationStatus_Accepted;
  19051. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19052. }
  19053. else
  19054. {
  19055. isSuccess = ConfigurationStatus_Rejected;
  19056. }
  19057. }
  19058. #endif
  19059. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19060. {
  19061. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19062. {
  19063. check_ascii = value[0];
  19064. if( (check_ascii < 48) || (check_ascii > 57) )
  19065. {
  19066. isSuccess = ConfigurationStatus_Rejected;
  19067. }
  19068. else
  19069. {
  19070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19071. isSuccess = ConfigurationStatus_Accepted;
  19072. }
  19073. }
  19074. else
  19075. {
  19076. isSuccess = ConfigurationStatus_Rejected;
  19077. }
  19078. }
  19079. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19080. {
  19081. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19082. {
  19083. check_ascii = value[0];
  19084. if( (check_ascii < 48) || (check_ascii > 57) )
  19085. {
  19086. isSuccess = ConfigurationStatus_Rejected;
  19087. }
  19088. else
  19089. {
  19090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19091. isSuccess = ConfigurationStatus_Accepted;
  19092. }
  19093. }
  19094. else
  19095. {
  19096. isSuccess = ConfigurationStatus_Rejected;
  19097. }
  19098. }
  19099. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19100. {
  19101. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19102. {
  19103. strcpy(str, (const char*)value);
  19104. for(int i = 0; str[i]; i++)
  19105. {
  19106. str[i] = tolower(str[i]);
  19107. }
  19108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19109. isSuccess = ConfigurationStatus_Accepted;
  19110. }
  19111. else
  19112. {
  19113. isSuccess = ConfigurationStatus_Rejected;
  19114. }
  19115. }
  19116. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19117. {
  19118. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19119. {
  19120. check_ascii = value[0];
  19121. if( (check_ascii < 48) || (check_ascii > 57) )
  19122. {
  19123. isSuccess = ConfigurationStatus_Rejected;
  19124. }
  19125. else
  19126. {
  19127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19128. isSuccess = ConfigurationStatus_Accepted;
  19129. }
  19130. }
  19131. else
  19132. {
  19133. isSuccess = ConfigurationStatus_Rejected;
  19134. }
  19135. }
  19136. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19137. {
  19138. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19139. {
  19140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19141. isSuccess = ConfigurationStatus_Accepted;
  19142. }
  19143. else
  19144. {
  19145. isSuccess = ConfigurationStatus_Rejected;
  19146. }
  19147. }
  19148. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19149. {
  19150. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19151. {
  19152. check_ascii = value[0];
  19153. if( (check_ascii < 48) || (check_ascii > 57) )
  19154. {
  19155. isSuccess = ConfigurationStatus_Rejected;
  19156. }
  19157. else
  19158. {
  19159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19160. isSuccess = ConfigurationStatus_Accepted;
  19161. }
  19162. }
  19163. else
  19164. {
  19165. isSuccess = ConfigurationStatus_Rejected;
  19166. }
  19167. }
  19168. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19169. {
  19170. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19171. {
  19172. strcpy(str, (const char*)value);
  19173. for(int i = 0; str[i]; i++)
  19174. {
  19175. str[i] = tolower(str[i]);
  19176. }
  19177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19178. isSuccess = ConfigurationStatus_Accepted;
  19179. }
  19180. else
  19181. {
  19182. isSuccess = ConfigurationStatus_Rejected;
  19183. }
  19184. }
  19185. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19186. {
  19187. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19188. {
  19189. check_ascii = value[0];
  19190. if( (check_ascii < 48) || (check_ascii > 57) )
  19191. {
  19192. isSuccess = ConfigurationStatus_Rejected;
  19193. }
  19194. else
  19195. {
  19196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19197. isSuccess = ConfigurationStatus_Accepted;
  19198. }
  19199. }
  19200. else
  19201. {
  19202. isSuccess = ConfigurationStatus_Rejected;
  19203. }
  19204. }
  19205. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19206. return isSuccess;
  19207. }
  19208. int TransactionMessageAttemptsGet(void)
  19209. {
  19210. return TransactionMessageAttemptsValue;
  19211. }
  19212. int FirstHeartBeatResponse(void)
  19213. {
  19214. return FirstHeartBeat;
  19215. }
  19216. int TransactionMessageRetryIntervalGet(void)
  19217. {
  19218. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19219. }
  19220. int ReadHttpStatus(int sock)
  19221. {
  19222. //char c;
  19223. char buff[1024]="",*ptr=buff+1;
  19224. int bytes_received, status;
  19225. DEBUG_INFO("Begin Response ..\n");
  19226. while((bytes_received = recv(sock, ptr, 1, 0))){
  19227. if(bytes_received==-1){
  19228. perror("ReadHttpStatus");
  19229. exit(1);
  19230. }
  19231. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19232. ptr++;
  19233. }
  19234. *ptr=0;
  19235. ptr=buff+1;
  19236. sscanf(ptr,"%*s %d ", &status);
  19237. DEBUG_INFO("%s\n",ptr);
  19238. DEBUG_INFO("status=%d\n",status);
  19239. DEBUG_INFO("End Response ..\n");
  19240. return (bytes_received>0)?status:0;
  19241. }
  19242. //the only filed that it parsed is 'Content-Length'
  19243. int ParseHeader(int sock)
  19244. {
  19245. //char c;
  19246. char buff[1024]="",*ptr=buff+4;
  19247. int bytes_received;
  19248. DEBUG_INFO("Begin HEADER ..\n");
  19249. while((bytes_received = recv(sock, ptr, 1, 0))){
  19250. if(bytes_received==-1){
  19251. perror("Parse Header");
  19252. exit(1);
  19253. }
  19254. if(
  19255. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19256. (ptr[-1]=='\r') && (*ptr=='\n' )
  19257. ) break;
  19258. ptr++;
  19259. }
  19260. *ptr=0;
  19261. ptr=buff+4;
  19262. //printf("%s",ptr);
  19263. if(bytes_received){
  19264. ptr=strstr(ptr,"Content-Length:");
  19265. if(ptr){
  19266. sscanf(ptr,"%*s %d",&bytes_received);
  19267. }else
  19268. bytes_received=-1; //unknown size
  19269. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19270. }
  19271. DEBUG_INFO("End HEADER ..\n");
  19272. return bytes_received ;
  19273. }
  19274. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19275. {
  19276. int result = TRUE;
  19277. char rmFileCmd[100]={0};
  19278. char FilePath[100]={0};
  19279. char ftpbuf[200];
  19280. int systemresult;
  19281. sprintf(FilePath,"/mnt/%s",filename);
  19282. system("ping 8.8.8.8 &");
  19283. if((access(FilePath,F_OK))!=-1)
  19284. {
  19285. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19286. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19287. system(rmFileCmd);
  19288. }
  19289. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19290. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19291. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19292. systemresult = system(ftpbuf);
  19293. if(systemresult != 0)
  19294. {
  19295. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19296. result = FALSE;
  19297. }
  19298. system("pkill ping");
  19299. return result;
  19300. }
  19301. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19302. {
  19303. int result = TRUE;
  19304. char rmFileCmd[100]={0};
  19305. char FilePath[100]={0};
  19306. char ftpbuf[200];
  19307. int systemresult;
  19308. sprintf(FilePath,"/mnt/%s",filename);
  19309. system("ping 8.8.8.8 &");
  19310. if((access(FilePath,F_OK))!=-1)
  19311. {
  19312. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19313. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19314. system(rmFileCmd);
  19315. }
  19316. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19317. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19318. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19319. systemresult = system(ftpbuf);
  19320. if(systemresult != 0)
  19321. {
  19322. DEBUG_WARN("scp error!\n");
  19323. result = FALSE;
  19324. }
  19325. system("pkill ping");
  19326. return result;
  19327. }
  19328. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19329. {
  19330. int result = TRUE;
  19331. char rmFileCmd[100]={0};
  19332. char FilePath[100]={0};
  19333. char ftpbuf[200];
  19334. int systemresult;
  19335. sprintf(FilePath,"/mnt/%s",filename);
  19336. system("ping 8.8.8.8 &");
  19337. if((access(FilePath,F_OK))!=-1)
  19338. {
  19339. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19340. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19341. system(rmFileCmd);
  19342. }
  19343. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19344. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  19345. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19346. systemresult = system(ftpbuf);
  19347. if(systemresult != 0)
  19348. {
  19349. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  19350. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19351. systemresult = system(ftpbuf);
  19352. if(systemresult != 0)
  19353. {
  19354. DEBUG_WARN("FTP download fail!\n");
  19355. result = FALSE;
  19356. }
  19357. }
  19358. system("pkill ping");
  19359. return result;
  19360. }
  19361. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19362. {
  19363. char rmFileCmd[100]={0};
  19364. char FilePath[100]={0};
  19365. char buf[512];
  19366. int systemresult = 0;
  19367. //DEBUG_INFO("filename=%s\n",filename);
  19368. //DEBUG_INFO("url=%s\n",url);
  19369. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19370. if((access(FilePath,F_OK))!=-1)
  19371. {
  19372. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19373. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19374. system(rmFileCmd);
  19375. }
  19376. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19377. if(fp == NULL)
  19378. {
  19379. DEBUG_INFO("log is NULL\n");
  19380. return FALSE;
  19381. }
  19382. else
  19383. {
  19384. fprintf(fp, "%s\n", url);
  19385. fprintf(fp, "%s\n", filename);
  19386. fclose(fp);
  19387. }
  19388. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19389. if(phpFP == NULL)
  19390. {
  19391. DEBUG_INFO("PHP upload fail.\n");
  19392. return FALSE;
  19393. }
  19394. else
  19395. {
  19396. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19397. {
  19398. if(strstr(buf, "result") != NULL)
  19399. {
  19400. sscanf(buf, "result: %d", &systemresult);
  19401. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19402. }
  19403. }
  19404. pclose(phpFP);
  19405. }
  19406. if(systemresult != 1)
  19407. {
  19408. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19409. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19410. if(phpFP == NULL)
  19411. {
  19412. DEBUG_WARN("PHP PUT upload fail.\n");
  19413. return FALSE;
  19414. }
  19415. else
  19416. {
  19417. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19418. {
  19419. if(strstr(buf, "result") != NULL)
  19420. {
  19421. sscanf(buf, "result: %d", &systemresult);
  19422. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19423. }
  19424. }
  19425. pclose(phpFP);
  19426. }
  19427. }
  19428. if(systemresult != 1)
  19429. {
  19430. DEBUG_WARN("PHP PUT upload fail.\n");
  19431. return FALSE;
  19432. }
  19433. return TRUE;
  19434. }
  19435. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19436. {
  19437. int result = FALSE;
  19438. char ftpbuf[200];
  19439. int systemresult;
  19440. /*
  19441. // Domaind name transfer to IP address
  19442. struct hostent* server;
  19443. char *IPbuffer;
  19444. server = gethostbyname(location);
  19445. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19446. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19447. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19448. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19449. systemresult = system(ftpbuf);
  19450. if(systemresult != 0)
  19451. {
  19452. DEBUG_INFO("ftpput error!\n");
  19453. }
  19454. else
  19455. {
  19456. result = TRUE;
  19457. DEBUG_INFO("ftpput OK!\n");
  19458. }
  19459. return result;
  19460. }
  19461. int GetOcppServerURL()
  19462. {
  19463. int result = FALSE;
  19464. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19465. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19466. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19467. struct yuarel url;
  19468. char urlStr[512];
  19469. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19470. {
  19471. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19472. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19473. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19474. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19475. if(yuarel_parse(&url, urlStr) != -1)
  19476. {
  19477. sprintf(OcppProtocol, "%s", url.scheme);
  19478. sprintf(OcppHost, "%s", url.host);
  19479. if(url.path == NULL)
  19480. OcppTempPath[0] = '\0';
  19481. else
  19482. {
  19483. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19484. {
  19485. sprintf(OcppTempPath, "%s/", url.path);
  19486. }
  19487. else
  19488. {
  19489. sprintf(OcppTempPath, "%s", url.path);
  19490. }
  19491. }
  19492. if(url.port == 0)
  19493. {
  19494. if(strcmp(OcppProtocol, "wss") == 0)
  19495. OcppPort = 443;
  19496. else
  19497. OcppPort = 80;
  19498. }
  19499. else
  19500. OcppPort = url.port;
  19501. result = TRUE;
  19502. }
  19503. }
  19504. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19505. {
  19506. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19507. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19508. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19509. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19510. if(yuarel_parse(&url, urlStr) != -1)
  19511. {
  19512. sprintf(OcppProtocol, "%s", url.scheme);
  19513. sprintf(OcppHost, "%s", url.host);
  19514. if(url.path == NULL)
  19515. OcppTempPath[0] = '\0';
  19516. else
  19517. sprintf(OcppTempPath, "%s", url.path);
  19518. if(url.port == 0)
  19519. {
  19520. if(strcmp(OcppProtocol, "wss") == 0)
  19521. OcppPort = 443;
  19522. else
  19523. OcppPort = 80;
  19524. }
  19525. else
  19526. OcppPort = url.port;
  19527. result = TRUE;
  19528. }
  19529. }
  19530. else
  19531. {
  19532. strcpy(OcppHost,"");
  19533. }
  19534. return result;
  19535. }
  19536. int GetOcppPath()
  19537. {
  19538. int result = FALSE;
  19539. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19540. {
  19541. if(OcppTempPath == NULL)
  19542. {
  19543. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19544. }
  19545. else
  19546. {
  19547. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19548. }
  19549. result = TRUE;
  19550. goto End;
  19551. }
  19552. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19553. {
  19554. if(OcppTempPath == NULL)
  19555. {
  19556. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19557. }
  19558. else
  19559. {
  19560. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19561. }
  19562. result = TRUE;
  19563. goto End;
  19564. }
  19565. else
  19566. {
  19567. strcpy(OcppPath,"");
  19568. }
  19569. End:
  19570. return result;
  19571. }
  19572. int GetOcppPort()
  19573. {
  19574. return OcppPort;
  19575. }
  19576. int GetOcppConnStatus(void)
  19577. {
  19578. return ShmOCPP16Data->OcppConnStatus;
  19579. }
  19580. void SetOcppConnStatus(uint8_t status)
  19581. {
  19582. ShmOCPP16Data->OcppConnStatus = status;
  19583. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19584. }
  19585. int GetHeartBeatWithNOResponse(void)
  19586. {
  19587. return HeartBeatWithNOResponse;
  19588. }
  19589. void SetHeartBeatWithNOResponse(void)
  19590. {
  19591. HeartBeatWithNOResponse = 0;
  19592. }
  19593. void GetStartTransactionIdTag(int gun_index)
  19594. {
  19595. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19596. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19597. }
  19598. int GetStartTransactionId(int gun_index)
  19599. {
  19600. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19601. }
  19602. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19603. {
  19604. char ch;
  19605. FILE *fptr1;
  19606. int temptransactionId;
  19607. char str[100]={0};
  19608. temptransactionId = 0;
  19609. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19610. {
  19611. DEBUG_INFO("IdTag is empty.\n");
  19612. return temptransactionId;
  19613. }
  19614. /*------ Read the file ----------------*/
  19615. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19616. if (!fptr1)
  19617. {
  19618. DEBUG_INFO("QueueTransactionId file open error.\n");
  19619. //printf(" File not found or unable to open the input file!!\n");
  19620. return temptransactionId;
  19621. }
  19622. ch=fgetc(fptr1);
  19623. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19624. rewind(fptr1);
  19625. if(ch!=EOF)
  19626. {
  19627. // printf("%c",ch);
  19628. while (fgets(str, 100, fptr1) != NULL)
  19629. {
  19630. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19631. if(str[0]=='\0')
  19632. {
  19633. break;
  19634. }
  19635. char *revbuf[8] = {0}; // Variable store string split
  19636. int num = 0;// Quantity after string split
  19637. DEBUG_INFO("Transaction queue data= %s\n", str);
  19638. splitstring(str,",",revbuf,&num); // String split
  19639. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19640. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19641. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19642. DEBUG_INFO("------------------------------\n");
  19643. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19644. {
  19645. if(isStopTransaction)
  19646. {
  19647. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19648. {
  19649. temptransactionId = atoi(revbuf[2]);
  19650. //break;
  19651. }
  19652. }
  19653. else
  19654. {
  19655. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19656. {
  19657. temptransactionId = atoi(revbuf[2]);
  19658. //break;
  19659. }
  19660. }
  19661. }
  19662. }
  19663. }
  19664. else
  19665. DEBUG_INFO("EOF\n");
  19666. fclose(fptr1);
  19667. /*------- End of reading ---------------*/
  19668. return temptransactionId;
  19669. }
  19670. void SetTransactionIdZero(int transactionId)
  19671. {
  19672. char ch;
  19673. FILE *fptr1, *fptr2;
  19674. int temptransactionId = 0;
  19675. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19676. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19677. if (!fptr1)
  19678. {
  19679. //printf(" File not found or unable to open the input file!!\n");
  19680. return ;
  19681. }
  19682. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19683. if (!fptr2)
  19684. {
  19685. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19686. fclose(fptr1);
  19687. return ;
  19688. }
  19689. ch=fgetc(fptr1);
  19690. rewind(fptr1);
  19691. if(ch!=EOF)
  19692. {
  19693. // copy all contents to the temporary file except the specific line
  19694. while (fgets(str, 100, fptr1) != NULL)
  19695. {
  19696. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19697. if(str[0]=='\0')
  19698. {
  19699. break;
  19700. }
  19701. char *revbuf[8] = {0};
  19702. int num = 0;
  19703. strcpy(strtemp, str);
  19704. splitstring(str,",",revbuf,&num);
  19705. if(revbuf[2][0] != '\0')
  19706. {
  19707. temptransactionId = atoi(revbuf[2]);
  19708. if(transactionId != temptransactionId)
  19709. {
  19710. fprintf(fptr2, "%s\n", strtemp);
  19711. }
  19712. }
  19713. }
  19714. }
  19715. fclose(fptr1);
  19716. fclose(fptr2);
  19717. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19718. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19719. /*------ Read the file ----------------*/
  19720. }
  19721. int InternetDisconnect(void)
  19722. {
  19723. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19724. }
  19725. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19726. void storeTempStopTransaction(int gun_index)
  19727. {
  19728. char guid[37]={0};
  19729. int tempIndex = 0;
  19730. char TempStopTransaction[256];
  19731. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19732. DEBUG_INFO("storeTempStopTransaction...\n");
  19733. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19734. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19735. //=========================== Stop Transaction Time ===============================================
  19736. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  19737. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19738. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19739. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19740. {
  19741. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19742. {
  19743. tempIndex = ((gun_index==2) ? 1: 0);
  19744. }
  19745. else
  19746. {
  19747. tempIndex = gun_index;
  19748. }
  19749. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19750. {
  19751. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19752. {
  19753. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19754. }
  19755. }// END OF CHAdeMO_QUANTITY
  19756. }
  19757. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19758. {
  19759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19760. {
  19761. tempIndex = ((gun_index==2) ? 1: 0);
  19762. }
  19763. else
  19764. {
  19765. tempIndex = gun_index;
  19766. }
  19767. for (int index = 0; index < CCS_QUANTITY; index++)
  19768. {
  19769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19770. {
  19771. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19772. }
  19773. }// END OF CCS_QUANTITY
  19774. }
  19775. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19776. {
  19777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19778. {
  19779. tempIndex = ((gun_index==2) ? 1: 0);
  19780. }
  19781. else
  19782. {
  19783. tempIndex = gun_index;
  19784. }
  19785. for (int index = 0; index < GB_QUANTITY; index++)
  19786. {
  19787. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19788. {
  19789. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19790. }
  19791. }// END OF GB_QUANTITY
  19792. }
  19793. else if(gunType[gun_index] == GUN_TYPE_DO)
  19794. {
  19795. tempIndex = gun_index;
  19796. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19797. {
  19798. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19799. {
  19800. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19801. }
  19802. }
  19803. }
  19804. else
  19805. {
  19806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19807. {
  19808. tempIndex = 2;
  19809. }
  19810. else
  19811. {
  19812. tempIndex = gun_index;
  19813. }
  19814. for (int index = 0; index < AC_QUANTITY; index++)
  19815. {
  19816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19817. {
  19818. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19819. }
  19820. }// END OF AC_QUANTITY
  19821. }
  19822. //======================================== Message create ==============================================
  19823. json_object *StopTransaction = json_object_new_object();
  19824. json_object *transactionDatas = json_object_new_array();
  19825. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19826. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19827. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19828. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19829. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19830. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19831. meterValueBufferQuery(gun_index, transactionDatas);
  19832. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19833. random_uuid(guid);
  19834. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19835. ,MESSAGE_TYPE_CALL
  19836. ,guid
  19837. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19838. json_object_put(StopTransaction);
  19839. // Check File "TempStopTransaction" Exist
  19840. if((access(TempStopTransaction,F_OK))!=-1)
  19841. {
  19842. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19843. fclose(fopen(TempStopTransaction, "w"));
  19844. }
  19845. else
  19846. {
  19847. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19848. FILE *log = fopen(TempStopTransaction, "w+");
  19849. if(log == NULL)
  19850. {
  19851. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19852. return ;
  19853. }
  19854. else
  19855. {
  19856. fclose(log);
  19857. }
  19858. }
  19859. //Add TempStopTransaction | Update TempStopTransaction
  19860. // open file for writing
  19861. FILE *outfile;
  19862. outfile = fopen (TempStopTransaction, "a");
  19863. //DEBUG_INFO("data = %s\n", queuedata);
  19864. fputs(queuedata, outfile);
  19865. fputs("\n", outfile);
  19866. fclose (outfile);
  19867. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19868. OCPP_updatePeriodEnergy(gun_index);
  19869. }
  19870. void checkTempStopTransaction(int gun_index)
  19871. {
  19872. FILE *fptr1;
  19873. char ch;
  19874. char str[QUEUE_MESSAGE_LENGTH]={0};
  19875. char guid[37]={0};
  19876. char tempdata[65]={0};
  19877. char connectorStr[2]={0};
  19878. char TempStopTransaction[256];
  19879. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19880. fptr1 = fopen(TempStopTransaction, "r");
  19881. //TempStopTransaction格式: 槍號,StopTransaction封包
  19882. if (!fptr1)
  19883. {
  19884. //printf(" File not found or unable to open the input file!!\n");
  19885. return ;
  19886. }
  19887. ch=fgetc(fptr1);
  19888. //printf(" Now the content of the file %s is : \n",fname);
  19889. rewind(fptr1);
  19890. if(ch!=EOF)
  19891. {
  19892. // copy all contents to the temporary file except the specific line
  19893. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19894. {
  19895. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19896. if(str[0]=='\0')
  19897. {
  19898. break;
  19899. }
  19900. //TempStopTransaction格式: 槍號,StopTransaction封包
  19901. strncpy(connectorStr, str, 1);
  19902. if(atoi(connectorStr) != (gun_index+1))
  19903. {
  19904. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19905. fclose(fptr1);
  19906. return ;
  19907. }
  19908. //random_uuid(guid);
  19909. strncpy(guid, str+6, 36); //copy guid
  19910. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19911. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19912. {
  19913. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19914. }
  19915. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19916. OCPP_insert_transaction_msg(NO, str);
  19917. memset(str,0,ARRAY_SIZE(str));
  19918. }
  19919. }
  19920. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19921. fclose(fptr1);
  19922. remove(TempStopTransaction); // remove the original file
  19923. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19924. }
  19925. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19926. {
  19927. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19928. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19929. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19930. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19931. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19932. }
  19933. void FillTransactionId(int ConnectorId, int TransactionId)
  19934. {
  19935. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19936. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  19937. }
  19938. int GetWebSocketPingInterval(void)
  19939. {
  19940. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19941. }
  19942. int GetServerSign(void)
  19943. {
  19944. return server_sign;
  19945. }
  19946. uint8_t GetOcppSecurityProfile()
  19947. {
  19948. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19949. }
  19950. void MergeCertificates()
  19951. {
  19952. char cmdBuf[2048]={0};
  19953. if(access(ROOTCA_CS,F_OK) != -1)
  19954. {
  19955. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  19956. }
  19957. else
  19958. {
  19959. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  19960. }
  19961. system(cmdBuf);
  19962. }
  19963. void GetOcppChargerBoxId(uint8_t *data)
  19964. {
  19965. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19966. }
  19967. void GetOcppSecurityPassword(uint8_t *data)
  19968. {
  19969. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19970. }
  19971. void SetOcppVersion(uint8_t *version)
  19972. {
  19973. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19974. DEBUG_INFO("ocpp version: %s\n", version);
  19975. if(strstr((char*)version, "ocpp1.6") != NULL)
  19976. {
  19977. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19978. }
  19979. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19980. {
  19981. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19982. system("pkill OcppBackend");
  19983. }
  19984. }
  19985. void SetServerSign(int value)
  19986. {
  19987. server_sign = value;
  19988. }
  19989. int GetBootNotificationInterval(void)
  19990. {
  19991. return BootNotificationInterval;
  19992. }
  19993. int GetInternetConn(void)
  19994. {
  19995. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19996. }
  19997. int GetBackendConnectionTimeout(void)
  19998. {
  19999. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20000. }
  20001. int isConnectorInitMode(int gun_index)
  20002. {
  20003. int tempIndex = 0;
  20004. int result = TRUE;
  20005. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20006. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20007. {
  20008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20009. {
  20010. tempIndex = ((gun_index==2) ? 1: 0);
  20011. }
  20012. else
  20013. {
  20014. tempIndex = gun_index;
  20015. }
  20016. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20017. {
  20018. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20019. {
  20020. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20021. } //end of the same index
  20022. }//end of for CHAdeMO_QUANTITY
  20023. }
  20024. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20025. {
  20026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20027. {
  20028. tempIndex = ((gun_index==2) ? 1: 0);
  20029. }
  20030. else
  20031. {
  20032. tempIndex = gun_index;
  20033. }
  20034. for (int index = 0; index < CCS_QUANTITY; index++)
  20035. {
  20036. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20037. {
  20038. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20039. } //end of the same index
  20040. } // end of for CCS_QUANTITY
  20041. }
  20042. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20043. {
  20044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20045. {
  20046. tempIndex = ((gun_index==2) ? 1: 0);
  20047. }
  20048. else
  20049. {
  20050. tempIndex = gun_index;
  20051. }
  20052. for (int index = 0; index < GB_QUANTITY; index++)
  20053. {
  20054. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20055. {
  20056. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20057. } //end of the same index
  20058. } // end of for GB_QUANTITY
  20059. }
  20060. else if(gunType[gun_index] == GUN_TYPE_DO)
  20061. {
  20062. tempIndex = gun_index;
  20063. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20064. {
  20065. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20066. {
  20067. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20068. } //end of the same index
  20069. }
  20070. }
  20071. else
  20072. {
  20073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20074. {
  20075. tempIndex = 2;
  20076. }
  20077. else
  20078. {
  20079. tempIndex = gun_index;
  20080. }
  20081. for (int index = 0; index < AC_QUANTITY; index++)
  20082. {
  20083. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20084. {
  20085. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20086. }//end of the same index
  20087. }//end of for AC_QUANTITY
  20088. }
  20089. return result;
  20090. }
  20091. void refreshProcDogTimer()
  20092. {
  20093. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20094. }
  20095. void InitialSystemValue(void)
  20096. {
  20097. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20098. locallistVersion=0;
  20099. BootNotificationInterval = 0;
  20100. authorizeRetryTimes = 0;
  20101. GunStatusInterval = 10;
  20102. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20103. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20104. //Hear Beat
  20105. HeartBeatWithNOResponse = 0;
  20106. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20107. FirstHeartBeat = 0;
  20108. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20109. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20110. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20111. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20112. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20113. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20114. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20115. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20116. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20117. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20118. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20119. //Status && ConnectorPlugIn Setting
  20120. Connector0PreviousSystemStatus = 99;
  20121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20122. {
  20123. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20124. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20125. }
  20126. for (int index = 0; index < CCS_QUANTITY; index++)
  20127. {
  20128. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20129. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20130. }
  20131. for (int index = 0; index < GB_QUANTITY; index++)
  20132. {
  20133. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20134. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20135. }
  20136. for (int index = 0; index < AC_QUANTITY; index++)
  20137. {
  20138. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20139. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20140. }
  20141. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20142. {
  20143. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20144. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20145. }
  20146. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20147. {
  20148. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20149. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20150. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20151. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20152. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20153. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20154. }
  20155. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20156. refreshStartTimer(&clientTime.Heartbeat);
  20157. sleep(1);
  20158. }
  20159. void LWS_Send(char *str)
  20160. {
  20161. //=====================================================
  20162. // Check InternetConn 0: disconnected, 1: connected
  20163. //====================================================
  20164. if(GetOcppConnStatus() == 0)
  20165. {
  20166. DEBUG_INFO("offline now !!!\n");
  20167. return;
  20168. }
  20169. // Only disable isWebsocketSendable operation initiated by charger
  20170. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20171. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20172. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20173. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20174. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20175. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20176. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20177. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20178. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20179. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20180. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20181. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20182. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20183. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20184. {
  20185. isWebsocketSendable = 0;
  20186. }
  20187. pthread_mutex_lock(&lock_send);
  20188. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20189. sprintf((char *)SendBuffer, "%s", str);
  20190. SendBufLen = strlen(str);
  20191. pthread_mutex_unlock(&lock_send);
  20192. lws_callback_on_writable(wsi_client);
  20193. //lws_service(context, 0);
  20194. //sleep(1);
  20195. }
  20196. void LWS_SendNow(char *str)
  20197. {
  20198. //=====================================================
  20199. // Check InternetConn 0: disconnected, 1: connected
  20200. //====================================================
  20201. if(GetOcppConnStatus() == 0)
  20202. {
  20203. DEBUG_INFO("offline now !!!\n");
  20204. return;
  20205. }
  20206. // Only disable isWebsocketSendable operation initiated by charger
  20207. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20208. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20209. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20210. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20211. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20212. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20213. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20214. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20215. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20216. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20217. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20218. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20219. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20220. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20221. {
  20222. isWebsocketSendable = 0;
  20223. }
  20224. pthread_mutex_lock(&lock_send);
  20225. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20226. sprintf((char *)SendBuffer, "%s", str);
  20227. SendBufLen = strlen(str);
  20228. pthread_mutex_unlock(&lock_send);
  20229. lws_callback_on_writable(wsi_client);
  20230. lws_service(context, 0);
  20231. //sleep(1);
  20232. }