MessageHandler.c 992 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129
  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 getOccupancyFee(int gun_index)
  1365. {
  1366. struct timeval tmnow;
  1367. struct tm *tm;
  1368. char buf[28];//, usec_buf[6];
  1369. gettimeofday(&tmnow, NULL);
  1370. time_t t;
  1371. t = time(NULL);
  1372. /*UTC time and date*/
  1373. tm = gmtime(&t);
  1374. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1375. #if 0 // remove temporally
  1376. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1377. strcat(buf,".");
  1378. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1379. strcat(buf,usec_buf);
  1380. #endif
  1381. json_object *dataBuf = json_object_new_object();
  1382. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1383. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_GetOccupancyFee");
  1384. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1385. json_object_object_add(dataBuf, "occupancySN", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[gun_index].occupancySN));
  1386. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1387. json_object_put(dataBuf);
  1388. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1389. }
  1390. //==========================================
  1391. // Check time passed since today
  1392. //==========================================
  1393. long long DiffTimebWithNow(struct timeb ST)
  1394. {
  1395. //return milli-second
  1396. struct timeb ET;
  1397. long long StartTime,StopTime;
  1398. ftime(&ET);
  1399. StartTime=(long long)ST.time;
  1400. StopTime=(long long)ET.time;
  1401. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1402. }
  1403. int getTimePassSinceToday(uint8_t gun_index)
  1404. {
  1405. int result = -1;
  1406. static time_t lastTime[4];
  1407. time_t t;
  1408. struct tm *tmStartToday;
  1409. struct timeb tbStartToday;
  1410. t=time(NULL);
  1411. if(difftime(t, lastTime[gun_index])>0)
  1412. {
  1413. tmStartToday=localtime(&t);
  1414. tmStartToday->tm_hour = 0;
  1415. tmStartToday->tm_min = 0;
  1416. tmStartToday->tm_sec = 0;
  1417. tbStartToday.time = mktime(tmStartToday);
  1418. tbStartToday.millitm = 0;
  1419. result = DiffTimebWithNow(tbStartToday)/1000;
  1420. lastTime[gun_index] = t;
  1421. }
  1422. return result;
  1423. }
  1424. void getNowDatetime(uint8_t *data)
  1425. {
  1426. time_t t = time(NULL);
  1427. struct tm tm = *localtime(&t);
  1428. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1429. }
  1430. int syncDateTimeRTC(uint8_t *data)
  1431. {
  1432. struct ParsingResult
  1433. {
  1434. int result;
  1435. int scanedElement;
  1436. int year;
  1437. int month;
  1438. int mday;
  1439. int hour;
  1440. int min;
  1441. int sec;
  1442. int tz_hour;
  1443. int tz_min;
  1444. float minSec;
  1445. }result;
  1446. struct tm tmOrg;
  1447. struct tm *tmTarget;
  1448. struct timeb tbTarget;
  1449. char buf[128];
  1450. memset(&result, 0x00, sizeof(struct ParsingResult));
  1451. result.result = PASS;
  1452. if(strstr((char*)data, ".") != NULL)
  1453. {
  1454. // Original data with mini second
  1455. if(strstr((char*)data, "Z") != NULL)
  1456. {
  1457. // Original data with Z
  1458. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1459. &result.year,
  1460. &result.month,
  1461. &result.mday,
  1462. &result.hour,
  1463. &result.min,
  1464. &result.sec,
  1465. &result.minSec);
  1466. }
  1467. else
  1468. {
  1469. // Original data without Z
  1470. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1471. &result.year,
  1472. &result.month,
  1473. &result.mday,
  1474. &result.hour,
  1475. &result.min,
  1476. &result.sec,
  1477. &result.minSec,
  1478. &result.tz_hour,
  1479. &result.tz_min);
  1480. }
  1481. }
  1482. else
  1483. {
  1484. // Original data without mini second
  1485. if(strstr((char*)data, "Z") != NULL)
  1486. {
  1487. // Original data with Z
  1488. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1489. &result.year,
  1490. &result.month,
  1491. &result.mday,
  1492. &result.hour,
  1493. &result.min,
  1494. &result.sec);
  1495. }
  1496. else
  1497. {
  1498. // Original data without Z
  1499. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1500. &result.year,
  1501. &result.month,
  1502. &result.mday,
  1503. &result.hour,
  1504. &result.min,
  1505. &result.sec,
  1506. &result.tz_hour,
  1507. &result.tz_min);
  1508. }
  1509. }
  1510. tmOrg.tm_year = result.year - 1900;
  1511. tmOrg.tm_mon = result.month - 1;
  1512. tmOrg.tm_mday = result.mday;
  1513. tmOrg.tm_hour = result.hour;
  1514. tmOrg.tm_min = result.min;
  1515. tmOrg.tm_sec = result.sec;
  1516. tmOrg.tm_gmtoff = 0;
  1517. tbTarget.time = mktime(&tmOrg);
  1518. tbTarget.timezone = 0;
  1519. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1520. tmTarget = gmtime(&tbTarget.time);
  1521. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1522. //DEBUG_INFO(" org date time: %s\n", data);
  1523. //DEBUG_INFO("parse date time: %s\n", buf);
  1524. system(buf);
  1525. system("/sbin/hwclock -w --systohc");
  1526. if(result.scanedElement < 6)
  1527. result.result = FAIL;
  1528. return result.result;
  1529. }
  1530. //==========================================
  1531. // Parse certificate content
  1532. //==========================================
  1533. int parseCertInfo(char *certPath, int parseType, char *data)
  1534. {
  1535. int result = FAIL;
  1536. int count = 0;
  1537. int showupLine = 0;
  1538. memset(data, 0, ARRAY_SIZE(data));
  1539. if(access(certPath,F_OK) != -1)
  1540. {
  1541. char temp[512] = {0};
  1542. char capturedData[256] = {0};
  1543. char hashType[10] = "SHA256";
  1544. FILE *fp;
  1545. // Need to get hash type first
  1546. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1547. fp = popen(temp, "r");
  1548. if(fp)
  1549. {
  1550. while(fgets(temp, sizeof(temp), fp) != NULL)
  1551. {
  1552. if(strstr(temp, "Signature Algorithm:") != NULL)
  1553. {
  1554. result = PASS;
  1555. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1556. sprintf((char*)hashType, "SHA256");
  1557. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1558. sprintf((char*)hashType, "SHA384");
  1559. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1560. sprintf((char*)hashType, "SHA512");
  1561. else
  1562. {
  1563. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1564. result = FAIL;
  1565. }
  1566. break;
  1567. }
  1568. }
  1569. }
  1570. switch(parseType)
  1571. {
  1572. case CERT_PARSE_HashAlgorithm:
  1573. sprintf((char*)data, hashType);
  1574. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1575. break;
  1576. case CERT_PARSE_SerialNumber:
  1577. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1578. fp = popen(temp, "r");
  1579. if(fp)
  1580. {
  1581. while(fgets(temp, sizeof(temp), fp) != NULL)
  1582. {
  1583. if(strstr(temp, "serial=") != NULL)
  1584. {
  1585. sscanf(temp, "%*[^=]=%s", capturedData);
  1586. result = PASS;
  1587. break;
  1588. }
  1589. }
  1590. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1591. sprintf((char*)data, capturedData);
  1592. }
  1593. break;
  1594. case CERT_PARSE_IssuerNameHash:
  1595. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1596. fp = popen(temp, "r");
  1597. if(fp)
  1598. {
  1599. while(fgets(temp, sizeof(temp), fp) != NULL)
  1600. {
  1601. if(strstr(temp, "SEQUENCE") != NULL)
  1602. {
  1603. count++;
  1604. if(count==4)
  1605. {
  1606. sscanf(temp, "%[^:]", capturedData);
  1607. showupLine = atoi(capturedData);
  1608. break;
  1609. }
  1610. }
  1611. }
  1612. }
  1613. if(showupLine > 0)
  1614. {
  1615. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerNameHash", certPath, showupLine);
  1616. system(temp);
  1617. }
  1618. else
  1619. {
  1620. break;
  1621. }
  1622. if(access("/Storage/OCPP/IssuerNameHash",F_OK) != -1)
  1623. {
  1624. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerNameHash", (char*)hashType);
  1625. fp = popen(temp, "r");
  1626. if(fp)
  1627. {
  1628. while(fgets(temp, sizeof(temp), fp) != NULL)
  1629. {
  1630. if(strstr(temp, "(stdin)=") != NULL)
  1631. {
  1632. sscanf(temp, "%*[^=]=%s", capturedData);
  1633. result = PASS;
  1634. break;
  1635. }
  1636. }
  1637. stringtrimspace(capturedData);
  1638. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1639. sprintf((char*)data, capturedData);
  1640. }
  1641. }
  1642. break;
  1643. case CERT_PARSE_IssuerKeyHash:
  1644. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1645. fp = popen(temp, "r");
  1646. if(fp)
  1647. {
  1648. while(fgets(temp, sizeof(temp), fp) != NULL)
  1649. {
  1650. if(strstr(temp, "BIT STRING") != NULL)
  1651. {
  1652. sscanf(temp, "%[^:]", capturedData);
  1653. showupLine = atoi(capturedData);
  1654. break;
  1655. }
  1656. }
  1657. }
  1658. if(showupLine > 0)
  1659. {
  1660. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerKeyHash", certPath, showupLine);
  1661. system(temp);
  1662. }
  1663. else
  1664. {
  1665. break;
  1666. }
  1667. if(access("/Storage/OCPP/IssuerKeyHash",F_OK) != -1)
  1668. {
  1669. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerKeyHash", (char*)hashType);
  1670. fp = popen(temp, "r");
  1671. if(fp)
  1672. {
  1673. while(fgets(temp, sizeof(temp), fp) != NULL)
  1674. {
  1675. if(strstr(temp, "(stdin)=") != NULL)
  1676. {
  1677. sscanf(temp, "%*[^=]=%s", capturedData);
  1678. result = PASS;
  1679. break;
  1680. }
  1681. }
  1682. stringtrimspace(capturedData);
  1683. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1684. sprintf((char*)data, capturedData);
  1685. }
  1686. }
  1687. break;
  1688. case CERT_PARSE_OcspUrl:
  1689. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1690. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1691. fp = popen(temp, "r");
  1692. if(fp)
  1693. {
  1694. while(fgets(temp, sizeof(temp), fp) != NULL)
  1695. {
  1696. if(strstr(temp, "OCSP - URI:") != NULL)
  1697. {
  1698. //strcpy((char*)data, temp);
  1699. sscanf(temp, "%*[^:]:%s", capturedData);
  1700. sprintf((char*)data, capturedData);
  1701. DEBUG_INFO("OCSP_URI: %s\n", data);
  1702. result = PASS;
  1703. break;
  1704. }
  1705. }
  1706. }
  1707. break;
  1708. default:
  1709. DEBUG_INFO("Parse type is invalid.\n");
  1710. break;
  1711. }
  1712. pclose(fp);
  1713. }
  1714. return result;
  1715. }
  1716. //==========================================
  1717. // GetCompositeSchedule logic related function
  1718. //==========================================
  1719. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1720. {
  1721. //return milli-second
  1722. unsigned int StartTime,StopTime;
  1723. StartTime=(unsigned int)ST.time;
  1724. StopTime=(unsigned int)ET.time;
  1725. return (StopTime-StartTime);
  1726. }
  1727. int DiffTimebWithNowSec(struct timeb ST)
  1728. {
  1729. //return milli-second
  1730. struct timeb ET;
  1731. unsigned int StartTime,StopTime;
  1732. ftime(&ET);
  1733. StartTime=(unsigned int)ST.time;
  1734. StopTime=(unsigned int)ET.time;
  1735. return (StopTime-StartTime);
  1736. }
  1737. int getStartStop(uint8_t *start, uint8_t *stop)
  1738. {
  1739. struct ParsingResult
  1740. {
  1741. int result;
  1742. int scanedElement;
  1743. int year;
  1744. int month;
  1745. int mday;
  1746. int hour;
  1747. int min;
  1748. int sec;
  1749. int tz_hour;
  1750. int tz_min;
  1751. float minSec;
  1752. };
  1753. struct ParsingResult parseStart;
  1754. struct ParsingResult parseStop;
  1755. int result = -1;
  1756. struct tm tmStart;
  1757. struct timeb tbStart;
  1758. struct tm tmStop;
  1759. struct timeb tbStop;
  1760. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1761. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1762. // Scan start & stop date time
  1763. if(strstr((char*)start, ".") != NULL)
  1764. {
  1765. // Original data with mini second
  1766. if(strstr((char*)start, "Z") != NULL)
  1767. {
  1768. // Original data with Z
  1769. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1770. &parseStart.year,
  1771. &parseStart.month,
  1772. &parseStart.mday,
  1773. &parseStart.hour,
  1774. &parseStart.min,
  1775. &parseStart.sec,
  1776. &parseStart.minSec);
  1777. }
  1778. else
  1779. {
  1780. // Original data without Z
  1781. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1782. &parseStart.year,
  1783. &parseStart.month,
  1784. &parseStart.mday,
  1785. &parseStart.hour,
  1786. &parseStart.min,
  1787. &parseStart.sec,
  1788. &parseStart.minSec,
  1789. &parseStart.tz_hour,
  1790. &parseStart.tz_min);
  1791. }
  1792. }
  1793. else
  1794. {
  1795. // Original data without mini second
  1796. if(strstr((char*)start, "Z") != NULL)
  1797. {
  1798. // Original data with Z
  1799. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1800. &parseStart.year,
  1801. &parseStart.month,
  1802. &parseStart.mday,
  1803. &parseStart.hour,
  1804. &parseStart.min,
  1805. &parseStart.sec);
  1806. }
  1807. else
  1808. {
  1809. // Original data without Z
  1810. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1811. &parseStart.year,
  1812. &parseStart.month,
  1813. &parseStart.mday,
  1814. &parseStart.hour,
  1815. &parseStart.min,
  1816. &parseStart.sec,
  1817. &parseStart.tz_hour,
  1818. &parseStart.tz_min);
  1819. }
  1820. }
  1821. if(strstr((char*)stop, ".") != NULL)
  1822. {
  1823. // Original data with mini second
  1824. if(strstr((char*)stop, "Z") != NULL)
  1825. {
  1826. // Original data with Z
  1827. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1828. &parseStop.year,
  1829. &parseStop.month,
  1830. &parseStop.mday,
  1831. &parseStop.hour,
  1832. &parseStop.min,
  1833. &parseStop.sec,
  1834. &parseStop.minSec);
  1835. }
  1836. else
  1837. {
  1838. // Original data without Z
  1839. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1840. &parseStop.year,
  1841. &parseStop.month,
  1842. &parseStop.mday,
  1843. &parseStop.hour,
  1844. &parseStop.min,
  1845. &parseStop.sec,
  1846. &parseStop.minSec,
  1847. &parseStop.tz_hour,
  1848. &parseStop.tz_min);
  1849. }
  1850. }
  1851. else
  1852. {
  1853. // Original data without mini second
  1854. if(strstr((char*)stop, "Z") != NULL)
  1855. {
  1856. // Original data with Z
  1857. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1858. &parseStop.year,
  1859. &parseStop.month,
  1860. &parseStop.mday,
  1861. &parseStop.hour,
  1862. &parseStop.min,
  1863. &parseStop.sec);
  1864. }
  1865. else
  1866. {
  1867. // Original data without Z
  1868. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1869. &parseStop.year,
  1870. &parseStop.month,
  1871. &parseStop.mday,
  1872. &parseStop.hour,
  1873. &parseStop.min,
  1874. &parseStop.sec,
  1875. &parseStop.tz_hour,
  1876. &parseStop.tz_min);
  1877. }
  1878. }
  1879. // Calculate date time difference
  1880. if((parseStart.scanedElement >=6) &&
  1881. (parseStop.scanedElement >=6))
  1882. {
  1883. //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);
  1884. //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);
  1885. tmStart.tm_year = parseStart.year - 1900;
  1886. tmStart.tm_mon = parseStart.month - 1;
  1887. tmStart.tm_mday = parseStart.mday;
  1888. tmStart.tm_hour = parseStart.hour;
  1889. tmStart.tm_min = parseStart.min;
  1890. tmStart.tm_sec = parseStart.sec;
  1891. tmStart.tm_gmtoff = 0;
  1892. tbStart.time = mktime(&tmStart);
  1893. tbStart.timezone = 0;
  1894. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1895. tmStop.tm_year = parseStop.year - 1900;
  1896. tmStop.tm_mon = parseStop.month - 1;
  1897. tmStop.tm_mday = parseStop.mday;
  1898. tmStop.tm_hour = parseStop.hour;
  1899. tmStop.tm_min = parseStop.min;
  1900. tmStop.tm_sec = parseStop.sec;
  1901. tmStop.tm_gmtoff = 0;
  1902. tbStop.time = mktime(&tmStop);
  1903. tbStop.timezone = 0;
  1904. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1905. result = DiffTimebSec(tbStart, tbStop);
  1906. //DEBUG_INFO("getStartStop(): %d\n", result);
  1907. }
  1908. else
  1909. {
  1910. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1911. }
  1912. return result;
  1913. }
  1914. int isOvertNow(uint8_t *start)
  1915. {
  1916. int result = NO;
  1917. struct ParsingResult
  1918. {
  1919. int result;
  1920. int scanedElement;
  1921. int year;
  1922. int month;
  1923. int mday;
  1924. int hour;
  1925. int min;
  1926. int sec;
  1927. int tz_hour;
  1928. int tz_min;
  1929. float minSec;
  1930. }parsingResult;
  1931. struct tm tmStart;
  1932. struct timeb tbStart;
  1933. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1934. if(strstr((char*)start, ".") != NULL)
  1935. {
  1936. // Original data with mini second
  1937. if(strstr((char*)start, "Z") != NULL)
  1938. {
  1939. // Original data with Z
  1940. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1941. &parsingResult.year,
  1942. &parsingResult.month,
  1943. &parsingResult.mday,
  1944. &parsingResult.hour,
  1945. &parsingResult.min,
  1946. &parsingResult.sec,
  1947. &parsingResult.minSec);
  1948. }
  1949. else
  1950. {
  1951. // Original data without Z
  1952. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1953. &parsingResult.year,
  1954. &parsingResult.month,
  1955. &parsingResult.mday,
  1956. &parsingResult.hour,
  1957. &parsingResult.min,
  1958. &parsingResult.sec,
  1959. &parsingResult.minSec,
  1960. &parsingResult.tz_hour,
  1961. &parsingResult.tz_min);
  1962. }
  1963. }
  1964. else
  1965. {
  1966. // Original data without mini second
  1967. if(strstr((char*)start, "Z") != NULL)
  1968. {
  1969. // Original data with Z
  1970. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1971. &parsingResult.year,
  1972. &parsingResult.month,
  1973. &parsingResult.mday,
  1974. &parsingResult.hour,
  1975. &parsingResult.min,
  1976. &parsingResult.sec);
  1977. }
  1978. else
  1979. {
  1980. // Original data without Z
  1981. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1982. &parsingResult.year,
  1983. &parsingResult.month,
  1984. &parsingResult.mday,
  1985. &parsingResult.hour,
  1986. &parsingResult.min,
  1987. &parsingResult.sec,
  1988. &parsingResult.tz_hour,
  1989. &parsingResult.tz_min);
  1990. }
  1991. }
  1992. if(parsingResult.scanedElement >= 6)
  1993. {
  1994. tmStart.tm_year = parsingResult.year - 1900;
  1995. tmStart.tm_mon = parsingResult.month - 1;
  1996. tmStart.tm_mday = parsingResult.mday;
  1997. tmStart.tm_hour = parsingResult.hour;
  1998. tmStart.tm_min = parsingResult.min;
  1999. tmStart.tm_sec = parsingResult.sec;
  2000. tmStart.tm_gmtoff = 0;
  2001. tbStart.time = mktime(&tmStart);
  2002. tbStart.timezone = 0;
  2003. tbStart.millitm = 0;
  2004. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  2005. if(DiffTimebWithNowSec(tbStart) <= 0)
  2006. result = NO;
  2007. else
  2008. result = YES;
  2009. }
  2010. else
  2011. {
  2012. DEBUG_WARN("Start date parsing error.\n");
  2013. }
  2014. return result;
  2015. }
  2016. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2017. {
  2018. struct ParsingResult
  2019. {
  2020. int result;
  2021. int scanedElement;
  2022. int year;
  2023. int month;
  2024. int mday;
  2025. int hour;
  2026. int min;
  2027. int sec;
  2028. int tz_hour;
  2029. int tz_min;
  2030. float minSec;
  2031. };
  2032. struct ParsingResult parseStart;
  2033. struct ParsingResult parseStop;
  2034. int result = -1;
  2035. struct tm tmStart;
  2036. struct timeb tbStart;
  2037. struct tm tmStop;
  2038. struct timeb tbStop;
  2039. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  2040. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  2041. // Scan start & stop date time
  2042. if(strstr((char*)start, ".") != NULL)
  2043. {
  2044. // Original data with mini second
  2045. if(strstr((char*)start, "Z") != NULL)
  2046. {
  2047. // Original data with Z
  2048. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  2049. &parseStart.year,
  2050. &parseStart.month,
  2051. &parseStart.mday,
  2052. &parseStart.hour,
  2053. &parseStart.min,
  2054. &parseStart.sec,
  2055. &parseStart.minSec);
  2056. }
  2057. else
  2058. {
  2059. // Original data without Z
  2060. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2061. &parseStart.year,
  2062. &parseStart.month,
  2063. &parseStart.mday,
  2064. &parseStart.hour,
  2065. &parseStart.min,
  2066. &parseStart.sec,
  2067. &parseStart.minSec,
  2068. &parseStart.tz_hour,
  2069. &parseStart.tz_min);
  2070. }
  2071. }
  2072. else
  2073. {
  2074. // Original data without mini second
  2075. if(strstr((char*)start, "Z") != NULL)
  2076. {
  2077. // Original data with Z
  2078. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  2079. &parseStart.year,
  2080. &parseStart.month,
  2081. &parseStart.mday,
  2082. &parseStart.hour,
  2083. &parseStart.min,
  2084. &parseStart.sec);
  2085. }
  2086. else
  2087. {
  2088. // Original data without Z
  2089. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  2090. &parseStart.year,
  2091. &parseStart.month,
  2092. &parseStart.mday,
  2093. &parseStart.hour,
  2094. &parseStart.min,
  2095. &parseStart.sec,
  2096. &parseStart.tz_hour,
  2097. &parseStart.tz_min);
  2098. }
  2099. }
  2100. if(strstr((char*)stop, ".") != NULL)
  2101. {
  2102. // Original data with mini second
  2103. if(strstr((char*)stop, "Z") != NULL)
  2104. {
  2105. // Original data with Z
  2106. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  2107. &parseStop.year,
  2108. &parseStop.month,
  2109. &parseStop.mday,
  2110. &parseStop.hour,
  2111. &parseStop.min,
  2112. &parseStop.sec,
  2113. &parseStop.minSec);
  2114. }
  2115. else
  2116. {
  2117. // Original data without Z
  2118. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2119. &parseStop.year,
  2120. &parseStop.month,
  2121. &parseStop.mday,
  2122. &parseStop.hour,
  2123. &parseStop.min,
  2124. &parseStop.sec,
  2125. &parseStop.minSec,
  2126. &parseStop.tz_hour,
  2127. &parseStop.tz_min);
  2128. }
  2129. }
  2130. else
  2131. {
  2132. // Original data without mini second
  2133. if(strstr((char*)stop, "Z") != NULL)
  2134. {
  2135. // Original data with Z
  2136. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  2137. &parseStop.year,
  2138. &parseStop.month,
  2139. &parseStop.mday,
  2140. &parseStop.hour,
  2141. &parseStop.min,
  2142. &parseStop.sec);
  2143. }
  2144. else
  2145. {
  2146. // Original data without Z
  2147. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  2148. &parseStop.year,
  2149. &parseStop.month,
  2150. &parseStop.mday,
  2151. &parseStop.hour,
  2152. &parseStop.min,
  2153. &parseStop.sec,
  2154. &parseStop.tz_hour,
  2155. &parseStop.tz_min);
  2156. }
  2157. }
  2158. // Calculate date time difference
  2159. if((parseStart.scanedElement >=6) &&
  2160. (parseStop.scanedElement >=6))
  2161. {
  2162. //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);
  2163. //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);
  2164. tmStart.tm_year = parseStart.year - 1900;
  2165. tmStart.tm_mon = parseStart.month - 1;
  2166. tmStart.tm_mday = parseStart.mday;
  2167. tmStart.tm_hour = parseStart.hour;
  2168. tmStart.tm_min = parseStart.min;
  2169. tmStart.tm_sec = parseStart.sec;
  2170. tmStart.tm_gmtoff = 0;
  2171. tbStart.time = mktime(&tmStart);
  2172. tbStart.timezone = 0;
  2173. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  2174. tmStop.tm_year = parseStop.year - 1900;
  2175. tmStop.tm_mon = parseStop.month - 1;
  2176. tmStop.tm_mday = parseStop.mday;
  2177. tmStop.tm_hour = parseStop.hour;
  2178. tmStop.tm_min = parseStop.min;
  2179. tmStop.tm_sec = parseStop.sec;
  2180. tmStop.tm_gmtoff = 0;
  2181. tbStop.time = mktime(&tmStop);
  2182. tbStop.timezone = 0;
  2183. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  2184. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2185. //DEBUG_INFO("getStartStop(): %d\n", result);
  2186. }
  2187. else
  2188. {
  2189. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2190. }
  2191. return result;
  2192. }
  2193. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2194. {
  2195. FILE *fp;
  2196. char profileFileName[128];
  2197. char *line = NULL;
  2198. size_t len = 0;
  2199. time_t CurrentTime;
  2200. struct tm *tmComposite;
  2201. struct StructChargingProfile maxProfile;
  2202. struct StructChargingProfile compositeProfile;
  2203. uint8_t limitMax=0;
  2204. int compositePeriodIdx = 0;
  2205. //uint8_t isDurationNull = FALSE;
  2206. CurrentTime = time(NULL);
  2207. tmComposite=localtime(&CurrentTime);
  2208. 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);
  2209. if(isUnitA)
  2210. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2211. else
  2212. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2213. compositeProfile.ChargingSchedule.Duration = durationReq;
  2214. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2215. {
  2216. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2217. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2218. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2219. }
  2220. compositeProfile.ChargingProfileId = 0;
  2221. compositeProfile.StackLevel = 99 ;
  2222. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2223. maxProfile.ChargingProfileId = -1;
  2224. maxProfile.ChargingSchedule.Duration = -1;
  2225. system("rm -f /tmp/*.json");
  2226. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2227. // Search max profile
  2228. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2229. if((access(profileFileName, F_OK))!=-1)
  2230. {
  2231. fp = fopen(profileFileName, "r");
  2232. while(getline(&line, &len, fp) != -1)
  2233. {
  2234. json_object *obj = NULL;
  2235. obj = json_tokener_parse(line);
  2236. if(is_error(obj))
  2237. {
  2238. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2239. }
  2240. else
  2241. {
  2242. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2243. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2244. )
  2245. {
  2246. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2247. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2248. )
  2249. {
  2250. struct tm tmFrom, tmTo;
  2251. struct timeb tbFrom, tbTo;
  2252. 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) &&
  2253. (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))
  2254. {
  2255. tmFrom.tm_year -= 1900;
  2256. tmFrom.tm_mon -= 1;
  2257. tbFrom.time = mktime(&tmFrom);
  2258. tmTo.tm_year -= 1900;
  2259. tmTo.tm_mon -= 1;
  2260. tbTo.time = mktime(&tmTo);
  2261. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2262. {
  2263. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2264. {
  2265. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2266. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2267. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2268. }
  2269. if(maxProfile.ChargingProfileId == -1)
  2270. DEBUG_INFO("MaxProfile found.\n");
  2271. else
  2272. DEBUG_INFO("MaxProfile updated.\n");
  2273. // Required item
  2274. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2275. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2276. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2277. if(isUnitA)
  2278. {
  2279. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2280. 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++)
  2281. {
  2282. 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"));
  2283. 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?
  2284. 3:
  2285. 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")));
  2286. 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")));
  2287. }
  2288. }
  2289. else
  2290. {
  2291. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2292. 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++)
  2293. {
  2294. 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"));
  2295. 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?
  2296. 3:
  2297. 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")));
  2298. 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));
  2299. }
  2300. }
  2301. // Optional item
  2302. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2303. {
  2304. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2305. }
  2306. else
  2307. {
  2308. sprintf((char*)maxProfile.ValidFrom, " ");
  2309. }
  2310. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2311. {
  2312. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2313. }
  2314. else
  2315. {
  2316. sprintf((char*)maxProfile.ValidTo, " ");
  2317. }
  2318. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2319. {
  2320. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2321. }
  2322. else
  2323. {
  2324. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2325. }
  2326. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2327. {
  2328. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2329. }
  2330. else
  2331. {
  2332. maxProfile.TransactionId = -1;
  2333. }
  2334. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2335. {
  2336. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2337. }
  2338. else
  2339. {
  2340. maxProfile.ChargingSchedule.Duration = 86400;
  2341. //isDurationNull = TRUE;
  2342. }
  2343. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2344. {
  2345. 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")));
  2346. }
  2347. else
  2348. {
  2349. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2350. }
  2351. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2352. {
  2353. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2354. }
  2355. else
  2356. {
  2357. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2358. }
  2359. }
  2360. }
  2361. }
  2362. else
  2363. {
  2364. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2365. {
  2366. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2367. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2368. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2369. }
  2370. if(maxProfile.ChargingProfileId == -1)
  2371. DEBUG_INFO("MaxProfile found.\n");
  2372. else
  2373. DEBUG_INFO("MaxProfile updated.\n");
  2374. // Required item
  2375. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2376. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2377. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2378. if(isUnitA)
  2379. {
  2380. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2381. 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++)
  2382. {
  2383. 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"));
  2384. 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?
  2385. 3:
  2386. 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")));
  2387. 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")));
  2388. }
  2389. }
  2390. else
  2391. {
  2392. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2393. 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++)
  2394. {
  2395. 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"));
  2396. 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?
  2397. 3:
  2398. 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")));
  2399. 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));
  2400. }
  2401. }
  2402. // Optional item
  2403. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2404. {
  2405. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2406. }
  2407. else
  2408. {
  2409. sprintf((char*)maxProfile.ValidFrom, " ");
  2410. }
  2411. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2412. {
  2413. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2414. }
  2415. else
  2416. {
  2417. sprintf((char*)maxProfile.ValidTo, " ");
  2418. }
  2419. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2420. {
  2421. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2422. }
  2423. else
  2424. {
  2425. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2426. }
  2427. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2428. {
  2429. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2430. }
  2431. else
  2432. {
  2433. maxProfile.TransactionId = -1;
  2434. }
  2435. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2436. {
  2437. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2438. }
  2439. else
  2440. {
  2441. maxProfile.ChargingSchedule.Duration = 86400;
  2442. //isDurationNull = TRUE;
  2443. }
  2444. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2445. {
  2446. 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")));
  2447. }
  2448. else
  2449. {
  2450. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2451. }
  2452. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2453. {
  2454. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2455. }
  2456. else
  2457. {
  2458. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2459. }
  2460. }
  2461. }
  2462. }
  2463. json_object_put(obj);
  2464. }
  2465. fclose(fp);
  2466. /*
  2467. if(maxProfile.ChargingProfileId !=-1)
  2468. {
  2469. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2470. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2471. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2472. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2473. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2474. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2475. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2476. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2477. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2478. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2479. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2480. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2481. {
  2482. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2483. {
  2484. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2485. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2486. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2487. }
  2488. }
  2489. }
  2490. else
  2491. DEBUG_INFO("MaxProfile not found.\n");
  2492. DEBUG_INFO("------------------------------------\n");*/
  2493. }
  2494. if(maxProfile.ChargingProfileId != -1)
  2495. {
  2496. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2497. {
  2498. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2499. {
  2500. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2501. 0:
  2502. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2503. }
  2504. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2505. {
  2506. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2507. {
  2508. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2509. 0:
  2510. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2511. if(idxPeriod > 0)
  2512. {
  2513. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2514. {
  2515. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2522. {
  2523. if(maxProfile.ChargingSchedule.Duration != -1)
  2524. {
  2525. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2526. }
  2527. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2528. {
  2529. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2530. {
  2531. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2532. if(idxPeriod > 0)
  2533. {
  2534. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2535. {
  2536. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2537. }
  2538. }
  2539. }
  2540. }
  2541. }
  2542. else
  2543. {
  2544. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2545. {
  2546. if(maxProfile.ChargingSchedule.Duration != -1)
  2547. {
  2548. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2549. 0:
  2550. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2551. }
  2552. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2553. {
  2554. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2555. {
  2556. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2557. 0:
  2558. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2559. if(idxPeriod > 0)
  2560. {
  2561. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2562. {
  2563. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2564. }
  2565. }
  2566. }
  2567. }
  2568. }
  2569. else
  2570. {
  2571. if(maxProfile.ChargingSchedule.Duration != -1)
  2572. {
  2573. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2574. 0:
  2575. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2576. }
  2577. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2578. {
  2579. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2580. {
  2581. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2582. 0:
  2583. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2584. if(idxPeriod > 0)
  2585. {
  2586. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2587. {
  2588. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2589. }
  2590. }
  2591. }
  2592. }
  2593. }
  2594. }
  2595. /*
  2596. DEBUG_INFO("MaxProfile after align.\n");
  2597. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2598. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2599. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2600. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2601. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2602. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2603. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2604. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2605. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2606. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2607. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2608. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2609. {
  2610. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2611. {
  2612. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2613. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2614. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2615. }
  2616. }
  2617. DEBUG_INFO("------------------------------------\n");*/
  2618. }
  2619. // Find each profile period quantity
  2620. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2621. {
  2622. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2623. limitMax = idx+1;
  2624. }
  2625. if(maxProfile.ChargingProfileId != -1)
  2626. {
  2627. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2628. {
  2629. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2630. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2631. (maxProfile.ChargingSchedule.Duration > 0))
  2632. {
  2633. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2634. {
  2635. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2636. compositePeriodIdx++;
  2637. }
  2638. else
  2639. {
  2640. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2641. }
  2642. }
  2643. }
  2644. }
  2645. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2646. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2647. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2648. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2649. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2650. {
  2651. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2652. {
  2653. compositeProfile.ChargingProfileId = 1;
  2654. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2655. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2656. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2657. }
  2658. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2659. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2660. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2661. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2662. }
  2663. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2664. if(line)
  2665. free(line);
  2666. }
  2667. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2668. {
  2669. FILE *fp;
  2670. char profileFileName[128];
  2671. char *line = NULL;
  2672. size_t len = 0;
  2673. time_t CurrentTime;
  2674. struct tm *tmComposite;
  2675. struct StructChargingProfile maxProfile;
  2676. struct StructChargingProfile defaultTxProfile;
  2677. struct StructChargingProfile txProfile;
  2678. struct StructChargingProfile compositeProfile;
  2679. struct StructChargingSchedulePeriod tmpPeriod;
  2680. uint8_t limitMax=0;
  2681. uint8_t limitDef=0;
  2682. uint8_t limitTx=0;
  2683. int compositePeriodIdx = 0;
  2684. CurrentTime = time(NULL);
  2685. tmComposite=localtime(&CurrentTime);
  2686. 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);
  2687. if(isUnitA)
  2688. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2689. else
  2690. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2691. compositeProfile.ChargingSchedule.Duration = durationReq;
  2692. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2693. {
  2694. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2695. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2696. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2697. }
  2698. compositeProfile.ChargingProfileId = 0;
  2699. compositeProfile.StackLevel = 99 ;
  2700. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2701. maxProfile.ChargingProfileId = -1;
  2702. defaultTxProfile.ChargingProfileId = -1;
  2703. txProfile.ChargingProfileId = -1;
  2704. maxProfile.ChargingSchedule.Duration = -1;
  2705. defaultTxProfile.ChargingSchedule.Duration = -1;
  2706. txProfile.ChargingSchedule.Duration = -1;
  2707. system("rm -f /tmp/*.json");
  2708. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2709. /*
  2710. * Search valid charging profile
  2711. */
  2712. //DEBUG_INFO("====================================\n");
  2713. // Search tx profile
  2714. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2715. if((access(profileFileName, F_OK))!=-1)
  2716. {
  2717. fp = fopen(profileFileName, "r");
  2718. while(getline(&line, &len, fp) != -1)
  2719. {
  2720. json_object *obj = NULL;
  2721. obj = json_tokener_parse(line);
  2722. if(is_error(obj))
  2723. {
  2724. DEBUG_ERROR("Parse txProfile from file error.\n");
  2725. }
  2726. else
  2727. {
  2728. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2729. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2730. )
  2731. {
  2732. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2733. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2734. )
  2735. {
  2736. struct tm tmFrom, tmTo;
  2737. struct timeb tbFrom, tbTo;
  2738. 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) &&
  2739. (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))
  2740. {
  2741. tmFrom.tm_year -= 1900;
  2742. tmFrom.tm_mon -= 1;
  2743. tbFrom.time = mktime(&tmFrom);
  2744. tmTo.tm_year -= 1900;
  2745. tmTo.tm_mon -= 1;
  2746. tbTo.time = mktime(&tmTo);
  2747. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2748. {
  2749. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2750. {
  2751. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2752. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2754. }
  2755. if(txProfile.ChargingProfileId == -1)
  2756. DEBUG_INFO("TxProfile found.\n");
  2757. else
  2758. DEBUG_INFO("TxProfile updated.\n");
  2759. // Required item
  2760. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2761. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2762. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2763. if(isUnitA)
  2764. {
  2765. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2766. 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++)
  2767. {
  2768. 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"));
  2769. 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?
  2770. 3:
  2771. 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")));
  2772. 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")));
  2773. }
  2774. }
  2775. else
  2776. {
  2777. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2778. 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++)
  2779. {
  2780. 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"));
  2781. 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?
  2782. 3:
  2783. 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")));
  2784. 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));
  2785. }
  2786. }
  2787. // Optional item
  2788. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2789. {
  2790. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2791. }
  2792. else
  2793. {
  2794. sprintf((char*)txProfile.ValidFrom, " ");
  2795. }
  2796. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2797. {
  2798. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2799. }
  2800. else
  2801. {
  2802. sprintf((char*)txProfile.ValidTo, " ");
  2803. }
  2804. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2805. {
  2806. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2807. }
  2808. else
  2809. {
  2810. sprintf((char*)txProfile.RecurrencyKind, " ");
  2811. }
  2812. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2813. {
  2814. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2815. }
  2816. else
  2817. {
  2818. txProfile.TransactionId = -1;
  2819. }
  2820. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2821. {
  2822. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2823. }
  2824. else
  2825. {
  2826. txProfile.ChargingSchedule.Duration = 86400;
  2827. }
  2828. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2829. {
  2830. 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")));
  2831. }
  2832. else
  2833. {
  2834. 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));
  2835. }
  2836. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2837. {
  2838. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2839. }
  2840. else
  2841. {
  2842. txProfile.ChargingSchedule.MinChargingRate = -1;
  2843. }
  2844. }
  2845. }
  2846. }
  2847. else
  2848. {
  2849. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2850. {
  2851. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2852. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2853. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2854. }
  2855. if(txProfile.ChargingProfileId == -1)
  2856. DEBUG_INFO("TxProfile found.\n");
  2857. else
  2858. DEBUG_INFO("TxProfile updated.\n");
  2859. // Required item
  2860. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2861. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2862. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2863. if(isUnitA)
  2864. {
  2865. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2866. 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++)
  2867. {
  2868. 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"));
  2869. 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?
  2870. 3:
  2871. 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")));
  2872. 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")));
  2873. }
  2874. }
  2875. else
  2876. {
  2877. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2878. 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++)
  2879. {
  2880. 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"));
  2881. 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?
  2882. 3:
  2883. 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")));
  2884. 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));
  2885. }
  2886. }
  2887. // Optional item
  2888. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2889. {
  2890. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2891. }
  2892. else
  2893. {
  2894. sprintf((char*)txProfile.ValidFrom, " ");
  2895. }
  2896. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2897. {
  2898. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2899. }
  2900. else
  2901. {
  2902. sprintf((char*)txProfile.ValidTo, " ");
  2903. }
  2904. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2905. {
  2906. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2907. }
  2908. else
  2909. {
  2910. sprintf((char*)txProfile.RecurrencyKind, " ");
  2911. }
  2912. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2913. {
  2914. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2915. }
  2916. else
  2917. {
  2918. txProfile.TransactionId = -1;
  2919. }
  2920. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2921. {
  2922. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2923. }
  2924. else
  2925. {
  2926. txProfile.ChargingSchedule.Duration = 86400;
  2927. }
  2928. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2929. {
  2930. 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")));
  2931. }
  2932. else
  2933. {
  2934. 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));
  2935. }
  2936. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2937. {
  2938. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2939. }
  2940. else
  2941. {
  2942. txProfile.ChargingSchedule.MinChargingRate = -1;
  2943. }
  2944. }
  2945. }
  2946. }
  2947. json_object_put(obj);
  2948. }
  2949. fclose(fp);
  2950. /*
  2951. if(txProfile.ChargingProfileId != -1)
  2952. {
  2953. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2954. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2955. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2956. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2957. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2958. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2959. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2960. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2961. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2962. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2963. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2964. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2965. {
  2966. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2967. {
  2968. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2969. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2970. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2971. }
  2972. }
  2973. }
  2974. else
  2975. DEBUG_INFO("TxProfile not found.\n");*/
  2976. }
  2977. // Search default tx profile
  2978. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2979. if((access(profileFileName, F_OK))==-1)
  2980. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2981. if((access(profileFileName, F_OK))!=-1)
  2982. {
  2983. fp = fopen(profileFileName, "r");
  2984. while(getline(&line, &len, fp) != -1)
  2985. {
  2986. json_object *obj = NULL;
  2987. obj = json_tokener_parse(line);
  2988. if(is_error(obj))
  2989. {
  2990. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2991. }
  2992. else
  2993. {
  2994. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2995. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2996. )
  2997. {
  2998. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2999. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3000. )
  3001. {
  3002. struct tm tmFrom, tmTo;
  3003. struct timeb tbFrom, tbTo;
  3004. 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) &&
  3005. (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))
  3006. {
  3007. tmFrom.tm_year -= 1900;
  3008. tmFrom.tm_mon -= 1;
  3009. tbFrom.time = mktime(&tmFrom);
  3010. tmTo.tm_year -= 1900;
  3011. tmTo.tm_mon -= 1;
  3012. tbTo.time = mktime(&tmTo);
  3013. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3014. {
  3015. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3016. {
  3017. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3018. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3019. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3020. }
  3021. if(defaultTxProfile.ChargingProfileId == -1)
  3022. DEBUG_INFO("TxDefaultProfile found.\n");
  3023. else
  3024. DEBUG_INFO("TxDefaultProfile updated.\n");
  3025. // Required item
  3026. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3027. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3028. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3029. if(isUnitA)
  3030. {
  3031. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3032. 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++)
  3033. {
  3034. 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"));
  3035. 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?
  3036. 3:
  3037. 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")));
  3038. 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")));
  3039. }
  3040. }
  3041. else
  3042. {
  3043. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3044. 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++)
  3045. {
  3046. 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"));
  3047. 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?
  3048. 3:
  3049. 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")));
  3050. 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));
  3051. }
  3052. }
  3053. // Optional item
  3054. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3055. {
  3056. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3057. }
  3058. else
  3059. {
  3060. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3061. }
  3062. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3063. {
  3064. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3065. }
  3066. else
  3067. {
  3068. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3069. }
  3070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3071. {
  3072. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3073. }
  3074. else
  3075. {
  3076. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3077. }
  3078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3079. {
  3080. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3081. }
  3082. else
  3083. {
  3084. defaultTxProfile.TransactionId = -1;
  3085. }
  3086. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3087. {
  3088. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3089. }
  3090. else
  3091. {
  3092. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3093. }
  3094. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3095. {
  3096. 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")));
  3097. }
  3098. else
  3099. {
  3100. 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));
  3101. }
  3102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3103. {
  3104. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3105. }
  3106. else
  3107. {
  3108. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3109. }
  3110. }
  3111. }
  3112. }
  3113. else
  3114. {
  3115. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3116. {
  3117. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3118. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3119. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3120. }
  3121. if(defaultTxProfile.ChargingProfileId == -1)
  3122. DEBUG_INFO("TxDefaultProfile found.\n");
  3123. else
  3124. DEBUG_INFO("TxDefaultProfile updated.\n");
  3125. // Required item
  3126. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3127. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3128. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3129. if(isUnitA)
  3130. {
  3131. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3132. 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++)
  3133. {
  3134. 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"));
  3135. 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?
  3136. 3:
  3137. 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")));
  3138. 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")));
  3139. }
  3140. }
  3141. else
  3142. {
  3143. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3144. 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++)
  3145. {
  3146. 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"));
  3147. 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?
  3148. 3:
  3149. 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")));
  3150. 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));
  3151. }
  3152. }
  3153. // Optional item
  3154. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3155. {
  3156. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3157. }
  3158. else
  3159. {
  3160. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3161. }
  3162. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3163. {
  3164. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3165. }
  3166. else
  3167. {
  3168. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3169. }
  3170. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3171. {
  3172. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3173. }
  3174. else
  3175. {
  3176. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3177. }
  3178. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3179. {
  3180. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3181. }
  3182. else
  3183. {
  3184. defaultTxProfile.TransactionId = -1;
  3185. }
  3186. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3187. {
  3188. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3189. }
  3190. else
  3191. {
  3192. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3193. }
  3194. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3195. {
  3196. 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")));
  3197. }
  3198. else
  3199. {
  3200. 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));
  3201. }
  3202. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3203. {
  3204. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3205. }
  3206. else
  3207. {
  3208. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3209. }
  3210. }
  3211. }
  3212. }
  3213. json_object_put(obj);
  3214. }
  3215. fclose(fp);
  3216. /*
  3217. if(defaultTxProfile.ChargingProfileId != -1)
  3218. {
  3219. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3220. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3221. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3222. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3223. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3224. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3225. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3226. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  3227. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3228. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3229. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3230. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3231. {
  3232. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3233. {
  3234. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3235. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3236. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3237. }
  3238. }
  3239. }
  3240. else
  3241. DEBUG_INFO("TxDefaultProfile not found.\n");
  3242. DEBUG_INFO("------------------------------------\n");*/
  3243. }
  3244. // Search max profile
  3245. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3246. if((access(profileFileName, F_OK))!=-1)
  3247. {
  3248. fp = fopen(profileFileName, "r");
  3249. while(getline(&line, &len, fp) != -1)
  3250. {
  3251. json_object *obj = NULL;
  3252. obj = json_tokener_parse(line);
  3253. if(is_error(obj))
  3254. {
  3255. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3256. }
  3257. else
  3258. {
  3259. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3260. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3261. )
  3262. {
  3263. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3264. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3265. )
  3266. {
  3267. struct tm tmFrom, tmTo;
  3268. struct timeb tbFrom, tbTo;
  3269. 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) &&
  3270. (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))
  3271. {
  3272. tmFrom.tm_year -= 1900;
  3273. tmFrom.tm_mon -= 1;
  3274. tbFrom.time = mktime(&tmFrom);
  3275. tmTo.tm_year -= 1900;
  3276. tmTo.tm_mon -= 1;
  3277. tbTo.time = mktime(&tmTo);
  3278. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3279. {
  3280. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3281. {
  3282. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3283. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3285. }
  3286. if(maxProfile.ChargingProfileId == -1)
  3287. DEBUG_INFO("MaxProfile found.\n");
  3288. else
  3289. DEBUG_INFO("MaxProfile updated.\n");
  3290. // Required item
  3291. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3292. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3293. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3294. if(isUnitA)
  3295. {
  3296. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3297. 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++)
  3298. {
  3299. 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"));
  3300. 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?
  3301. 3:
  3302. 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")));
  3303. 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")));
  3304. }
  3305. }
  3306. else
  3307. {
  3308. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3309. 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++)
  3310. {
  3311. 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"));
  3312. 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?
  3313. 3:
  3314. 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")));
  3315. 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));
  3316. }
  3317. }
  3318. // Optional item
  3319. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3320. {
  3321. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3322. }
  3323. else
  3324. {
  3325. sprintf((char*)maxProfile.ValidFrom, " ");
  3326. }
  3327. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3328. {
  3329. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3330. }
  3331. else
  3332. {
  3333. sprintf((char*)maxProfile.ValidTo, " ");
  3334. }
  3335. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3336. {
  3337. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3338. }
  3339. else
  3340. {
  3341. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3342. }
  3343. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3344. {
  3345. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3346. }
  3347. else
  3348. {
  3349. maxProfile.TransactionId = -1;
  3350. }
  3351. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3352. {
  3353. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3354. }
  3355. else
  3356. {
  3357. maxProfile.ChargingSchedule.Duration = 86400;
  3358. }
  3359. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3360. {
  3361. 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")));
  3362. }
  3363. else
  3364. {
  3365. 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));
  3366. }
  3367. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3368. {
  3369. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3370. }
  3371. else
  3372. {
  3373. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3374. }
  3375. }
  3376. }
  3377. }
  3378. else
  3379. {
  3380. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3381. {
  3382. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3383. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3384. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3385. }
  3386. if(maxProfile.ChargingProfileId == -1)
  3387. DEBUG_INFO("MaxProfile found.\n");
  3388. else
  3389. DEBUG_INFO("MaxProfile updated.\n");
  3390. // Required item
  3391. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3392. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3393. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3394. if(isUnitA)
  3395. {
  3396. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3397. 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++)
  3398. {
  3399. 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"));
  3400. 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?
  3401. 3:
  3402. 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")));
  3403. 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")));
  3404. }
  3405. }
  3406. else
  3407. {
  3408. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3409. 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++)
  3410. {
  3411. 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"));
  3412. 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?
  3413. 3:
  3414. 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")));
  3415. 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));
  3416. }
  3417. }
  3418. // Optional item
  3419. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3420. {
  3421. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3422. }
  3423. else
  3424. {
  3425. sprintf((char*)maxProfile.ValidFrom, " ");
  3426. }
  3427. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3428. {
  3429. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3430. }
  3431. else
  3432. {
  3433. sprintf((char*)maxProfile.ValidTo, " ");
  3434. }
  3435. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3436. {
  3437. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3438. }
  3439. else
  3440. {
  3441. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3442. }
  3443. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3444. {
  3445. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3446. }
  3447. else
  3448. {
  3449. maxProfile.TransactionId = -1;
  3450. }
  3451. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3452. {
  3453. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3454. }
  3455. else
  3456. {
  3457. maxProfile.ChargingSchedule.Duration = 86400;
  3458. }
  3459. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3460. {
  3461. 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")));
  3462. }
  3463. else
  3464. {
  3465. 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));
  3466. }
  3467. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3468. {
  3469. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3470. }
  3471. else
  3472. {
  3473. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3474. }
  3475. }
  3476. }
  3477. }
  3478. json_object_put(obj);
  3479. }
  3480. fclose(fp);
  3481. /*
  3482. if(maxProfile.ChargingProfileId !=-1)
  3483. {
  3484. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3485. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3486. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3487. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3488. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3489. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3490. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3491. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3492. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3493. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3494. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3495. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3496. {
  3497. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3498. {
  3499. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3500. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3501. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3502. }
  3503. }
  3504. }
  3505. else
  3506. DEBUG_INFO("MaxProfile not found.\n");
  3507. DEBUG_INFO("------------------------------------\n");*/
  3508. }
  3509. /*
  3510. * Align found profile start schedule & periods
  3511. */
  3512. //DEBUG_INFO("====================================\n");
  3513. /*
  3514. // For local test usage, force modify found profile start schedule info
  3515. 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);
  3516. 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);
  3517. 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);
  3518. */
  3519. if(txProfile.ChargingProfileId != -1)
  3520. {
  3521. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3522. {
  3523. if(txProfile.ChargingSchedule.Duration != -1)
  3524. {
  3525. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3526. 0:
  3527. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3528. }
  3529. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3530. {
  3531. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3532. {
  3533. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3534. 0:
  3535. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3536. if(idxPeriod > 0)
  3537. {
  3538. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3539. {
  3540. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3541. }
  3542. }
  3543. }
  3544. }
  3545. }
  3546. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3547. {
  3548. if(txProfile.ChargingSchedule.Duration != -1)
  3549. {
  3550. 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?
  3551. 0:
  3552. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3553. }
  3554. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3555. {
  3556. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3557. {
  3558. 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?
  3559. 0:
  3560. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3561. if(idxPeriod > 0)
  3562. {
  3563. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3564. {
  3565. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3566. }
  3567. }
  3568. }
  3569. }
  3570. }
  3571. else
  3572. {
  3573. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3574. {
  3575. if(txProfile.ChargingSchedule.Duration != -1)
  3576. {
  3577. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3578. 0:
  3579. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3580. }
  3581. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3582. {
  3583. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3584. {
  3585. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3586. 0:
  3587. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3588. if(idxPeriod > 0)
  3589. {
  3590. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3591. {
  3592. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3593. }
  3594. }
  3595. }
  3596. }
  3597. }
  3598. else
  3599. {
  3600. if(txProfile.ChargingSchedule.Duration != -1)
  3601. {
  3602. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3603. 0:
  3604. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3605. }
  3606. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3607. {
  3608. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3609. {
  3610. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3611. 0:
  3612. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3613. if(idxPeriod > 0)
  3614. {
  3615. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3616. {
  3617. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3618. }
  3619. }
  3620. }
  3621. }
  3622. }
  3623. }
  3624. /*
  3625. DEBUG_INFO("txProfile after align.\n");
  3626. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3627. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3628. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3629. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3630. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3631. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3632. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3633. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3634. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3635. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3636. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3637. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3638. {
  3639. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3640. {
  3641. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3642. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3643. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3644. }
  3645. }*/
  3646. }
  3647. if(defaultTxProfile.ChargingProfileId != -1)
  3648. {
  3649. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3650. {
  3651. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3652. {
  3653. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3654. 0:
  3655. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3656. }
  3657. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3658. {
  3659. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3660. {
  3661. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3662. 0:
  3663. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3664. if(idxPeriod > 0)
  3665. {
  3666. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3667. {
  3668. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3669. }
  3670. }
  3671. }
  3672. }
  3673. }
  3674. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3675. {
  3676. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3677. {
  3678. 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?
  3679. 0:
  3680. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3681. }
  3682. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3683. {
  3684. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3685. {
  3686. 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?
  3687. 0:
  3688. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3689. if(idxPeriod > 0)
  3690. {
  3691. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3692. {
  3693. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3694. }
  3695. }
  3696. }
  3697. }
  3698. }
  3699. else
  3700. {
  3701. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3702. {
  3703. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3704. {
  3705. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3706. 0:
  3707. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3708. }
  3709. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3710. {
  3711. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3712. {
  3713. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3714. 0:
  3715. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3716. if(idxPeriod > 0)
  3717. {
  3718. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3719. {
  3720. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3721. }
  3722. }
  3723. }
  3724. }
  3725. }
  3726. else
  3727. {
  3728. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3729. {
  3730. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3731. 0:
  3732. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3733. }
  3734. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3735. {
  3736. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3737. {
  3738. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3739. 0:
  3740. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3741. if(idxPeriod > 0)
  3742. {
  3743. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3744. {
  3745. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3746. }
  3747. }
  3748. }
  3749. }
  3750. }
  3751. }
  3752. /*
  3753. DEBUG_INFO("defaultTxProfile after align.\n");
  3754. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3755. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3756. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3757. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3758. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3759. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3760. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3761. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3762. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3763. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3764. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3765. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3766. {
  3767. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3768. {
  3769. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3770. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3771. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3772. }
  3773. }
  3774. DEBUG_INFO("------------------------------------\n");*/
  3775. }
  3776. if(maxProfile.ChargingProfileId != -1)
  3777. {
  3778. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3779. {
  3780. if(maxProfile.ChargingSchedule.Duration != -1)
  3781. {
  3782. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3783. 0:
  3784. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3785. }
  3786. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3787. {
  3788. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3789. {
  3790. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3791. 0:
  3792. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3793. if(idxPeriod > 0)
  3794. {
  3795. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3796. {
  3797. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3798. }
  3799. }
  3800. }
  3801. }
  3802. }
  3803. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3804. {
  3805. if(maxProfile.ChargingSchedule.Duration != -1)
  3806. {
  3807. 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?
  3808. 0:
  3809. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3810. }
  3811. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3812. {
  3813. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3814. {
  3815. 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?
  3816. 0:
  3817. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3818. if(idxPeriod > 0)
  3819. {
  3820. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3821. {
  3822. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3823. }
  3824. }
  3825. }
  3826. }
  3827. }
  3828. else
  3829. {
  3830. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3831. {
  3832. if(maxProfile.ChargingSchedule.Duration != -1)
  3833. {
  3834. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3835. 0:
  3836. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3837. }
  3838. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3839. {
  3840. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3841. {
  3842. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3843. 0:
  3844. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3845. if(idxPeriod > 0)
  3846. {
  3847. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3848. {
  3849. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3850. }
  3851. }
  3852. }
  3853. }
  3854. }
  3855. else
  3856. {
  3857. if(maxProfile.ChargingSchedule.Duration != -1)
  3858. {
  3859. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3860. 0:
  3861. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3862. }
  3863. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3864. {
  3865. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3866. {
  3867. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3868. 0:
  3869. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3870. if(idxPeriod > 0)
  3871. {
  3872. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3873. {
  3874. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3875. }
  3876. }
  3877. }
  3878. }
  3879. }
  3880. }
  3881. /*
  3882. DEBUG_INFO("MaxProfile after align.\n");
  3883. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3884. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3885. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3886. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3887. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3888. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3889. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3890. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3891. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3892. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3893. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3894. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3895. {
  3896. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3897. {
  3898. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3899. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3900. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3901. }
  3902. }
  3903. DEBUG_INFO("------------------------------------\n");*/
  3904. }
  3905. /*
  3906. * Merge to composite schedule
  3907. */
  3908. //DEBUG_INFO("====================================\n");
  3909. // Find each profile period quantity
  3910. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3911. {
  3912. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3913. limitMax = idx+1;
  3914. }
  3915. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3916. {
  3917. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3918. limitDef = idx+1;
  3919. }
  3920. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3921. {
  3922. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3923. limitTx = idx+1;
  3924. }
  3925. // TxProfile found, composite schedule based on it
  3926. if(txProfile.ChargingProfileId != -1)
  3927. {
  3928. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3929. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3930. {
  3931. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3932. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3933. (txProfile.ChargingSchedule.Duration > 0))
  3934. {
  3935. if(maxProfile.ChargingProfileId != -1)
  3936. {
  3937. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3938. {
  3939. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3940. {
  3941. if((maxProfile.ChargingSchedule.Duration > 0))
  3942. {
  3943. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3944. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3945. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3946. }
  3947. else
  3948. {
  3949. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3950. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3951. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3952. }
  3953. }
  3954. if(idxMaxPeriod == (limitMax-1))
  3955. {
  3956. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3957. {
  3958. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3959. {
  3960. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3961. compositePeriodIdx++;
  3962. }
  3963. else
  3964. {
  3965. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3966. }
  3967. }
  3968. }
  3969. }
  3970. }
  3971. else
  3972. {
  3973. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3974. {
  3975. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3976. compositePeriodIdx++;
  3977. }
  3978. else
  3979. {
  3980. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3981. }
  3982. }
  3983. }
  3984. if(idxTxPeriod == (limitTx-1))
  3985. {
  3986. if(defaultTxProfile.ChargingProfileId != -1)
  3987. {
  3988. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3989. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3990. {
  3991. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3992. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3993. (defaultTxProfile.ChargingSchedule.Duration>0))
  3994. {
  3995. if(maxProfile.ChargingProfileId != -1)
  3996. {
  3997. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3998. {
  3999. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4000. {
  4001. if((maxProfile.ChargingSchedule.Duration > 0))
  4002. {
  4003. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4004. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4005. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  4006. }
  4007. else
  4008. {
  4009. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4010. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4011. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4012. }
  4013. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4014. {
  4015. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4016. {
  4017. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4018. compositePeriodIdx++;
  4019. }
  4020. else
  4021. {
  4022. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4023. }
  4024. }
  4025. // Delete duplicate period
  4026. if(compositePeriodIdx > 1)
  4027. {
  4028. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4029. {
  4030. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4031. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4032. compositePeriodIdx -= 1;
  4033. }
  4034. }
  4035. }
  4036. else
  4037. {
  4038. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4039. {
  4040. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4041. compositePeriodIdx++;
  4042. }
  4043. else
  4044. {
  4045. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4046. }
  4047. break;
  4048. }
  4049. }
  4050. }
  4051. else
  4052. {
  4053. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4054. {
  4055. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4056. compositePeriodIdx++;
  4057. }
  4058. else
  4059. {
  4060. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4061. }
  4062. }
  4063. }
  4064. }
  4065. }
  4066. }
  4067. }
  4068. }
  4069. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4070. else if(defaultTxProfile.ChargingProfileId != -1)
  4071. {
  4072. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  4073. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4074. {
  4075. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  4076. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  4077. (defaultTxProfile.ChargingSchedule.Duration > 0))
  4078. {
  4079. if(maxProfile.ChargingProfileId != -1)
  4080. {
  4081. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4082. {
  4083. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4084. {
  4085. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4086. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4087. if((maxProfile.ChargingSchedule.Duration > 0))
  4088. {
  4089. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  4090. }
  4091. else
  4092. {
  4093. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4094. }
  4095. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4096. {
  4097. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4098. {
  4099. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4100. compositePeriodIdx++;
  4101. }
  4102. else
  4103. {
  4104. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4105. }
  4106. }
  4107. // Delete duplicate period
  4108. if(compositePeriodIdx > 1)
  4109. {
  4110. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4111. {
  4112. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4113. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4114. compositePeriodIdx -= 1;
  4115. }
  4116. }
  4117. }
  4118. else
  4119. {
  4120. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4121. {
  4122. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4123. compositePeriodIdx++;
  4124. }
  4125. else
  4126. {
  4127. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4128. }
  4129. break;
  4130. }
  4131. }
  4132. }
  4133. else
  4134. {
  4135. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4136. {
  4137. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4138. compositePeriodIdx++;
  4139. }
  4140. else
  4141. {
  4142. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4143. }
  4144. }
  4145. }
  4146. }
  4147. }
  4148. // Fill other period by MaxProfile
  4149. if(maxProfile.ChargingProfileId != -1)
  4150. {
  4151. if(compositePeriodIdx==0)
  4152. {
  4153. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4154. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  4155. {
  4156. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4157. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4158. (maxProfile.ChargingSchedule.Duration > 0))
  4159. {
  4160. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4161. {
  4162. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4163. compositePeriodIdx++;
  4164. }
  4165. else
  4166. {
  4167. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4168. }
  4169. }
  4170. }
  4171. }
  4172. else
  4173. {
  4174. int lastCompositePeriodIdx = compositePeriodIdx;
  4175. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4176. {
  4177. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4178. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4179. (maxProfile.ChargingSchedule.Duration > 0))
  4180. {
  4181. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  4182. {
  4183. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  4184. {
  4185. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4186. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4187. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  4188. }
  4189. else
  4190. {
  4191. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4192. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4193. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  4194. }
  4195. }
  4196. if(tmpPeriod.Limit != -1)
  4197. {
  4198. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  4199. {
  4200. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  4201. {
  4202. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4203. compositePeriodIdx++;
  4204. }
  4205. else
  4206. {
  4207. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4208. }
  4209. }
  4210. // Delete duplicate period
  4211. if(compositePeriodIdx > 1)
  4212. {
  4213. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4214. {
  4215. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4216. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4217. compositePeriodIdx -= 1;
  4218. }
  4219. }
  4220. }
  4221. }
  4222. }
  4223. }
  4224. }
  4225. if(compositeProfile.ChargingSchedule.Duration < durationReq)
  4226. {
  4227. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4228. {
  4229. if((idxPeriod > 0) && (compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == 0 || compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1))
  4230. {
  4231. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = compositeProfile.ChargingSchedule.Duration;
  4232. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  4233. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].NumberPhases;
  4234. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  4235. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4236. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4237. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4238. DEBUG_INFO("------------------------------------------------\n");
  4239. break;
  4240. }
  4241. }
  4242. }
  4243. compositeProfile.ChargingSchedule.Duration = durationReq;
  4244. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4245. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4246. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4247. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4248. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4249. {
  4250. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4251. {
  4252. compositeProfile.ChargingProfileId = 1;
  4253. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4254. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4255. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4256. }
  4257. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4258. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4259. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4260. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4261. }
  4262. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4263. if(line)
  4264. free(line);
  4265. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4266. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4267. }
  4268. //==========================================
  4269. // Init all share memory
  4270. //==========================================
  4271. int InitShareMemory()
  4272. {
  4273. int result = PASS;
  4274. int MeterSMId;
  4275. //creat ShmSysConfigAndInfo
  4276. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4277. {
  4278. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4279. result = FAIL;
  4280. }
  4281. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4282. {
  4283. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4284. result = FAIL;
  4285. }
  4286. else
  4287. {}
  4288. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4289. {
  4290. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4291. result = FAIL;
  4292. }
  4293. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4294. {
  4295. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4296. result = FAIL;
  4297. }
  4298. else
  4299. {}
  4300. //creat ShmPsuData
  4301. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4302. {
  4303. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4304. result = FAIL;
  4305. }
  4306. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4307. {
  4308. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4309. result = FAIL;
  4310. }
  4311. else
  4312. {}
  4313. //creat ShmOCPP16Data
  4314. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4315. {
  4316. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4317. result = FAIL;
  4318. }
  4319. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4320. {
  4321. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4322. result = FAIL;
  4323. }
  4324. else
  4325. {}
  4326. /****************************** For Initial Settings************************************************/
  4327. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4328. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4329. // allocate Configuration memory address
  4330. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4331. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4332. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4333. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4334. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4335. //offline MeterValue Interval
  4336. TempMeterValueInterval = 0;
  4337. return result;
  4338. }
  4339. int ProcessShareMemory()
  4340. {
  4341. int result = PASS;
  4342. if(InitShareMemory() == FAIL)
  4343. {
  4344. DEBUG_ERROR("InitShareMemory NG\n");
  4345. if(ShmStatusCodeData!=NULL)
  4346. {
  4347. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4348. }
  4349. result = FAIL;
  4350. }
  4351. // Model name parsing
  4352. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4353. {
  4354. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4355. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4356. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4357. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4358. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  4359. ) // 'D' means DC
  4360. {
  4361. // DO series
  4362. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4363. {
  4364. gunTotalNumber += 1;
  4365. gunType[gun_index] = GUN_TYPE_DO;
  4366. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4367. {
  4368. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4369. {
  4370. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4371. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4372. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4373. }
  4374. }
  4375. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4376. {
  4377. case Gun_Type_Chademo:
  4378. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4379. break;
  4380. case Gun_Type_CCS_2:
  4381. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4382. break;
  4383. case Gun_Type_GB:
  4384. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4385. break;
  4386. case Gun_Type_AC:
  4387. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4388. break;
  4389. default:
  4390. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4391. break;
  4392. }
  4393. }
  4394. }
  4395. else
  4396. {
  4397. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4398. {
  4399. gunTotalNumber += 1;
  4400. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4401. {
  4402. case Gun_Type_Chademo:
  4403. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4404. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4405. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4406. {
  4407. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4408. {
  4409. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4410. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4411. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4412. }
  4413. }
  4414. break;
  4415. case Gun_Type_CCS_2:
  4416. gunType[gun_index] = GUN_TYPE_CCS;
  4417. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4418. for (int index = 0; index < CCS_QUANTITY; index++)
  4419. {
  4420. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4421. {
  4422. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4423. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4424. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4425. }
  4426. }
  4427. break;
  4428. case Gun_Type_GB:
  4429. gunType[gun_index] = GUN_TYPE_GBT;
  4430. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4431. for (int index = 0; index < GB_QUANTITY; index++)
  4432. {
  4433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4434. {
  4435. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4436. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4437. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4438. }
  4439. }
  4440. break;
  4441. case Gun_Type_AC:
  4442. gunType[gun_index] = GUN_TYPE_AC;
  4443. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4444. for (int index = 0; index < AC_QUANTITY; index++)
  4445. {
  4446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4447. {
  4448. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4449. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4450. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4451. }
  4452. }
  4453. break;
  4454. default:
  4455. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4456. break;
  4457. }
  4458. }
  4459. }
  4460. }
  4461. else
  4462. {
  4463. DEBUG_ERROR("Model name parsing fail.\n");
  4464. result = FAIL;
  4465. }
  4466. if(result != PASS)sleep(5);
  4467. return result;
  4468. }
  4469. void checkRemoteStart(uint8_t connectorIdInt)
  4470. {
  4471. uint8_t tempIndex;
  4472. int result = PASS;
  4473. char cmdBuf[512];
  4474. //check Transaction active
  4475. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4476. {
  4477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4478. {
  4479. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4480. }
  4481. else
  4482. {
  4483. tempIndex = connectorIdInt -1;
  4484. }
  4485. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4486. {
  4487. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4488. {
  4489. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4490. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4491. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4492. {
  4493. //Reserved
  4494. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4495. }
  4496. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4497. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4498. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4499. {
  4500. //Reserved
  4501. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4502. result = FAIL;
  4503. goto end;
  4504. }
  4505. else
  4506. {
  4507. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4508. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4509. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4510. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4511. {
  4512. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4513. result = FAIL;
  4514. goto end;
  4515. }
  4516. }//END FOR ELSE
  4517. }
  4518. }// END FOR CHAdeMO_QUANTITY
  4519. }
  4520. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4521. {
  4522. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4523. {
  4524. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4525. }
  4526. else
  4527. {
  4528. tempIndex = connectorIdInt -1;
  4529. }
  4530. for (int index = 0; index < CCS_QUANTITY; index++)
  4531. {
  4532. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4533. {
  4534. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4535. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4536. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4537. {
  4538. //Reserved
  4539. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4540. }
  4541. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4542. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4543. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4544. {
  4545. //Reserved
  4546. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4547. result = FAIL;
  4548. goto end;
  4549. }
  4550. else
  4551. {
  4552. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4553. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4554. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4555. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4556. {
  4557. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4558. result = FAIL;
  4559. goto end;
  4560. }
  4561. }// END FOR ELSE
  4562. }
  4563. }// END FOR CCS_QUANTITY
  4564. }
  4565. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4566. {
  4567. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4568. {
  4569. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4570. }
  4571. else
  4572. {
  4573. tempIndex = connectorIdInt -1;
  4574. }
  4575. for (int index = 0; index < GB_QUANTITY; index++)
  4576. {
  4577. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4578. {
  4579. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4580. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4581. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4582. {
  4583. //Reserved
  4584. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4585. }
  4586. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4588. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4589. {
  4590. //Reserved
  4591. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4592. result = FAIL;
  4593. goto end;
  4594. }
  4595. else
  4596. {
  4597. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4598. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4599. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4600. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4601. {
  4602. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4603. result = FAIL;
  4604. goto end;
  4605. }
  4606. }// END FOR ELSE
  4607. }
  4608. } // END FOR GB_QUANTITY
  4609. }
  4610. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4611. {
  4612. tempIndex = connectorIdInt -1;
  4613. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4614. {
  4615. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4616. {
  4617. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4618. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4619. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4620. {
  4621. //Reserved
  4622. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4623. }
  4624. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4625. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4626. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4627. {
  4628. //Reserved
  4629. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4630. result = FAIL;
  4631. goto end;
  4632. }
  4633. else
  4634. {
  4635. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4636. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4637. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4638. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4639. {
  4640. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4641. result = FAIL;
  4642. goto end;
  4643. }
  4644. }// END FOR ELSE
  4645. }
  4646. } // END FOR GB_QUANTITY
  4647. }
  4648. else
  4649. {
  4650. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4651. {
  4652. tempIndex = 2;
  4653. }
  4654. else
  4655. {
  4656. tempIndex = connectorIdInt -1;
  4657. }
  4658. for (int index = 0; index < AC_QUANTITY; index++)
  4659. {
  4660. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4661. {
  4662. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4663. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4664. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4665. {
  4666. //Reserved
  4667. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4668. }
  4669. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4670. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4671. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4672. {
  4673. //Reserved
  4674. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4675. result = FAIL;
  4676. goto end;
  4677. }
  4678. else
  4679. {
  4680. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4681. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4682. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4683. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4684. {
  4685. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4686. result = FAIL;
  4687. goto end;
  4688. }
  4689. }//END FOR ELSE
  4690. }
  4691. }// END FOR AC_QUANTITY
  4692. }
  4693. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4694. {
  4695. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4696. {
  4697. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4698. {
  4699. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4700. system(cmdBuf);
  4701. }
  4702. }
  4703. else
  4704. {
  4705. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4706. result = FAIL;
  4707. }
  4708. }
  4709. end:
  4710. if(result == PASS)
  4711. {
  4712. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4713. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4714. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4715. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4716. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4717. }
  4718. }
  4719. int isConnector0Unavailable()
  4720. {
  4721. uint8_t result = YES;
  4722. uint8_t tempIndex;
  4723. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4724. {
  4725. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4726. {
  4727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4728. {
  4729. tempIndex = ((gun_index==2) ? 1: 0);
  4730. }
  4731. else
  4732. {
  4733. tempIndex = gun_index;
  4734. }
  4735. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4736. {
  4737. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4738. {
  4739. 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))
  4740. {
  4741. result = NO;
  4742. }
  4743. }
  4744. }
  4745. }
  4746. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4747. {
  4748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4749. {
  4750. tempIndex = ((gun_index==2) ? 1: 0);
  4751. }
  4752. else
  4753. {
  4754. tempIndex = gun_index;
  4755. }
  4756. for (int index = 0; index < CCS_QUANTITY; index++)
  4757. {
  4758. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4759. {
  4760. 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))
  4761. {
  4762. result = NO;
  4763. }
  4764. }
  4765. }
  4766. }
  4767. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4768. {
  4769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4770. {
  4771. tempIndex = ((gun_index==2) ? 1: 0);
  4772. }
  4773. else
  4774. {
  4775. tempIndex = gun_index;
  4776. }
  4777. for (int index = 0; index < GB_QUANTITY; index++)
  4778. {
  4779. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4780. {
  4781. 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))
  4782. {
  4783. result = NO;
  4784. }
  4785. }
  4786. }
  4787. }
  4788. else if(gunType[gun_index] == GUN_TYPE_DO)
  4789. {
  4790. tempIndex = gun_index;
  4791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4792. {
  4793. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4794. {
  4795. 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))
  4796. {
  4797. result = NO;
  4798. }
  4799. }
  4800. }
  4801. }
  4802. else
  4803. {
  4804. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4805. {
  4806. tempIndex = 2;
  4807. }
  4808. else
  4809. {
  4810. tempIndex = gun_index;
  4811. }
  4812. for (int index = 0; index < AC_QUANTITY; index++)
  4813. {
  4814. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4815. {
  4816. 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))
  4817. {
  4818. result = NO;
  4819. }
  4820. }
  4821. }// END
  4822. }
  4823. }
  4824. return result;
  4825. }
  4826. void CheckSystemValue(void)
  4827. {
  4828. char filenmae[100]={0};
  4829. char str[100]={0};
  4830. int tempIndex = 0;
  4831. //===============================
  4832. // send Heartbeat
  4833. //===============================
  4834. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4835. {
  4836. //parameter for test
  4837. sendHeartbeatRequest(0);
  4838. //===========================
  4839. // Reset Waiting Time
  4840. //===========================
  4841. HeartBeatWithNOResponse += 1;
  4842. }
  4843. //===============================
  4844. // Tcci credit deduct report
  4845. //===============================
  4846. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4847. {
  4848. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4849. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4850. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4851. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4852. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4853. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4854. }
  4855. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4856. {
  4857. OCPP_query_deduct_info();
  4858. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4859. }
  4860. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4861. {
  4862. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4863. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4864. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4865. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4866. }
  4867. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4868. {
  4869. OCPP_query_occupancyDeduct_info();
  4870. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4871. }
  4872. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4873. {
  4874. // ClockAlign MeterValue
  4875. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4876. {
  4877. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4878. {
  4879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4880. {
  4881. tempIndex = ((gun_index==2) ? 1: 0);
  4882. }
  4883. else
  4884. {
  4885. tempIndex = gun_index;
  4886. }
  4887. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4888. {
  4889. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4890. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4891. {
  4892. reqClockAlignMeter[gun_index] = 1;
  4893. }
  4894. }// End for CHAdeMO
  4895. }
  4896. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4897. {
  4898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4899. {
  4900. tempIndex = ((gun_index==2) ? 1: 0);
  4901. }
  4902. else
  4903. {
  4904. tempIndex = gun_index;
  4905. }
  4906. for (int index = 0; index < CCS_QUANTITY; index++)
  4907. {
  4908. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4909. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4910. {
  4911. reqClockAlignMeter[gun_index] = 1;
  4912. }
  4913. } // End for CCS
  4914. }
  4915. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4916. {
  4917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4918. {
  4919. tempIndex = ((gun_index==2) ? 1: 0);
  4920. }
  4921. else
  4922. {
  4923. tempIndex = gun_index;
  4924. }
  4925. for (int index = 0; index < GB_QUANTITY; index++)
  4926. {
  4927. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4928. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4929. {
  4930. reqClockAlignMeter[gun_index] = 1;
  4931. }
  4932. }// End for GB
  4933. }
  4934. else if(gunType[gun_index] == GUN_TYPE_DO)
  4935. {
  4936. tempIndex = gun_index;
  4937. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4938. {
  4939. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4940. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4941. {
  4942. reqClockAlignMeter[gun_index] = 1;
  4943. }
  4944. }
  4945. }
  4946. else
  4947. {
  4948. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4949. {
  4950. tempIndex = 2;
  4951. }
  4952. else
  4953. {
  4954. tempIndex = gun_index;
  4955. }
  4956. for (int index = 0; index < AC_QUANTITY; index++)
  4957. {
  4958. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4959. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4960. {
  4961. reqClockAlignMeter[gun_index] = 1;
  4962. }
  4963. }//End for AC
  4964. }
  4965. }
  4966. }
  4967. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4968. {
  4969. //==========================================
  4970. // Check remote start without connector id
  4971. //==========================================
  4972. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4973. {
  4974. int connectorIdInt = -1;
  4975. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4976. {
  4977. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4978. {
  4979. connectorIdInt = (gun_index+1);
  4980. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4981. checkRemoteStart(connectorIdInt);
  4982. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4983. break;
  4984. }
  4985. }
  4986. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4987. {
  4988. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4989. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4990. }
  4991. }
  4992. //==========================================
  4993. // csu trigger DataTransferReq
  4994. //==========================================
  4995. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4996. {
  4997. sendDataTransferRequest(gun_index);
  4998. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4999. }
  5000. //==========================================
  5001. // CSU Trigger Authorize Request
  5002. //==========================================
  5003. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  5004. {
  5005. sendAuthorizeRequest(0);
  5006. authorizeRetryTimes = authorizeRetryTimes + 1;
  5007. if(authorizeRetryTimes < 3)
  5008. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5009. }
  5010. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  5011. {
  5012. authorizeRetryTimes = 0;
  5013. SetOcppConnStatus(FALSE);
  5014. server_sign = FALSE;
  5015. }
  5016. 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))
  5017. {
  5018. sendAuthorizeRequest(0);
  5019. }
  5020. //==========================================
  5021. // Charger start transaction
  5022. //==========================================
  5023. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  5024. {
  5025. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  5026. meterValueBufferClear(gun_index);
  5027. sendStartTransactionRequest(gun_index);
  5028. refreshStartTimer(&clientTime.StartTransaction);
  5029. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5030. storeTempStopTransaction(gun_index);
  5031. }
  5032. //==========================================
  5033. // Charger stop transaction
  5034. //==========================================
  5035. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  5036. {
  5037. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5038. sendStopTransactionRequest(gun_index);
  5039. OCPP_updatePeriodEnergy(gun_index);
  5040. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  5041. refreshStartTimer(&clientTime.StopTransaction);
  5042. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  5043. }
  5044. //==========================================
  5045. // Charger OCMF message
  5046. //==========================================
  5047. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  5048. {
  5049. sendOcmfByDataTransferRequest(gun_index);
  5050. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  5051. }
  5052. //==========================================
  5053. // Charger status report
  5054. //==========================================
  5055. //--- Check Mode Change ---//
  5056. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5057. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5058. {
  5059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5060. {
  5061. tempIndex = ((gun_index==2) ? 1: 0);
  5062. }
  5063. else
  5064. {
  5065. tempIndex = gun_index;
  5066. }
  5067. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5068. {
  5069. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5070. {
  5071. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5072. {
  5073. // Sent unplug message for California pricing logic
  5074. 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])
  5075. {
  5076. uint8_t ts[36];
  5077. getNowDatetime(ts);
  5078. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5079. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5080. if(strcmp((char*)dmsVersion, "2.0")==0)
  5081. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5082. else
  5083. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5084. sendUnplugByDataTransferRequest(gun_index);
  5085. interLock.isSentUnplug[gun_index] = 1;
  5086. }
  5087. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5088. {
  5089. interLock.isSentUnplug[gun_index] = 0;
  5090. }
  5091. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5092. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5093. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5094. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5095. {
  5096. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5097. if((access(filenmae,F_OK))!=-1)
  5098. {
  5099. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5100. sprintf(str,"rm -f %s",filenmae);
  5101. system(str);
  5102. }
  5103. }
  5104. }
  5105. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5106. #if 1 // for TempStopTransaction
  5107. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5108. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5109. {
  5110. checkTempStopTransaction(gun_index);
  5111. }
  5112. #endif
  5113. }
  5114. }
  5115. }
  5116. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5117. {
  5118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5119. {
  5120. tempIndex = ((gun_index==2) ? 1: 0);
  5121. }
  5122. else
  5123. {
  5124. tempIndex = gun_index;
  5125. }
  5126. for (int index = 0; index < CCS_QUANTITY; index++)
  5127. {
  5128. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5129. {
  5130. 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]*/ )
  5131. {
  5132. // Sent unplug message for California pricing logic
  5133. 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])
  5134. {
  5135. uint8_t ts[36];
  5136. getNowDatetime(ts);
  5137. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5138. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5139. if(strcmp((char*)dmsVersion, "2.0")==0)
  5140. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5141. else
  5142. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5143. sendUnplugByDataTransferRequest(gun_index);
  5144. interLock.isSentUnplug[gun_index] = 1;
  5145. }
  5146. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5147. {
  5148. interLock.isSentUnplug[gun_index] = 0;
  5149. }
  5150. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5151. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5152. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5153. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5154. {
  5155. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5156. if((access(filenmae,F_OK))!=-1)
  5157. {
  5158. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5159. sprintf(str,"rm -f %s",filenmae);
  5160. system(str);
  5161. }
  5162. }
  5163. }
  5164. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5165. #if 1 // for TempStopTransaction
  5166. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5167. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5168. {
  5169. checkTempStopTransaction(gun_index);
  5170. }
  5171. #endif
  5172. }
  5173. }
  5174. }
  5175. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5176. {
  5177. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5178. {
  5179. tempIndex = ((gun_index==2) ? 1: 0);
  5180. }
  5181. else
  5182. {
  5183. tempIndex = gun_index;
  5184. }
  5185. for (int index = 0; index < GB_QUANTITY; index++)
  5186. {
  5187. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5188. {
  5189. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5190. {
  5191. // Sent unplug message for California pricing logic
  5192. 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])
  5193. {
  5194. uint8_t ts[36];
  5195. getNowDatetime(ts);
  5196. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5197. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5198. if(strcmp((char*)dmsVersion, "2.0")==0)
  5199. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5200. else
  5201. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5202. sendUnplugByDataTransferRequest(gun_index);
  5203. interLock.isSentUnplug[gun_index] = 1;
  5204. }
  5205. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5206. {
  5207. interLock.isSentUnplug[gun_index] = 0;
  5208. }
  5209. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5210. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5211. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5212. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5213. {
  5214. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5215. if((access(filenmae,F_OK))!=-1)
  5216. {
  5217. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5218. sprintf(str,"rm -f %s",filenmae);
  5219. system(str);
  5220. }
  5221. }
  5222. }
  5223. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5224. #if 1 // for TempStopTransaction
  5225. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5226. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5227. {
  5228. checkTempStopTransaction(gun_index);
  5229. }
  5230. #endif
  5231. }
  5232. }
  5233. }
  5234. else if(gunType[gun_index] == GUN_TYPE_DO)
  5235. {
  5236. tempIndex = gun_index;
  5237. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5238. {
  5239. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5240. {
  5241. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5242. {
  5243. // Sent unplug message for California pricing logic
  5244. 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])
  5245. {
  5246. uint8_t ts[36];
  5247. getNowDatetime(ts);
  5248. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5249. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5250. if(strcmp((char*)dmsVersion, "2.0")==0)
  5251. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5252. else
  5253. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5254. sendUnplugByDataTransferRequest(gun_index);
  5255. interLock.isSentUnplug[gun_index] = 1;
  5256. }
  5257. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  5258. {
  5259. interLock.isSentUnplug[gun_index] = 0;
  5260. }
  5261. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5262. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5263. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5264. 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
  5265. {
  5266. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5267. if((access(filenmae,F_OK))!=-1)
  5268. {
  5269. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5270. sprintf(str,"rm -f %s",filenmae);
  5271. system(str);
  5272. }
  5273. }
  5274. }
  5275. 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);
  5276. #if 1 // for TempStopTransaction
  5277. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5278. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5279. {
  5280. checkTempStopTransaction(gun_index);
  5281. }
  5282. #endif
  5283. }
  5284. }
  5285. }
  5286. else
  5287. {
  5288. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5289. {
  5290. tempIndex = 2;
  5291. }
  5292. else
  5293. {
  5294. tempIndex = gun_index;
  5295. }
  5296. for (int index = 0; index < AC_QUANTITY; index++)
  5297. {
  5298. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5299. {
  5300. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5301. {
  5302. // Sent unplug message for California pricing logic
  5303. 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])
  5304. {
  5305. uint8_t ts[36];
  5306. getNowDatetime(ts);
  5307. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5308. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5309. if(strcmp((char*)dmsVersion, "2.0")==0)
  5310. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5311. else
  5312. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5313. sendUnplugByDataTransferRequest(gun_index);
  5314. interLock.isSentUnplug[gun_index] = 1;
  5315. }
  5316. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5317. {
  5318. interLock.isSentUnplug[gun_index] = 0;
  5319. }
  5320. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5321. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5322. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5323. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5324. {
  5325. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5326. if((access(filenmae,F_OK))!=-1)
  5327. {
  5328. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5329. sprintf(str,"rm -f %s",filenmae);
  5330. system(str);
  5331. }
  5332. }
  5333. }
  5334. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5335. #if 1 // for TempStopTransaction
  5336. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5337. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5338. {
  5339. checkTempStopTransaction(gun_index);
  5340. }
  5341. #endif
  5342. }
  5343. }// END
  5344. }
  5345. if(isWebsocketSendable && (server_sign == TRUE) && (isConnector0Unavailable() != Connector0PreviousSystemStatus))
  5346. {
  5347. sendConnector0StatusNotificationRequest();
  5348. Connector0PreviousSystemStatus = isConnector0Unavailable();
  5349. }
  5350. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5351. (
  5352. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5353. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5354. )
  5355. )
  5356. {
  5357. sendStatusNotificationRequest(gun_index);
  5358. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5359. }
  5360. //==============================================
  5361. // TCCI related DataTransfer messages
  5362. //==============================================
  5363. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5364. {
  5365. reportReaderStatus(gun_index);
  5366. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5367. }
  5368. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.GetOccupancyFee[gun_index].GetOccupancyFeeReq == 1))
  5369. {
  5370. getOccupancyFee(gun_index);
  5371. }
  5372. //==============================================
  5373. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5374. //==============================================
  5375. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5376. ((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))))
  5377. {
  5378. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5379. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5380. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5381. }
  5382. //==============================================
  5383. // Meter report
  5384. //==============================================
  5385. // Trigger MeterValue
  5386. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5387. {
  5388. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5389. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5390. }
  5391. // Clock-aligned Meter value
  5392. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5393. {
  5394. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5395. reqClockAlignMeter[gun_index] = 0;
  5396. }
  5397. // Sample period MeterValue
  5398. 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))))
  5399. {
  5400. //check Transaction active
  5401. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5402. {
  5403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5404. {
  5405. tempIndex = ((gun_index==2) ? 1: 0);
  5406. }
  5407. else
  5408. {
  5409. tempIndex = gun_index;
  5410. }
  5411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5412. {
  5413. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5414. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5415. {
  5416. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5417. {
  5418. reqSampleMeter[gun_index] = 1;
  5419. }
  5420. }
  5421. }// End for CHAdeMO
  5422. }
  5423. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5424. {
  5425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5426. {
  5427. tempIndex = ((gun_index==2) ? 1: 0);
  5428. }
  5429. else
  5430. {
  5431. tempIndex = gun_index;
  5432. }
  5433. for (int index = 0; index < CCS_QUANTITY; index++)
  5434. {
  5435. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5436. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5437. {
  5438. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5439. {
  5440. reqSampleMeter[gun_index] = 1;
  5441. }
  5442. }
  5443. } // End for CCS
  5444. }
  5445. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5446. {
  5447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5448. {
  5449. tempIndex = ((gun_index==2) ? 1: 0);
  5450. }
  5451. else
  5452. {
  5453. tempIndex = gun_index;
  5454. }
  5455. for (int index = 0; index < GB_QUANTITY; index++)
  5456. {
  5457. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5458. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5459. {
  5460. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5461. {
  5462. reqSampleMeter[gun_index] = 1;
  5463. }
  5464. }
  5465. }// End for GB
  5466. }
  5467. else if(gunType[gun_index] == GUN_TYPE_DO)
  5468. {
  5469. tempIndex = gun_index;
  5470. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5471. {
  5472. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5473. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5474. {
  5475. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5476. {
  5477. reqSampleMeter[gun_index] = 1;
  5478. }
  5479. }
  5480. }
  5481. }
  5482. else
  5483. {
  5484. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5485. {
  5486. tempIndex = 2;
  5487. }
  5488. else
  5489. {
  5490. tempIndex = gun_index;
  5491. }
  5492. for (int index = 0; index < AC_QUANTITY; index++)
  5493. {
  5494. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5495. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5496. {
  5497. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5498. {
  5499. reqSampleMeter[gun_index] = 1;
  5500. }
  5501. }
  5502. }//End for AC
  5503. }
  5504. if(reqSampleMeter[gun_index] == 1)
  5505. {
  5506. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5507. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5508. storeTempStopTransaction(gun_index);
  5509. reqSampleMeter[gun_index] = 0;
  5510. }
  5511. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5512. }
  5513. //==============================================
  5514. // Check Connector reserved
  5515. //==============================================
  5516. //===============================
  5517. // Check if Reserve is expired
  5518. //===============================
  5519. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5520. {
  5521. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5522. {
  5523. DEBUG_INFO("reserve expired.\n");
  5524. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5525. }
  5526. }//END OF Check if Reserve is expired
  5527. //==========================================
  5528. // csu trigger FirmwareStatusNotificationReq
  5529. //==========================================
  5530. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5531. {
  5532. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5533. }
  5534. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5535. {
  5536. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5537. }
  5538. //==========================================
  5539. // csu trigger DiagnosticsStatusNotificationReq
  5540. //==========================================
  5541. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5542. {
  5543. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5544. }
  5545. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5546. {
  5547. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5548. }
  5549. //==========================================
  5550. // csu trigger CancelReservationConf
  5551. //==========================================
  5552. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5553. {
  5554. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5555. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5556. }
  5557. //==========================================
  5558. // csu trigger ChangeAvailabilityConf
  5559. //==========================================
  5560. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5561. {
  5562. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5563. }
  5564. //==========================================
  5565. // csu trigger UnlockConnectorConf
  5566. //==========================================
  5567. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5568. {
  5569. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5570. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5571. }
  5572. //==========================================
  5573. // csu trigger ReserveNowConf
  5574. //==========================================
  5575. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5576. {
  5577. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5578. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5579. }
  5580. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5581. {
  5582. sendSignCertificateRequest();
  5583. }
  5584. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5585. {
  5586. sendSecurityEventNotificationRequest();
  5587. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5588. }
  5589. // Support 15118
  5590. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5591. {
  5592. json_object *data = json_object_new_object();
  5593. // Read csr file content
  5594. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5595. FILE *fp=fopen(CSR_V2G,"r");
  5596. char *line = NULL;
  5597. size_t len = 0;
  5598. while(getline(&line, &len, fp) != -1)
  5599. {
  5600. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5601. {
  5602. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5603. }
  5604. }
  5605. fclose(fp);
  5606. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5607. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5608. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5609. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5610. json_object_put(data);
  5611. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5612. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5613. }
  5614. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5615. {
  5616. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5617. int parseCertResult = FAIL;
  5618. json_object *data = json_object_new_object();
  5619. json_object *idToken = json_object_new_object();
  5620. json_object *iso15118CertificateHashData = json_object_new_array();
  5621. // Read CERTIFICATE_PnCAuth file content
  5622. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5623. {
  5624. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5625. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5626. char *line = NULL;
  5627. size_t len = 0;
  5628. while(getline(&line, &len, fp) != -1)
  5629. {
  5630. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5631. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5632. }
  5633. fclose(fp);
  5634. }
  5635. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5636. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5637. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5638. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5639. json_object_object_add(data, "idToken", idToken);
  5640. char parseData[512] = {0};
  5641. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5642. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5643. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5644. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5645. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5646. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5647. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5648. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5649. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5650. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5651. for(int idx=0; idx < 4; idx++)
  5652. {
  5653. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5654. {
  5655. json_object *OCSPRequestDataType = json_object_new_object();
  5656. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5657. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5658. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5659. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5660. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5661. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5662. parseCertResult = PASS;
  5663. }
  5664. }
  5665. if(parseCertResult == PASS)
  5666. {
  5667. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5668. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5669. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5670. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5671. json_object_put(data);
  5672. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5673. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5674. }
  5675. else
  5676. {
  5677. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5678. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5679. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5680. }
  5681. }
  5682. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5683. {
  5684. json_object *data = json_object_new_object();
  5685. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5686. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5687. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5688. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5689. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5690. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5691. json_object_put(data);
  5692. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5693. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5694. }
  5695. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5696. {
  5697. json_object *data = json_object_new_object();
  5698. json_object *OCSPRequestDataType = json_object_new_object();
  5699. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5700. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5701. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5702. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5703. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5704. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5705. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5706. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5707. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5708. json_object_put(data);
  5709. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5710. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5711. }
  5712. }
  5713. }
  5714. //==========================================
  5715. // send request routine
  5716. //==========================================
  5717. int sendAuthorizeRequest(int gun_index)
  5718. {
  5719. mtrace();
  5720. int result = FAIL;
  5721. char message[100]={0};
  5722. char guid[37];
  5723. char tempdata[65]={0};
  5724. DEBUG_INFO("sendAuthorizeRequest...\n");
  5725. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5726. //Local Authorize
  5727. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5728. {
  5729. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5730. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5731. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5732. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5733. result = PASS;
  5734. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5735. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5736. authorizeRetryTimes = 0;
  5737. return result;
  5738. }
  5739. 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))||
  5740. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5741. {
  5742. // Query from cache
  5743. DEBUG_INFO("Authorize from cache.\n");
  5744. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5745. // Query from list
  5746. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5747. {
  5748. DEBUG_INFO("Authorize from list.\n");
  5749. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5750. }
  5751. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5752. {
  5753. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5754. {
  5755. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5756. }
  5757. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5758. {
  5759. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5760. }
  5761. if(!GetOcppConnStatus())
  5762. {
  5763. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5764. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5765. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5766. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5767. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5768. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5769. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5770. authorizeRetryTimes = 0;
  5771. return result;
  5772. }
  5773. }
  5774. else
  5775. {
  5776. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5777. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5778. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5779. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5780. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5781. else
  5782. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5783. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5784. result = PASS;
  5785. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5786. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5787. authorizeRetryTimes = 0;
  5788. return result;
  5789. }
  5790. }
  5791. //initialize struct Authorize
  5792. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5793. //get data from shared memory
  5794. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5795. random_uuid(guid);
  5796. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5797. LWS_Send(message);
  5798. sprintf(tempdata, "Authorize,%d", gun_index);
  5799. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5800. {
  5801. result = PASS;
  5802. DEBUG_INFO("Authorize mapItem pass\n");
  5803. }
  5804. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5805. return result;
  5806. }
  5807. int sendBootNotificationRequest(void)
  5808. {
  5809. mtrace();
  5810. int result = FAIL;
  5811. char message[500]={0}, payload[700]={0};
  5812. char guid[37]={0};
  5813. char tempdata[65]={0};
  5814. // Fill BootNotification fields
  5815. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5816. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5817. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5818. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5819. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5820. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5821. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5822. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5823. ShmOCPP16Data->ChargeBoxId
  5824. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5825. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5826. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5827. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5828. ,ShmOCPP16Data->BootNotification.CpIccid
  5829. ,ShmOCPP16Data->BootNotification.CpImsi);
  5830. random_uuid(guid);
  5831. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5832. LWS_Send(message);
  5833. sprintf(tempdata, "BootNotification,0");
  5834. 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*/)
  5835. {
  5836. result = PASS;
  5837. }
  5838. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5839. strcpy(queuedata,message);
  5840. return result;
  5841. }
  5842. int sendDataTransferRequest(int gun_index)
  5843. {
  5844. mtrace();
  5845. char message[10240]={0};
  5846. char guid[37]={0};
  5847. char tempdata[65]={0};
  5848. int result = FAIL;
  5849. json_object *DataTransfer = json_object_new_object();
  5850. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5851. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5852. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5853. random_uuid(guid);
  5854. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5855. guid,
  5856. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5857. json_object_put(DataTransfer);
  5858. LWS_Send(message);
  5859. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5860. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5861. {
  5862. result = PASS;
  5863. DEBUG_INFO("DataTransfer mapItem pass\n");
  5864. }
  5865. return result;
  5866. }
  5867. int sendUnplugByDataTransferRequest(int gun_index)
  5868. {
  5869. mtrace();
  5870. char message[10752]={0};
  5871. char guid[37]={0};
  5872. char tempdata[65]={0};
  5873. int result = FAIL;
  5874. random_uuid(guid);
  5875. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5876. (gun_index+1),
  5877. MESSAGE_TYPE_CALL,
  5878. guid,
  5879. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5880. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5881. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5882. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5883. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5884. {
  5885. result = PASS;
  5886. DEBUG_INFO("DataTransfer mapItem pass\n");
  5887. }
  5888. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5889. return result;
  5890. }
  5891. int sendOcmfByDataTransferRequest(int gun_index)
  5892. {
  5893. mtrace();
  5894. json_object *DataTransfer = json_object_new_object();
  5895. json_object *data = json_object_new_object();
  5896. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5897. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5898. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5899. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5900. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5901. json_object_object_add(DataTransfer, "data", data);
  5902. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5903. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5904. char message[3000]={0};
  5905. char guid[37]={0};
  5906. char tempdata[65]={0};
  5907. int result = FAIL;
  5908. random_uuid(guid);
  5909. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5910. (gun_index+1),
  5911. MESSAGE_TYPE_CALL,
  5912. guid,
  5913. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5914. json_object_put(DataTransfer);
  5915. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5916. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5917. {
  5918. result = PASS;
  5919. DEBUG_INFO("DataTransfer mapItem pass\n");
  5920. }
  5921. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5922. return result;
  5923. }
  5924. int sendDiagnosticsStatusNotificationRequest(char *status)
  5925. {
  5926. mtrace();
  5927. int result = FAIL;
  5928. char message[110]={0};
  5929. char guid[37]={0};
  5930. char tempdata[65]={0};
  5931. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5932. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5933. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5934. random_uuid(guid);
  5935. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5936. LWS_SendNow(message);
  5937. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5938. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5939. {
  5940. result = PASS;
  5941. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5942. }
  5943. //#ifdef SystemLogMessage
  5944. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5945. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5946. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5947. //#endif
  5948. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5949. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5950. //record status
  5951. if(strcmp(status,"Idle")==0)
  5952. {
  5953. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5954. }
  5955. else if(strcmp(status,"Uploaded")==0)
  5956. {
  5957. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5958. }
  5959. else if(strcmp(status,"UploadFailed")==0)
  5960. {
  5961. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5962. }
  5963. else if(strcmp(status,"Uploading")==0)
  5964. {
  5965. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5966. }
  5967. return result;
  5968. }
  5969. int sendFirmwareStatusNotificationRequest(char *status)
  5970. {
  5971. mtrace();
  5972. int result = FAIL;
  5973. char message[110]={0};
  5974. char guid[37]={0};
  5975. char tempdata[65]={0};
  5976. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5977. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5978. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5979. random_uuid(guid);
  5980. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5981. LWS_SendNow(message);
  5982. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5983. 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*/)
  5984. {
  5985. result = PASS;
  5986. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5987. }
  5988. //#ifdef SystemLogMessage
  5989. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5990. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5991. //#endif
  5992. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5993. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5994. //record status
  5995. if(strcmp(status,"Downloaded")==0)
  5996. {
  5997. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5998. }
  5999. else if(strcmp(status,"DownloadFailed")==0)
  6000. {
  6001. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  6002. }
  6003. else if(strcmp(status,"Downloading")==0)
  6004. {
  6005. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  6006. }
  6007. else if(strcmp(status,"Idle")==0)
  6008. {
  6009. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  6010. }
  6011. else if(strcmp(status,"InstallationFailed")==0)
  6012. {
  6013. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  6014. }
  6015. else if(strcmp(status,"Installing")==0)
  6016. {
  6017. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  6018. }
  6019. else if(strcmp(status,"Installed")==0)
  6020. {
  6021. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  6022. }
  6023. return result;
  6024. }
  6025. int sendHeartbeatRequest(int gun_index)
  6026. {
  6027. mtrace();
  6028. int result = FAIL;
  6029. char message[80]={0};
  6030. char guid[37]={0};
  6031. char tempdata[65]={0};
  6032. random_uuid(guid);
  6033. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6034. , MESSAGE_TYPE_CALL
  6035. , guid );
  6036. LWS_Send(message);
  6037. sprintf(tempdata, "Heartbeat,%d", 0);
  6038. 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*/)
  6039. {
  6040. result = PASS;
  6041. }
  6042. return result;
  6043. }
  6044. int sendStartTransactionRequest(int gun_index)
  6045. {
  6046. mtrace();
  6047. int result = FAIL;
  6048. char message[250]={0};
  6049. char guid[37]={0};
  6050. struct timeval tmnow;
  6051. struct tm *tm;
  6052. char buf[28];//, usec_buf[6];
  6053. char tempdata[65]={0};
  6054. int tempIndex = 0;
  6055. DEBUG_INFO("sendStartTransactionRequest...\n");
  6056. gettimeofday(&tmnow, NULL);
  6057. time_t t;
  6058. t = time(NULL);
  6059. /*UTC time and date*/
  6060. tm = gmtime(&t);
  6061. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6062. #if 0 // remove temporally
  6063. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6064. strcat(buf,".");
  6065. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6066. strcat(buf,usec_buf);
  6067. #endif
  6068. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  6069. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  6070. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6071. // clear StartTransaction Response
  6072. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  6073. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  6074. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  6075. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  6076. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6077. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6078. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6079. {
  6080. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6081. {
  6082. tempIndex = ((gun_index==2) ? 1: 0);
  6083. }
  6084. else
  6085. {
  6086. tempIndex = gun_index;
  6087. }
  6088. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6089. {
  6090. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6091. {
  6092. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6093. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  6094. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6095. }
  6096. }
  6097. }
  6098. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6099. {
  6100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6101. {
  6102. tempIndex = ((gun_index==2) ? 1: 0);
  6103. }
  6104. else
  6105. {
  6106. tempIndex = gun_index;
  6107. }
  6108. for (int index = 0; index < CCS_QUANTITY; index++)
  6109. {
  6110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6111. {
  6112. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6113. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  6114. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6115. }
  6116. }
  6117. }
  6118. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6119. {
  6120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6121. {
  6122. tempIndex = ((gun_index==2) ? 1: 0);
  6123. }
  6124. else
  6125. {
  6126. tempIndex = gun_index;
  6127. }
  6128. for (int index = 0; index < GB_QUANTITY; index++)
  6129. {
  6130. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6131. {
  6132. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6133. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  6134. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6135. }
  6136. }
  6137. }
  6138. else if(gunType[gun_index] == GUN_TYPE_DO)
  6139. {
  6140. tempIndex = gun_index;
  6141. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6142. {
  6143. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6144. {
  6145. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6146. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  6147. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6148. }
  6149. }
  6150. }
  6151. else
  6152. {
  6153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6154. {
  6155. tempIndex = 2;
  6156. }
  6157. else
  6158. {
  6159. tempIndex = gun_index;
  6160. }
  6161. for (int index = 0; index < AC_QUANTITY; index++)
  6162. {
  6163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6164. {
  6165. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6166. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  6167. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6168. }
  6169. }
  6170. }
  6171. random_uuid(guid);
  6172. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  6173. {
  6174. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  6175. , gun_index +1
  6176. , MESSAGE_TYPE_CALL
  6177. , guid
  6178. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6179. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6180. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6181. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6182. }
  6183. else
  6184. {
  6185. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  6186. , gun_index +1
  6187. , MESSAGE_TYPE_CALL
  6188. , guid
  6189. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6190. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6191. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6192. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  6193. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6194. }
  6195. #if 1
  6196. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  6197. 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*/)
  6198. {
  6199. result = PASS;
  6200. }
  6201. #endif
  6202. strcpy(queuedata, message);
  6203. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6204. OCPP_insert_transaction_msg(YES, queuedata);
  6205. return result;
  6206. }
  6207. int sendConnector0StatusNotificationRequest()
  6208. {
  6209. mtrace();
  6210. int result = FAIL;
  6211. char message[600]={0};
  6212. char guid[37];
  6213. struct timeval tmnow;
  6214. struct tm *tm;
  6215. char buf[28];//, usec_buf[6];
  6216. char tempdata[65]={0};
  6217. DEBUG_INFO("sendConnector0StatusNotificationRequest...\n");
  6218. gettimeofday(&tmnow, NULL);
  6219. time_t t;
  6220. t = time(NULL);
  6221. /*UTC time and date*/
  6222. tm = gmtime(&t);
  6223. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6224. random_uuid(guid);
  6225. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":0,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6226. , MESSAGE_TYPE_CALL
  6227. , guid
  6228. , "NoError"
  6229. , ""
  6230. , (isConnector0Unavailable()==YES?"Unavailable":"Available")
  6231. , buf
  6232. , ShmSysConfigAndInfo->SysConfig.chargePointVendor
  6233. , "");
  6234. LWS_Send(message);
  6235. sprintf(tempdata, "StatusNotification,%d", 99);
  6236. 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*/)
  6237. {
  6238. //DEBUG_ERROR("statusNotification mapitem pass");
  6239. result = PASS;
  6240. }
  6241. return result;
  6242. }
  6243. int sendStatusNotificationRequest(int gun_index)
  6244. {
  6245. mtrace();
  6246. int result = FAIL;
  6247. char message[600]={0};
  6248. char guid[37];
  6249. int currentStatus = 0;
  6250. struct timeval tmnow;
  6251. struct tm *tm;
  6252. char buf[28];//, usec_buf[6];
  6253. char tempdata[65]={0};
  6254. int tempIndex = 0;
  6255. uint8_t isStateChanged = TRUE;
  6256. uint8_t isContentIllegal = TRUE;
  6257. DEBUG_INFO("sendStatusNotificationRequest...\n");
  6258. gettimeofday(&tmnow, NULL);
  6259. time_t t;
  6260. t = time(NULL);
  6261. /*UTC time and date*/
  6262. tm = gmtime(&t);
  6263. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6264. #if 0 // remove temporally
  6265. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6266. strcat(buf,".");
  6267. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6268. strcat(buf,usec_buf);
  6269. #endif
  6270. //printf("%s",buf);
  6271. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  6272. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6273. // it's option
  6274. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  6275. /*
  6276. enum _SYSTEM_STATUS
  6277. {
  6278. S_BOOTING = 0,
  6279. S_IDLE, = 1
  6280. S_AUTHORIZING, =2
  6281. S_REASSIGN_CHECK, =3
  6282. S_REASSIGN, =4
  6283. S_PRECHARGE, =5
  6284. S_PREPARING_FOR_EV, =6
  6285. S_PREPARING_FOR_EVSE, =7
  6286. S_CHARGING, =8
  6287. S_TERMINATING, =9
  6288. S_COMPLETE, =10
  6289. S_ALARM, =11
  6290. S_FAULT =12
  6291. }
  6292. */
  6293. //check Transaction active
  6294. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6295. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6296. {
  6297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6298. {
  6299. tempIndex = ((gun_index==2) ? 1: 0);
  6300. }
  6301. else
  6302. {
  6303. tempIndex = gun_index;
  6304. }
  6305. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6306. {
  6307. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6308. {
  6309. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6310. {
  6311. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6312. {
  6313. currentStatus = Preparing; //OCPP Status: Preparing
  6314. }
  6315. else
  6316. {
  6317. currentStatus = Available; //OCPP Status: Available
  6318. }
  6319. }
  6320. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6321. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6322. ) //S_PRECHARGE
  6323. {
  6324. currentStatus = Preparing; //OCPP Status: Preparing
  6325. }
  6326. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6327. {
  6328. currentStatus = Charging; //OCPP Status: Charging
  6329. }
  6330. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6331. {
  6332. currentStatus = Finishing; //OCPP Status: Finishing
  6333. }
  6334. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6335. {
  6336. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6337. }
  6338. 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
  6339. {
  6340. currentStatus = Unavailable; //OCPP Status: Unavailable
  6341. }
  6342. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6343. {
  6344. currentStatus = Faulted; //OCPP Status: Faulted
  6345. }
  6346. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6347. {
  6348. currentStatus = Reserved; //OCPP Status: Reserved
  6349. }
  6350. } //end of the same index
  6351. }//end of for CHAdeMO_QUANTITY
  6352. }
  6353. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6354. {
  6355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6356. {
  6357. tempIndex = ((gun_index==2) ? 1: 0);
  6358. }
  6359. else
  6360. {
  6361. tempIndex = gun_index;
  6362. }
  6363. for (int index = 0; index < CCS_QUANTITY; index++)
  6364. {
  6365. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6366. {
  6367. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6368. {
  6369. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6370. {
  6371. currentStatus = Preparing; //OCPP Status: Preparing
  6372. }
  6373. else
  6374. {
  6375. currentStatus = Available; //OCPP Status: Available
  6376. }
  6377. }
  6378. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6379. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6380. ) //S_PRECHARGE
  6381. {
  6382. currentStatus = Preparing; //OCPP Status: Preparing
  6383. }
  6384. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6385. {
  6386. currentStatus = Charging; //OCPP Status: Charging
  6387. }
  6388. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6389. {
  6390. currentStatus = Finishing; //OCPP Status: Finishing
  6391. }
  6392. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6393. {
  6394. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6395. }
  6396. 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
  6397. {
  6398. currentStatus = Unavailable; //OCPP Status : Unavailable
  6399. }
  6400. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6401. {
  6402. currentStatus = Faulted; //OCPP Status: Faulted
  6403. }
  6404. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6405. {
  6406. currentStatus = Reserved; //OCPP Status: Reserved
  6407. }
  6408. } //end of the same index
  6409. } // end of for CCS_QUANTITY
  6410. }
  6411. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6412. {
  6413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6414. {
  6415. tempIndex = ((gun_index==2) ? 1: 0);
  6416. }
  6417. else
  6418. {
  6419. tempIndex = gun_index;
  6420. }
  6421. for (int index = 0; index < GB_QUANTITY; index++)
  6422. {
  6423. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6424. {
  6425. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6426. {
  6427. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6428. {
  6429. currentStatus = Preparing; //OCPP Status: Preparing
  6430. }
  6431. else
  6432. {
  6433. currentStatus = Available; //OCPP Status: Available
  6434. }
  6435. }
  6436. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6437. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6438. ) //S_PRECHARGE
  6439. {
  6440. currentStatus = Preparing; //OCPP Status: Preparing
  6441. }
  6442. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6443. {
  6444. currentStatus = Charging; //OCPP Status: Charging
  6445. }
  6446. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6447. {
  6448. currentStatus = Finishing; //OCPP Status: Finishing
  6449. }
  6450. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6451. {
  6452. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6453. }
  6454. 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
  6455. {
  6456. currentStatus = Unavailable; //OCPP Status: Unavailable
  6457. }
  6458. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6459. {
  6460. currentStatus = Faulted; //OCPP Status: Faulted
  6461. }
  6462. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6463. {
  6464. currentStatus = Reserved; //OCPP Status: Reserved
  6465. }
  6466. } //end of the same index
  6467. } // end of for GB_QUANTITY
  6468. }
  6469. else if(gunType[gun_index] == GUN_TYPE_DO)
  6470. {
  6471. tempIndex = gun_index;
  6472. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6473. {
  6474. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6475. {
  6476. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6477. {
  6478. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6479. {
  6480. currentStatus = Preparing; //OCPP Status: Preparing
  6481. }
  6482. else
  6483. {
  6484. currentStatus = Available; //OCPP Status: Available
  6485. }
  6486. }
  6487. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6488. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6489. ) //S_PRECHARGE
  6490. {
  6491. currentStatus = Preparing; //OCPP Status: Preparing
  6492. }
  6493. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6494. {
  6495. currentStatus = Charging; //OCPP Status: Charging
  6496. }
  6497. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6498. {
  6499. currentStatus = Finishing; //OCPP Status: Finishing
  6500. }
  6501. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6502. {
  6503. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6504. }
  6505. 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
  6506. {
  6507. currentStatus = Unavailable; //OCPP Status: Unavailable
  6508. }
  6509. 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
  6510. {
  6511. currentStatus = Faulted; //OCPP Status: Faulted
  6512. }
  6513. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6514. {
  6515. currentStatus = Reserved; //OCPP Status: Reserved
  6516. }
  6517. } //end of the same index
  6518. }
  6519. }
  6520. else
  6521. {
  6522. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6523. {
  6524. tempIndex = 2;
  6525. }
  6526. else
  6527. {
  6528. tempIndex = gun_index;
  6529. }
  6530. for (int index = 0; index < AC_QUANTITY; index++)
  6531. {
  6532. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6533. {
  6534. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6535. {
  6536. 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))
  6537. {
  6538. currentStatus = Preparing; //OCPP Status: Preparing
  6539. }
  6540. else
  6541. {
  6542. currentStatus = Available; //OCPP Status: Available
  6543. }
  6544. }
  6545. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6546. {
  6547. currentStatus = Preparing; //OCPP Status: Preparing
  6548. }
  6549. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6550. {
  6551. currentStatus = Charging; //OCPP Status: Charging
  6552. }
  6553. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6554. {
  6555. currentStatus = Finishing; //OCPP Status: Finishing
  6556. }
  6557. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6558. {
  6559. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6560. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6561. else
  6562. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6563. }
  6564. 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
  6565. {
  6566. currentStatus = Unavailable; //OCPP Status: Unavailable
  6567. }
  6568. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6569. {
  6570. currentStatus = Faulted; //OCPP Status: Faulted
  6571. }
  6572. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6573. {
  6574. currentStatus = Reserved; //OCPP Status: Reserved
  6575. }
  6576. }//end of the same index
  6577. }//end of for AC_QUANTITY
  6578. }
  6579. //it's option
  6580. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6581. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6582. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6583. {
  6584. isStateChanged = FALSE;
  6585. }
  6586. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6587. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6588. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6589. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6590. isContentIllegal = TRUE;
  6591. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6592. {
  6593. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6594. {
  6595. isContentIllegal = FALSE;
  6596. break;
  6597. }
  6598. }
  6599. if(isContentIllegal)
  6600. {
  6601. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6602. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6603. }
  6604. random_uuid(guid);
  6605. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6606. , MESSAGE_TYPE_CALL
  6607. , guid
  6608. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6609. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6610. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6611. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6612. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6613. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6614. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6615. if((server_sign == TRUE) && isStateChanged)
  6616. {
  6617. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6618. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6619. LWS_Send(message);
  6620. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6621. 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*/)
  6622. {
  6623. //DEBUG_ERROR("statusNotification mapitem pass");
  6624. result = PASS;
  6625. }
  6626. }
  6627. else
  6628. {
  6629. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6630. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6631. result = PASS;
  6632. }
  6633. return result;
  6634. }
  6635. int sendStopTransactionRequest(int gun_index)
  6636. {
  6637. mtrace();
  6638. int result = FAIL;
  6639. //char message[1500]={0};
  6640. char guid[37]={0};
  6641. char tempdata[65]={0};
  6642. int tempIndex = 0;
  6643. char TempStopTransaction[256];
  6644. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6645. DEBUG_INFO("sendStopTransactionRequest \n");
  6646. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6647. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6648. //=========================== Stop Transaction Time ===============================================
  6649. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  6650. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6651. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6652. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6653. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6654. {
  6655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6656. {
  6657. tempIndex = ((gun_index==2) ? 1: 0);
  6658. }
  6659. else
  6660. {
  6661. tempIndex = gun_index;
  6662. }
  6663. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6664. {
  6665. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6666. {
  6667. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6668. }
  6669. }// END OF CHAdeMO_QUANTITY
  6670. }
  6671. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6672. {
  6673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6674. {
  6675. tempIndex = ((gun_index==2) ? 1: 0);
  6676. }
  6677. else
  6678. {
  6679. tempIndex = gun_index;
  6680. }
  6681. for (int index = 0; index < CCS_QUANTITY; index++)
  6682. {
  6683. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6684. {
  6685. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6686. }
  6687. }// END OF CCS_QUANTITY
  6688. }
  6689. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6690. {
  6691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6692. {
  6693. tempIndex = ((gun_index==2) ? 1: 0);
  6694. }
  6695. else
  6696. {
  6697. tempIndex = gun_index;
  6698. }
  6699. for (int index = 0; index < GB_QUANTITY; index++)
  6700. {
  6701. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6702. {
  6703. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6704. }
  6705. }// END OF GB_QUANTITY
  6706. }
  6707. else if(gunType[gun_index] == GUN_TYPE_DO)
  6708. {
  6709. tempIndex = gun_index;
  6710. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6711. {
  6712. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6713. {
  6714. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6715. }
  6716. }// END OF GB_QUANTITY
  6717. }
  6718. else
  6719. {
  6720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6721. {
  6722. tempIndex = 2;
  6723. }
  6724. else
  6725. {
  6726. tempIndex = gun_index;
  6727. }
  6728. for (int index = 0; index < AC_QUANTITY; index++)
  6729. {
  6730. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6731. {
  6732. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6733. }
  6734. }// END OF AC_QUANTITY
  6735. }
  6736. //================================================ Message create ====================================================
  6737. json_object *StopTransaction = json_object_new_object();
  6738. json_object *transactionDatas = json_object_new_array();
  6739. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6740. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6741. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6742. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6743. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6744. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6745. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6746. meterValueBufferQuery(gun_index, transactionDatas);
  6747. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6748. random_uuid(guid);
  6749. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6750. ,MESSAGE_TYPE_CALL
  6751. ,guid
  6752. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6753. json_object_put(StopTransaction);
  6754. #if 1 // for TempStopTransaction
  6755. //Delete TempStopTransaction
  6756. if((access(TempStopTransaction,F_OK))!=-1)
  6757. {
  6758. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6759. }
  6760. #endif
  6761. #if 1
  6762. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6763. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6764. {
  6765. result = PASS;
  6766. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6767. }
  6768. #endif
  6769. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6770. OCPP_insert_transaction_msg(NO, queuedata);
  6771. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6772. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6773. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6774. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6775. {
  6776. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6777. }
  6778. //for test
  6779. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6780. return result;
  6781. }
  6782. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6783. {
  6784. mtrace();
  6785. int result = FAIL;
  6786. char guid[37]={0};
  6787. char tempdata[65]={0};
  6788. int tempIndex = 0;
  6789. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6790. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6791. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6792. //set value
  6793. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6794. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6795. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6796. -1);
  6797. random_uuid(guid);
  6798. //UTC Date time
  6799. struct timeval tmnow;
  6800. struct tm *tm;
  6801. char buf[28];//, usec_buf[6];
  6802. gettimeofday(&tmnow, NULL);
  6803. time_t t;
  6804. t = time(NULL);
  6805. /*UTC time and date*/
  6806. tm = gmtime(&t);
  6807. if(dataType == ReadingContext_Sample_Clock)
  6808. {
  6809. struct tm *tmTarget;
  6810. struct timeb tbTarget;
  6811. tbTarget.time = mktime(tm);
  6812. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6813. tmTarget = gmtime(&tbTarget.time);
  6814. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6815. }
  6816. else
  6817. {
  6818. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6819. }
  6820. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6821. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6822. //********************************(1)Current.Import L1************************************************/
  6823. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6824. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6825. (dataType == ReadingContext_Trigger))
  6826. {
  6827. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6828. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6829. {
  6830. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6831. {
  6832. tempIndex = ((gun_index==2) ? 1: 0);
  6833. }
  6834. else
  6835. {
  6836. tempIndex = gun_index;
  6837. }
  6838. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6839. {
  6840. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6841. {
  6842. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6843. }
  6844. }
  6845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6846. }
  6847. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6848. {
  6849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6850. {
  6851. tempIndex = ((gun_index==2) ? 1: 0);
  6852. }
  6853. else
  6854. {
  6855. tempIndex = gun_index;
  6856. }
  6857. for (int index = 0; index < CCS_QUANTITY; index++)
  6858. {
  6859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6860. {
  6861. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6862. }
  6863. }
  6864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6865. }
  6866. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6867. {
  6868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6869. {
  6870. tempIndex = ((gun_index==2) ? 1: 0);
  6871. }
  6872. else
  6873. {
  6874. tempIndex = gun_index;
  6875. }
  6876. for (int index = 0; index < GB_QUANTITY; index++)
  6877. {
  6878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6879. {
  6880. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6881. }
  6882. }
  6883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6884. }
  6885. else if(gunType[gun_index] == GUN_TYPE_DO)
  6886. {
  6887. tempIndex = gun_index;
  6888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6889. {
  6890. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6891. {
  6892. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6893. }
  6894. }
  6895. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6896. }
  6897. else
  6898. {
  6899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6900. {
  6901. tempIndex = 2;
  6902. }
  6903. else
  6904. {
  6905. tempIndex = gun_index;
  6906. }
  6907. for (int index = 0; index < AC_QUANTITY; index++)
  6908. {
  6909. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6910. {
  6911. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6912. }
  6913. }
  6914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6915. }
  6916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6921. }
  6922. //********************************(2)Energy.Active.Import.Register ************************************************/
  6923. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6924. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6925. (dataType == ReadingContext_Trigger))
  6926. {
  6927. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6928. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6929. {
  6930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6931. {
  6932. tempIndex = ((gun_index==2) ? 1: 0);
  6933. }
  6934. else
  6935. {
  6936. tempIndex = gun_index;
  6937. }
  6938. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6939. {
  6940. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6941. {
  6942. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6943. }
  6944. }
  6945. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6946. }
  6947. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6948. {
  6949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6950. {
  6951. tempIndex = ((gun_index==2) ? 1: 0);
  6952. }
  6953. else
  6954. {
  6955. tempIndex = gun_index;
  6956. }
  6957. for (int index = 0; index < CCS_QUANTITY; index++)
  6958. {
  6959. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6960. {
  6961. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6962. }
  6963. }
  6964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6965. }
  6966. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6967. {
  6968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6969. {
  6970. tempIndex = ((gun_index==2) ? 1: 0);
  6971. }
  6972. else
  6973. {
  6974. tempIndex = gun_index;
  6975. }
  6976. for (int index = 0; index < GB_QUANTITY; index++)
  6977. {
  6978. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6979. {
  6980. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6981. }
  6982. }
  6983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6984. }
  6985. else if(gunType[gun_index] == GUN_TYPE_DO)
  6986. {
  6987. tempIndex = gun_index;
  6988. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6989. {
  6990. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6991. {
  6992. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6993. }
  6994. }
  6995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6996. }
  6997. else
  6998. {
  6999. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7000. {
  7001. tempIndex = 2;
  7002. }
  7003. else
  7004. {
  7005. tempIndex = gun_index;
  7006. }
  7007. for (int index = 0; index < AC_QUANTITY; index++)
  7008. {
  7009. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7010. {
  7011. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7012. }
  7013. }
  7014. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7015. }
  7016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7017. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7018. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7020. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7021. }
  7022. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7023. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7024. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7025. (dataType == ReadingContext_Trigger))
  7026. {
  7027. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7028. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7029. {
  7030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7031. {
  7032. tempIndex = ((gun_index==2) ? 1: 0);
  7033. }
  7034. else
  7035. {
  7036. tempIndex = gun_index;
  7037. }
  7038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7039. {
  7040. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7041. {
  7042. if(dataType == ReadingContext_Sample_Clock)
  7043. {
  7044. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7045. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7046. }
  7047. else if(dataType == ReadingContext_Sample_Periodic)
  7048. {
  7049. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7050. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7051. }
  7052. else
  7053. {
  7054. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7055. }
  7056. }
  7057. } // END OF FOR CHAdeMO_QUANTITY
  7058. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7059. }
  7060. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7061. {
  7062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7063. {
  7064. tempIndex = ((gun_index==2) ? 1: 0);
  7065. }
  7066. else
  7067. {
  7068. tempIndex = gun_index;
  7069. }
  7070. for (int index = 0; index < CCS_QUANTITY; index++)
  7071. {
  7072. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7073. {
  7074. if(dataType == ReadingContext_Sample_Clock)
  7075. {
  7076. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7077. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7078. }
  7079. else if(dataType == ReadingContext_Sample_Periodic)
  7080. {
  7081. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7082. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7083. }
  7084. else
  7085. {
  7086. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7087. }
  7088. }
  7089. } // END OF CCS_QUANTITY
  7090. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7091. }
  7092. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7093. {
  7094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7095. {
  7096. tempIndex = ((gun_index==2) ? 1: 0);
  7097. }
  7098. else
  7099. {
  7100. tempIndex = gun_index;
  7101. }
  7102. for (int index = 0; index < GB_QUANTITY; index++)
  7103. {
  7104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7105. {
  7106. if(dataType == ReadingContext_Sample_Clock)
  7107. {
  7108. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7109. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7110. }
  7111. else if(dataType == ReadingContext_Sample_Periodic)
  7112. {
  7113. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7114. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7115. }
  7116. else
  7117. {
  7118. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7119. }
  7120. }
  7121. } // END OF GB_QUANTITY
  7122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7123. }
  7124. else if(gunType[gun_index] == GUN_TYPE_DO)
  7125. {
  7126. tempIndex = gun_index;
  7127. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7128. {
  7129. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7130. {
  7131. if(dataType == ReadingContext_Sample_Clock)
  7132. {
  7133. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7134. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7135. }
  7136. else if(dataType == ReadingContext_Sample_Periodic)
  7137. {
  7138. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7139. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7140. }
  7141. else
  7142. {
  7143. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7144. }
  7145. }
  7146. }
  7147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7148. }
  7149. else
  7150. {
  7151. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7152. {
  7153. tempIndex = 2;
  7154. }
  7155. else
  7156. {
  7157. tempIndex = gun_index;
  7158. }
  7159. for (int index = 0; index < AC_QUANTITY; index++)
  7160. {
  7161. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7162. {
  7163. if(dataType == ReadingContext_Sample_Clock)
  7164. {
  7165. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7166. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7167. }
  7168. else if(dataType == ReadingContext_Sample_Periodic)
  7169. {
  7170. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7171. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7172. }
  7173. else
  7174. {
  7175. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7176. }
  7177. }
  7178. }
  7179. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7180. }
  7181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7186. }
  7187. //********************************(4)Power.Active.Import************************************************/
  7188. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7189. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7190. (dataType == ReadingContext_Trigger))
  7191. {
  7192. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7193. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7194. {
  7195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7196. {
  7197. tempIndex = ((gun_index==2) ? 1: 0);
  7198. }
  7199. else
  7200. {
  7201. tempIndex = gun_index;
  7202. }
  7203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7204. {
  7205. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7206. {
  7207. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7208. }
  7209. } // END OF FOR
  7210. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7211. }
  7212. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7213. {
  7214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7215. {
  7216. tempIndex = ((gun_index==2) ? 1: 0);
  7217. }
  7218. else
  7219. {
  7220. tempIndex = gun_index;
  7221. }
  7222. for (int index = 0; index < CCS_QUANTITY; index++)
  7223. {
  7224. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7225. {
  7226. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7227. }
  7228. }
  7229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7230. }
  7231. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7232. {
  7233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7234. {
  7235. tempIndex = ((gun_index==2) ? 1: 0);
  7236. }
  7237. else
  7238. {
  7239. tempIndex = gun_index;
  7240. }
  7241. for (int index = 0; index < GB_QUANTITY; index++)
  7242. {
  7243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7244. {
  7245. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7246. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7247. }
  7248. }
  7249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7250. }
  7251. else if(gunType[gun_index] == GUN_TYPE_DO)
  7252. {
  7253. tempIndex = gun_index;
  7254. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7255. {
  7256. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7257. {
  7258. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7259. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7260. }
  7261. }
  7262. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7263. }
  7264. else
  7265. {
  7266. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7267. {
  7268. tempIndex = 2;
  7269. }
  7270. else
  7271. {
  7272. tempIndex = gun_index;
  7273. }
  7274. for (int index = 0; index < AC_QUANTITY; index++)
  7275. {
  7276. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7277. {
  7278. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7279. }
  7280. }
  7281. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7282. }
  7283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7286. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7288. }
  7289. //***********************************************(5)VOLTAGE L1******************************************************/
  7290. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7291. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7292. (dataType == ReadingContext_Trigger))
  7293. {
  7294. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7295. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7296. {
  7297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7298. {
  7299. tempIndex = ((gun_index==2) ? 1: 0);
  7300. }
  7301. else
  7302. {
  7303. tempIndex = gun_index;
  7304. }
  7305. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7306. {
  7307. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7308. {
  7309. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7310. }
  7311. }
  7312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7313. }
  7314. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7315. {
  7316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7317. {
  7318. tempIndex = ((gun_index==2) ? 1: 0);
  7319. }
  7320. else
  7321. {
  7322. tempIndex = gun_index;
  7323. }
  7324. for (int index = 0; index < CCS_QUANTITY; index++)
  7325. {
  7326. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7327. {
  7328. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7329. }
  7330. }
  7331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7332. }
  7333. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7334. {
  7335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7336. {
  7337. tempIndex = ((gun_index==2) ? 1: 0);
  7338. }
  7339. else
  7340. {
  7341. tempIndex = gun_index;
  7342. }
  7343. for (int index = 0; index < GB_QUANTITY; index++)
  7344. {
  7345. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7346. {
  7347. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7348. }
  7349. }
  7350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7351. }
  7352. else if(gunType[gun_index] == GUN_TYPE_DO)
  7353. {
  7354. tempIndex = gun_index;
  7355. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7356. {
  7357. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7358. {
  7359. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7360. }
  7361. }
  7362. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7363. }
  7364. else
  7365. {
  7366. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7367. {
  7368. tempIndex = 2;
  7369. }
  7370. else
  7371. {
  7372. tempIndex = gun_index;
  7373. }
  7374. for (int index = 0; index < AC_QUANTITY; index++)
  7375. {
  7376. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7377. {
  7378. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7379. }
  7380. }
  7381. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7382. }
  7383. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7384. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7388. }
  7389. //***********************************************(6)SOC******************************************************/
  7390. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7391. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7392. (dataType == ReadingContext_Trigger))
  7393. {
  7394. 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))
  7395. {
  7396. //idx_sample=5;
  7397. //sampledValue = NULL;
  7398. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7399. {
  7400. tempIndex = ((gun_index==2) ? 1: 0);
  7401. }
  7402. else
  7403. {
  7404. tempIndex = gun_index;
  7405. }
  7406. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7407. {
  7408. //tempIndex = ((gun_index==2) ? 1: 0);
  7409. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7410. {
  7411. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7412. {
  7413. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7414. }
  7415. }
  7416. }
  7417. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7418. {
  7419. //tempIndex = ((gun_index==2) ? 1: 0);
  7420. for (int index = 0; index < CCS_QUANTITY; index++)
  7421. {
  7422. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7423. {
  7424. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7425. }
  7426. }
  7427. }
  7428. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7429. {
  7430. //tempIndex = ((gun_index==2) ? 1: 0);
  7431. for (int index = 0; index < GB_QUANTITY; index++)
  7432. {
  7433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7434. {
  7435. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7436. }
  7437. }
  7438. }
  7439. else if(gunType[gun_index] == GUN_TYPE_DO)
  7440. {
  7441. //tempIndex = ((gun_index==2) ? 1: 0);
  7442. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7443. {
  7444. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7445. {
  7446. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7447. }
  7448. }
  7449. }
  7450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7453. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7454. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7455. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7456. }
  7457. }
  7458. //********************************(7)Current.Import L2************************************************/
  7459. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7460. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7461. (dataType == ReadingContext_Trigger))
  7462. {
  7463. // Only for AC 3 phase
  7464. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7465. {
  7466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7467. {
  7468. tempIndex = 2;
  7469. }
  7470. else
  7471. {
  7472. tempIndex = gun_index;
  7473. }
  7474. for (int index = 0; index < AC_QUANTITY; index++)
  7475. {
  7476. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7477. {
  7478. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7479. }
  7480. }
  7481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7482. }
  7483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7488. }
  7489. //********************************(8)Current.Import L3************************************************/
  7490. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7491. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7492. (dataType == ReadingContext_Trigger))
  7493. {
  7494. // Only for AC 3 phase
  7495. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7496. {
  7497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7498. {
  7499. tempIndex = 2;
  7500. }
  7501. else
  7502. {
  7503. tempIndex = gun_index;
  7504. }
  7505. for (int index = 0; index < AC_QUANTITY; index++)
  7506. {
  7507. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7508. {
  7509. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7510. }
  7511. }
  7512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7513. }
  7514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7515. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7519. }
  7520. //***********************************************(9)VOLTAGE L2******************************************************/
  7521. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7522. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7523. (dataType == ReadingContext_Trigger))
  7524. {
  7525. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7526. {
  7527. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7528. {
  7529. tempIndex = 2;
  7530. }
  7531. else
  7532. {
  7533. tempIndex = gun_index;
  7534. }
  7535. for (int index = 0; index < AC_QUANTITY; index++)
  7536. {
  7537. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7538. {
  7539. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7540. }
  7541. }
  7542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7543. }
  7544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7549. }
  7550. //***********************************************(10)VOLTAGE L3******************************************************/
  7551. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7552. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7553. (dataType == ReadingContext_Trigger))
  7554. {
  7555. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7556. {
  7557. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7558. {
  7559. tempIndex = 2;
  7560. }
  7561. else
  7562. {
  7563. tempIndex = gun_index;
  7564. }
  7565. for (int index = 0; index < AC_QUANTITY; index++)
  7566. {
  7567. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7568. {
  7569. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7570. }
  7571. }
  7572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7573. }
  7574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7579. }
  7580. //***********************************************(11)Current.Offered******************************************************/
  7581. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7582. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7583. (dataType == ReadingContext_Trigger))
  7584. {
  7585. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7586. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7587. {
  7588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7589. {
  7590. tempIndex = ((gun_index==2) ? 1: 0);
  7591. }
  7592. else
  7593. {
  7594. tempIndex = gun_index;
  7595. }
  7596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7597. {
  7598. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7599. {
  7600. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7601. }
  7602. } // END OF FOR CHAdeMO_QUANTITY
  7603. }
  7604. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7605. {
  7606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7607. {
  7608. tempIndex = ((gun_index==2) ? 1: 0);
  7609. }
  7610. else
  7611. {
  7612. tempIndex = gun_index;
  7613. }
  7614. for (int index = 0; index < CCS_QUANTITY; index++)
  7615. {
  7616. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7617. {
  7618. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7619. }
  7620. } // END OF CCS_QUANTITY
  7621. }
  7622. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7623. {
  7624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7625. {
  7626. tempIndex = ((gun_index==2) ? 1: 0);
  7627. }
  7628. else
  7629. {
  7630. tempIndex = gun_index;
  7631. }
  7632. for (int index = 0; index < GB_QUANTITY; index++)
  7633. {
  7634. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7635. {
  7636. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7637. }
  7638. } // END OF GB_QUANTITY
  7639. }
  7640. else if(gunType[gun_index] == GUN_TYPE_DO)
  7641. {
  7642. tempIndex = gun_index;
  7643. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7644. {
  7645. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7646. {
  7647. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7648. }
  7649. }
  7650. }
  7651. else
  7652. {
  7653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7654. {
  7655. tempIndex = 2;
  7656. }
  7657. else
  7658. {
  7659. tempIndex = gun_index;
  7660. }
  7661. for (int index = 0; index < AC_QUANTITY; index++)
  7662. {
  7663. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7664. {
  7665. uint16_t currentOffer;
  7666. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7667. {
  7668. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7669. }
  7670. else
  7671. {
  7672. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7673. }
  7674. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7675. }
  7676. }
  7677. }
  7678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7683. }
  7684. //***********************************************(12)Power.Offered******************************************************/
  7685. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7686. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7687. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7688. {
  7689. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7690. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7691. {
  7692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7693. {
  7694. tempIndex = ((gun_index==2) ? 1: 0);
  7695. }
  7696. else
  7697. {
  7698. tempIndex = gun_index;
  7699. }
  7700. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7701. {
  7702. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7703. {
  7704. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7705. }
  7706. } // END OF FOR CHAdeMO_QUANTITY
  7707. }
  7708. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7709. {
  7710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7711. {
  7712. tempIndex = ((gun_index==2) ? 1: 0);
  7713. }
  7714. else
  7715. {
  7716. tempIndex = gun_index;
  7717. }
  7718. for (int index = 0; index < CCS_QUANTITY; index++)
  7719. {
  7720. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7721. {
  7722. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7723. }
  7724. } // END OF CCS_QUANTITY
  7725. }
  7726. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7727. {
  7728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7729. {
  7730. tempIndex = ((gun_index==2) ? 1: 0);
  7731. }
  7732. else
  7733. {
  7734. tempIndex = gun_index;
  7735. }
  7736. for (int index = 0; index < GB_QUANTITY; index++)
  7737. {
  7738. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7739. {
  7740. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7741. }
  7742. } // END OF GB_QUANTITY
  7743. }
  7744. else if(gunType[gun_index] == GUN_TYPE_DO)
  7745. {
  7746. tempIndex = gun_index;
  7747. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7748. {
  7749. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7750. {
  7751. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7752. }
  7753. }
  7754. }
  7755. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7760. }
  7761. // Message create ====================================================================================================
  7762. if(TRUE)
  7763. {
  7764. json_object *MeterValueReq = json_object_new_object();
  7765. json_object *MeterValues = json_object_new_array();
  7766. json_object *sampledValues = json_object_new_array();
  7767. json_object *sampledValuesBuffer = json_object_new_array();
  7768. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7769. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7770. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7771. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7772. {
  7773. json_object *MeterValue = json_object_new_object();
  7774. json_object *MeterValueBuffer = json_object_new_object();
  7775. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7776. {
  7777. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7778. {
  7779. json_object *sampledValue = json_object_new_object();
  7780. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7781. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7782. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7783. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7784. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7785. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7786. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7787. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7788. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7789. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7790. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7791. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7792. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7793. json_object_array_add(sampledValues, sampledValue);
  7794. // For StopTxn data
  7795. 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)) ||
  7796. ((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)))
  7797. {
  7798. json_object *sampledValue = json_object_new_object();
  7799. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7800. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7801. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7802. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7803. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7804. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7805. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7806. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7807. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7808. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7809. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7810. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7811. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7812. json_object_array_add(sampledValuesBuffer, sampledValue);
  7813. }
  7814. }
  7815. }
  7816. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7817. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7818. json_object_array_add(MeterValues, MeterValue);
  7819. // For StopTxn data
  7820. if((dataType != ReadingContext_Trigger) &&
  7821. (json_object_array_length(sampledValuesBuffer) > 0))
  7822. {
  7823. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7824. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  7825. 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));
  7826. json_object_put(MeterValueBuffer);
  7827. }
  7828. else
  7829. {
  7830. json_object_put(sampledValuesBuffer);
  7831. json_object_put(MeterValueBuffer);
  7832. }
  7833. }
  7834. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7835. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7836. ,gun_index + 1
  7837. ,MESSAGE_TYPE_CALL
  7838. ,guid
  7839. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7840. json_object_put(MeterValueReq);
  7841. }
  7842. // Put request guid to hash map
  7843. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7844. 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*/)
  7845. {
  7846. result = PASS;
  7847. //DEBUG_INFO("MeterValues mapitem pass\n");
  7848. }
  7849. if((dataType != ReadingContext_Trigger) &&
  7850. (dataType != ReadingContext_Sample_Clock) &&
  7851. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7852. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7853. else
  7854. {
  7855. if(FirstHeartBeat)
  7856. LWS_Send(queuedata +2);
  7857. }
  7858. return result;
  7859. }
  7860. int sendLogStatusNotificationRequest(char *status)
  7861. {
  7862. mtrace();
  7863. int result = PASS;
  7864. char message[4096]={0};
  7865. char guid[37]={0};
  7866. char tempdata[128]={0};
  7867. json_object *LogStatusNotification = json_object_new_object();
  7868. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7869. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7870. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7871. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7872. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7873. random_uuid(guid);
  7874. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7875. json_object_put(LogStatusNotification);
  7876. LWS_Send(message);
  7877. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7878. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7879. {
  7880. result = PASS;
  7881. }
  7882. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7883. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7884. return result;
  7885. }
  7886. int sendSecurityEventNotificationRequest()
  7887. {
  7888. mtrace();
  7889. int result = PASS;
  7890. char message[4096]={0};
  7891. char guid[37]={0};
  7892. char tempdata[128]={0};
  7893. json_object *SecurityEventNotification = json_object_new_object();
  7894. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7895. //Stop Transaction Time
  7896. struct timeval tmnow;
  7897. struct tm *tm;
  7898. gettimeofday(&tmnow, NULL);
  7899. time_t t;
  7900. t = time(NULL);
  7901. /*UTC time and date*/
  7902. tm = gmtime(&t);
  7903. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7904. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7905. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7906. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7907. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7908. random_uuid(guid);
  7909. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7910. json_object_put(SecurityEventNotification);
  7911. LWS_Send(message);
  7912. sprintf(tempdata, "SecurityEventNotification,0");
  7913. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7914. {
  7915. result = PASS;
  7916. }
  7917. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7918. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7919. return result;
  7920. }
  7921. int sendSignCertificateRequest()
  7922. {
  7923. mtrace();
  7924. int result = PASS;
  7925. char message[4096]={0};
  7926. char guid[37]={0};
  7927. char tempdata[128]={0};
  7928. json_object *SignCertificate = json_object_new_object();
  7929. DEBUG_INFO("sendSignCertificateRequest...\n");
  7930. // Read csr file content
  7931. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7932. FILE *fp=fopen(CSR_CP,"r");
  7933. char *line = NULL;
  7934. size_t len = 0;
  7935. while(getline(&line, &len, fp) != -1)
  7936. {
  7937. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7938. {
  7939. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7940. }
  7941. }
  7942. fclose(fp);
  7943. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7944. random_uuid(guid);
  7945. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7946. json_object_put(SignCertificate);
  7947. LWS_Send(message);
  7948. sprintf(tempdata, "SignCertificate,0");
  7949. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7950. {
  7951. result = PASS;
  7952. }
  7953. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7954. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7955. return result;
  7956. }
  7957. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7958. {
  7959. mtrace();
  7960. int result = PASS;
  7961. char message[4096]={0};
  7962. char guid[37]={0};
  7963. char tempdata[128]={0};
  7964. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  7965. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7966. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7967. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7968. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7969. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7970. random_uuid(guid);
  7971. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7972. json_object_put(SignedFirmwareStatusNotification);
  7973. LWS_Send(message);
  7974. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  7975. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7976. {
  7977. result = PASS;
  7978. }
  7979. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7980. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7981. return result;
  7982. }
  7983. //==========================================
  7984. // send confirm routine
  7985. //==========================================
  7986. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7987. {
  7988. mtrace();
  7989. int result = FAIL;
  7990. char message[100]={0};
  7991. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7992. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7993. LWS_Send(message);
  7994. result = TRUE;
  7995. return result;
  7996. }
  7997. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7998. {
  7999. mtrace();
  8000. int result = FAIL;
  8001. char message[100]={0};
  8002. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8003. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8004. LWS_Send(message);
  8005. result = TRUE;
  8006. return result;
  8007. }
  8008. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8009. {
  8010. mtrace();
  8011. int result = FAIL;
  8012. char message[100]={0};
  8013. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8014. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8015. LWS_Send(message);
  8016. result = TRUE;
  8017. return result;
  8018. }
  8019. int sendClearCacheConfirmation(char *uuid,char *payload)
  8020. {
  8021. mtrace();
  8022. int result = FAIL;
  8023. char message[500]={0};
  8024. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8025. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8026. LWS_Send(message);
  8027. return result;
  8028. }
  8029. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8030. {
  8031. mtrace();
  8032. int result = FAIL;
  8033. char message[500]={0};
  8034. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8035. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8036. LWS_Send(message);
  8037. return result;
  8038. }
  8039. int sendDataTransferConfirmation(char *uuid,char *payload)
  8040. {
  8041. mtrace();
  8042. char statusStr[20]={0};
  8043. char dataStr[10]={0};
  8044. char sstr[20]={0};
  8045. int c = 0;
  8046. char *loc;
  8047. int result = FAIL;
  8048. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8049. /**********************status**************************/
  8050. loc = strstr(payload, "status");
  8051. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8052. c = 0;
  8053. while (loc[3+strlen("status")+c] != '\"')
  8054. {
  8055. sstr[c] = loc[3+strlen("status")+c];
  8056. c++;
  8057. }
  8058. sstr[c] = '\0';
  8059. strcpy(statusStr, sstr);
  8060. /**********************data**************************/
  8061. loc = strstr(payload, "data");
  8062. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8063. c = 0;
  8064. while (loc[3+strlen("data")+c] != '\"')
  8065. {
  8066. sstr[c] = loc[3+strlen("data")+c];
  8067. c++;
  8068. }
  8069. sstr[c] = '\0';
  8070. strcpy(dataStr, sstr);
  8071. return result;
  8072. }
  8073. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8074. {
  8075. mtrace();
  8076. int result = FAIL;
  8077. char message[1000]={0};
  8078. int CompositeScheduleIndex = 0;
  8079. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8080. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8081. if(nPeriod == 0)
  8082. {
  8083. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8084. {
  8085. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8086. ,MESSAGE_TYPE_CALLRESULT
  8087. ,uuid
  8088. ,payload
  8089. ,connectorIdInt);
  8090. }
  8091. else
  8092. {
  8093. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8094. ,MESSAGE_TYPE_CALLRESULT
  8095. ,uuid
  8096. ,payload
  8097. ,connectorIdInt
  8098. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8099. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8100. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8101. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8102. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8103. }
  8104. }
  8105. else
  8106. {
  8107. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8108. ,MESSAGE_TYPE_CALLRESULT
  8109. ,uuid
  8110. ,payload
  8111. ,connectorIdInt
  8112. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8113. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8114. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8115. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8116. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8117. {
  8118. if (idx_sample == 0)
  8119. {
  8120. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8121. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8122. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8123. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8124. }
  8125. else
  8126. {
  8127. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8128. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8129. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8130. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8131. }
  8132. }
  8133. sprintf(message + strlen(message), "]}}]");
  8134. }
  8135. LWS_Send(message);
  8136. result = TRUE;
  8137. return result;
  8138. }
  8139. int sendGetConfigurationConfirmation(char *uuid)
  8140. {
  8141. mtrace();
  8142. int result = FAIL;
  8143. int MaxKeySupported = 0;
  8144. int sentConfigurationNumber= 0;
  8145. int sentunConfigurationNumber= 0;
  8146. char message[1024*10]={0};
  8147. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8148. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8149. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8150. ,MESSAGE_TYPE_CALLRESULT
  8151. ,uuid );
  8152. //configuration key
  8153. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8154. {
  8155. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8156. {
  8157. if (sentConfigurationNumber == 0)
  8158. {
  8159. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8160. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8161. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8162. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8163. }
  8164. else
  8165. {
  8166. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8167. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8168. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8169. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8170. }
  8171. sentConfigurationNumber = sentConfigurationNumber + 1;
  8172. }
  8173. }
  8174. sprintf(message + strlen(message), "]");
  8175. if(UnknownKeynum != 0)
  8176. {
  8177. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8178. //unkown key
  8179. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8180. {
  8181. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8182. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8183. if(sentunConfigurationNumber == 0)
  8184. {
  8185. sprintf(message + strlen(message), "\"%s\""
  8186. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8187. }
  8188. else
  8189. {
  8190. sprintf(message + strlen(message), ",\"%s\""
  8191. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8192. }
  8193. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8194. }
  8195. sprintf(message + strlen(message), "]");
  8196. }
  8197. sprintf(message + strlen(message), "}]");
  8198. LWS_Send(message);
  8199. return result;
  8200. }
  8201. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8202. {
  8203. mtrace();
  8204. int result = FAIL;
  8205. char message[400]={0};
  8206. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8207. if(strcmp(payload,"")==0)
  8208. {
  8209. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8210. }
  8211. else
  8212. {
  8213. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8214. }
  8215. LWS_Send(message);
  8216. result = TRUE;
  8217. return result;
  8218. }
  8219. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8220. {
  8221. mtrace();
  8222. int result = FAIL;
  8223. char message[80]={0};
  8224. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8225. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8226. LWS_Send(message);
  8227. result = TRUE;
  8228. return result;
  8229. }
  8230. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8231. {
  8232. mtrace();
  8233. int result = FAIL;
  8234. char message[80]={0};
  8235. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8236. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8237. LWS_Send(message);
  8238. result = TRUE;
  8239. return result;
  8240. }
  8241. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8242. {
  8243. mtrace();
  8244. int result = FAIL;
  8245. char message[80]={0};
  8246. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8247. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8248. LWS_Send(message);
  8249. result = TRUE;
  8250. return result;
  8251. }
  8252. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8253. {
  8254. mtrace();
  8255. int result = FAIL;
  8256. char message[80]={0};
  8257. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8258. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8259. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8260. LWS_Send(message);
  8261. result = TRUE;
  8262. return result;
  8263. }
  8264. int sendResetConfirmation(char *uuid,char *payload)
  8265. {
  8266. mtrace();
  8267. int result = FAIL;
  8268. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8269. char message[80]={0};
  8270. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8271. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8272. LWS_Send(message);
  8273. result = TRUE;
  8274. return result;
  8275. }
  8276. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8277. {
  8278. mtrace();
  8279. int result = FAIL;
  8280. char message[500]={0};
  8281. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8282. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8283. LWS_Send(message);
  8284. result = TRUE;
  8285. return result;
  8286. }
  8287. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8288. {
  8289. mtrace();
  8290. int result = FAIL;
  8291. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8292. char message[80]={0};
  8293. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8294. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8295. LWS_Send(message);
  8296. result = TRUE;
  8297. return result;
  8298. }
  8299. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8300. {
  8301. mtrace();
  8302. int result = FAIL;
  8303. char message[80]={0};
  8304. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8305. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8306. LWS_Send(message);
  8307. result = TRUE;
  8308. return result;
  8309. }
  8310. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8311. {
  8312. mtrace();
  8313. int result = FAIL;
  8314. char message[80]={0};
  8315. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8316. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8317. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8318. LWS_Send(message);
  8319. result = TRUE;
  8320. return result;
  8321. }
  8322. int sendUpdateFirmwareConfirmation(char *uuid)
  8323. {
  8324. mtrace();
  8325. int result = FAIL;
  8326. char message[60]={0};
  8327. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8328. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8329. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8330. LWS_Send(message);
  8331. result = TRUE;
  8332. return result;
  8333. }
  8334. int sendCertificateSignedConfirmation(char *uuid)
  8335. {
  8336. mtrace();
  8337. int result = PASS;
  8338. char message[4096]={0};
  8339. json_object *CertificateSigned = json_object_new_object();
  8340. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8341. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8342. sprintf(message,"[%d,\"%s\",%s]"
  8343. ,MESSAGE_TYPE_CALLRESULT
  8344. ,uuid
  8345. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8346. json_object_put(CertificateSigned);
  8347. LWS_Send(message);
  8348. return result;
  8349. }
  8350. int sendDeleteCertificateConfirmation(char *uuid)
  8351. {
  8352. mtrace();
  8353. int result = PASS;
  8354. char message[4096]={0};
  8355. json_object *DeleteCertificate = json_object_new_object();
  8356. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8357. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8358. sprintf(message,"[%d,\"%s\",%s]"
  8359. ,MESSAGE_TYPE_CALLRESULT
  8360. ,uuid
  8361. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8362. json_object_put(DeleteCertificate);
  8363. LWS_Send(message);
  8364. return result;
  8365. }
  8366. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8367. {
  8368. mtrace();
  8369. int result = PASS;
  8370. char message[4096]={0};
  8371. json_object *ExtendedTriggerMessage = json_object_new_object();
  8372. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8373. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8374. sprintf(message,"[%d,\"%s\",%s]"
  8375. ,MESSAGE_TYPE_CALLRESULT
  8376. ,uuid
  8377. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8378. json_object_put(ExtendedTriggerMessage);
  8379. LWS_Send(message);
  8380. return result;
  8381. }
  8382. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8383. {
  8384. mtrace();
  8385. int result = PASS;
  8386. char message[4096]={0};
  8387. json_object *GetInstalledCertificateIds = json_object_new_object();
  8388. json_object *certificateHashDataDatas = json_object_new_array();
  8389. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8390. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8391. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8392. {
  8393. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8394. {
  8395. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8396. {
  8397. json_object *certificateHashData = json_object_new_object();
  8398. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8399. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8400. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8401. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8402. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8403. }
  8404. }
  8405. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8406. }
  8407. else
  8408. {
  8409. json_object_put(certificateHashDataDatas);
  8410. }
  8411. sprintf(message,"[%d,\"%s\",%s]"
  8412. ,MESSAGE_TYPE_CALLRESULT
  8413. ,uuid
  8414. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8415. json_object_put(GetInstalledCertificateIds);
  8416. LWS_Send(message);
  8417. return result;
  8418. }
  8419. int sendGetLogConfirmation(char *uuid)
  8420. {
  8421. mtrace();
  8422. int result = PASS;
  8423. char message[4096]={0};
  8424. json_object *GetLog = json_object_new_object();
  8425. DEBUG_INFO("sendGetLogConfirmation...\n");
  8426. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8427. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8428. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8429. sprintf(message,"[%d,\"%s\",%s]"
  8430. ,MESSAGE_TYPE_CALLRESULT
  8431. ,uuid
  8432. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8433. json_object_put(GetLog);
  8434. LWS_Send(message);
  8435. return result;
  8436. }
  8437. int sendInstallCertificateConfirmation(char *uuid)
  8438. {
  8439. mtrace();
  8440. int result = PASS;
  8441. char message[4096]={0};
  8442. json_object *InstallCertificate = json_object_new_object();
  8443. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8444. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8445. sprintf(message,"[%d,\"%s\",%s]"
  8446. ,MESSAGE_TYPE_CALLRESULT
  8447. ,uuid
  8448. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8449. json_object_put(InstallCertificate);
  8450. LWS_Send(message);
  8451. return result;
  8452. }
  8453. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8454. {
  8455. mtrace();
  8456. int result = PASS;
  8457. char message[4096]={0};
  8458. json_object *SignedUpdateFirmware = json_object_new_object();
  8459. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8460. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8461. sprintf(message,"[%d,\"%s\",%s]"
  8462. ,MESSAGE_TYPE_CALLRESULT
  8463. ,uuid
  8464. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8465. json_object_put(SignedUpdateFirmware);
  8466. LWS_Send(message);
  8467. return result;
  8468. }
  8469. int sendUnknownConfirmation(char *uuid)
  8470. {
  8471. mtrace();
  8472. int result = PASS;
  8473. char message[256]={0};
  8474. DEBUG_INFO("sendUnknownConfirmation...\n");
  8475. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8476. LWS_Send(message);
  8477. return result;
  8478. }
  8479. //==========================================
  8480. // Handle server request routine Start
  8481. //==========================================
  8482. int handleCancelReservationRequest(char *uuid, char *payload)
  8483. {
  8484. mtrace();
  8485. int result = FAIL;
  8486. int gunNO = 0;
  8487. int reservationIdInt = -1;
  8488. char comfirmstr[20];
  8489. DEBUG_INFO("handleCancelReservationRequest...\n");
  8490. json_object *CancelReservation;
  8491. CancelReservation = json_tokener_parse(payload);
  8492. if(!is_error(CancelReservation))
  8493. {
  8494. // Required data
  8495. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8496. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8497. }
  8498. json_object_put(CancelReservation);
  8499. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8500. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8501. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8502. if(reservationIdInt != -1)
  8503. {
  8504. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8505. //check Transaction active
  8506. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8508. {
  8509. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8510. {
  8511. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8512. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8513. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8514. {
  8515. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8516. }
  8517. else
  8518. {
  8519. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8520. }
  8521. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8522. goto end;
  8523. }
  8524. }
  8525. for (int index = 0; index < CCS_QUANTITY; index++)
  8526. {
  8527. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8528. {
  8529. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8530. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8531. if(gunType[2] == GUN_TYPE_CCS)
  8532. {
  8533. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8534. }
  8535. else
  8536. {
  8537. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8538. }
  8539. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8540. goto end;
  8541. }
  8542. }
  8543. for (int index = 0; index < GB_QUANTITY; index++)
  8544. {
  8545. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8546. {
  8547. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8548. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8549. if(gunType[2] == GUN_TYPE_GBT)
  8550. {
  8551. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8552. }
  8553. else
  8554. {
  8555. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8556. }
  8557. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8558. goto end;
  8559. }
  8560. }
  8561. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8562. {
  8563. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8564. {
  8565. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8566. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8567. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8568. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8569. goto end;
  8570. }
  8571. }
  8572. for (int index = 0; index < AC_QUANTITY; index++)
  8573. {
  8574. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8575. {
  8576. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8577. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8578. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8579. {
  8580. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8581. }
  8582. else
  8583. {
  8584. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8585. }
  8586. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8587. goto end;
  8588. }
  8589. }
  8590. }
  8591. //The reservationId does NOT match the reservationId
  8592. sendCancelReservationConfirmation(uuid, comfirmstr);
  8593. end:
  8594. // Fill in ocpp packet uuid
  8595. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8596. return result;
  8597. }
  8598. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8599. {
  8600. mtrace();
  8601. int result = FAIL;
  8602. int gunIndex = -1;
  8603. char typeStr[16]={0};
  8604. char comfirmstr[20];
  8605. int specificId = FALSE;
  8606. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8607. json_object *ChangeAvailability;
  8608. ChangeAvailability = json_tokener_parse(payload);
  8609. if(!is_error(ChangeAvailability))
  8610. {
  8611. // Required data
  8612. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8613. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8614. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8615. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8616. }
  8617. json_object_put(ChangeAvailability);
  8618. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8619. {
  8620. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8621. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8622. }
  8623. else if(gunIndex == 0)
  8624. {
  8625. for(int i=0; i < gunTotalNumber; i++)
  8626. {
  8627. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8628. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8629. }
  8630. }
  8631. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8633. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8634. {
  8635. specificId = TRUE;
  8636. }
  8637. if(specificId == FALSE)
  8638. goto end;
  8639. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8640. {
  8641. //----------------------gunIndex is 0 ------------------------------------------------//
  8642. if(gunIndex == 0)
  8643. {
  8644. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8645. {
  8646. for(int i=0; i < gunTotalNumber; i++)
  8647. {
  8648. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8649. {
  8650. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8651. {
  8652. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8653. {
  8654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8655. goto end;
  8656. }
  8657. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8658. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8659. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8660. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8661. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8662. {
  8663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8664. goto end;
  8665. }
  8666. }
  8667. }//END FOR CHAdeMO_QUANTITY
  8668. for (int index = 0; index < CCS_QUANTITY; index++)
  8669. {
  8670. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8671. {
  8672. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8673. {
  8674. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8675. goto end;
  8676. }
  8677. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8678. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8679. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8680. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8681. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8682. {
  8683. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8684. goto end;
  8685. }
  8686. }
  8687. }//END FOR CCS_QUANTITY
  8688. for (int index = 0; index < GB_QUANTITY; index++)
  8689. {
  8690. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8691. {
  8692. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8693. {
  8694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8695. goto end;
  8696. }
  8697. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8698. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8699. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8700. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8701. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8702. {
  8703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8704. goto end;
  8705. }
  8706. }
  8707. }// END FOR GB_QUANTITY
  8708. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8709. {
  8710. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8711. {
  8712. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8713. {
  8714. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8715. goto end;
  8716. }
  8717. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8718. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8719. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8720. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8721. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8722. {
  8723. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8724. goto end;
  8725. }
  8726. }
  8727. }// END FOR GENERAL_GUN_QUANTITY
  8728. for (int index = 0; index < AC_QUANTITY; index++)
  8729. {
  8730. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8731. {
  8732. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8733. {
  8734. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8735. goto end;
  8736. }
  8737. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8738. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8739. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8740. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8741. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8742. {
  8743. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8744. goto end;
  8745. }
  8746. }
  8747. }//END FOR AC_QUANTITY
  8748. }// END FOR gunTotalNumber
  8749. }
  8750. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8751. {
  8752. for(int i=0; i < gunTotalNumber; i++)
  8753. {
  8754. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8755. {
  8756. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8757. goto end;
  8758. }
  8759. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8760. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8761. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8762. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8763. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8764. {
  8765. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8766. goto end;
  8767. }
  8768. }
  8769. }
  8770. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8771. goto end;
  8772. }
  8773. //----------------------gunIndex is not 0 ------------------------------------------------//
  8774. //check Transaction active
  8775. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8776. {
  8777. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8778. {
  8779. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8780. {
  8781. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8782. goto end;
  8783. }
  8784. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8785. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8786. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8787. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8788. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8789. {
  8790. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8791. goto end;
  8792. }
  8793. else
  8794. {
  8795. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8796. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8797. goto end;
  8798. }
  8799. }
  8800. }//END FOR CHAdeMO_QUANTITY
  8801. for (int index = 0; index < CCS_QUANTITY; index++)
  8802. {
  8803. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8804. {
  8805. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8806. {
  8807. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8808. goto end;
  8809. }
  8810. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8811. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8812. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8813. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8814. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8815. {
  8816. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8817. goto end;
  8818. }
  8819. else
  8820. {
  8821. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8822. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8823. goto end;
  8824. }
  8825. }
  8826. }//END FOR CCS_QUANTITY
  8827. for (int index = 0; index < GB_QUANTITY; index++)
  8828. {
  8829. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8830. {
  8831. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8832. {
  8833. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8834. goto end;
  8835. }
  8836. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8837. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8838. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8839. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8840. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8841. {
  8842. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8843. goto end;
  8844. }
  8845. else
  8846. {
  8847. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8848. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8849. goto end;
  8850. }
  8851. }
  8852. }// END FOR GB_QUANTITY
  8853. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8854. {
  8855. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8856. {
  8857. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8858. {
  8859. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8860. goto end;
  8861. }
  8862. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8863. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8864. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8865. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8866. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8867. {
  8868. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8869. goto end;
  8870. }
  8871. else
  8872. {
  8873. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8874. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8875. goto end;
  8876. }
  8877. }
  8878. }// END FOR GENERAL_GUN_QUANTITY
  8879. for (int index = 0; index < AC_QUANTITY; index++)
  8880. {
  8881. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8882. {
  8883. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8884. {
  8885. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8886. goto end;
  8887. }
  8888. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8889. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8890. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8891. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8892. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8893. {
  8894. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8895. goto end;
  8896. }
  8897. else
  8898. {
  8899. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8900. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8901. goto end;
  8902. }
  8903. }
  8904. }//END FOR AC_QUANTITY
  8905. }//END FOR AvailabilityTypeStr[Inoperative]
  8906. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8907. {
  8908. //----------------------gunIndex is 0 ------------------------------------------------//
  8909. if(gunIndex == 0)
  8910. {
  8911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8912. {
  8913. for(int i=0; i < gunTotalNumber; i++)
  8914. {
  8915. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8916. {
  8917. 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
  8918. {
  8919. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8920. goto end;
  8921. }
  8922. }//END FOR CHAdeMO_QUANTITY
  8923. for (int index = 0; index < CCS_QUANTITY; index++)
  8924. {
  8925. 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
  8926. {
  8927. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8928. goto end;
  8929. }
  8930. }//END FOR CCS_QUANTITY
  8931. for (int index = 0; index < GB_QUANTITY; index++)
  8932. {
  8933. 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
  8934. {
  8935. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8936. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8937. goto end;
  8938. }
  8939. }// END FOR GB_QUANTITY
  8940. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8941. {
  8942. 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
  8943. {
  8944. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8945. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8946. goto end;
  8947. }
  8948. }// END FOR GENERAL_GUN_QUANTITY
  8949. for (int index = 0; index < AC_QUANTITY; index++)
  8950. {
  8951. 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
  8952. {
  8953. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8954. goto end;
  8955. }
  8956. }//END FOR CHAdeMO_QUANTITY
  8957. }// END FOR gunTotalNumber
  8958. }
  8959. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8960. {
  8961. for(int i=0; i < gunTotalNumber; i++)
  8962. {
  8963. for (int index = 0; index < AC_QUANTITY; index++)
  8964. {
  8965. 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
  8966. {
  8967. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8968. goto end;
  8969. }
  8970. }//END FOR CHAdeMO_QUANTITY
  8971. } // END FOR gunTotalNumber
  8972. }
  8973. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8974. goto end;
  8975. }
  8976. //----------------------gunIndex is not 0 ------------------------------------------------//
  8977. //check Transaction active
  8978. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8979. {
  8980. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8981. {
  8982. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8983. goto end;
  8984. }
  8985. }//END FOR CHAdeMO_QUANTITY
  8986. for (int index = 0; index < CCS_QUANTITY; index++)
  8987. {
  8988. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8989. {
  8990. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8991. goto end;
  8992. }
  8993. }//END FOR CCS_QUANTITY
  8994. for (int index = 0; index < GB_QUANTITY; index++)
  8995. {
  8996. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8997. {
  8998. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8999. goto end;
  9000. }
  9001. }// END FOR GB_QUANTITY
  9002. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9003. {
  9004. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9005. {
  9006. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9007. goto end;
  9008. }
  9009. }// END FOR GENERAL_GUN_QUANTITY
  9010. for (int index = 0; index < AC_QUANTITY; index++)
  9011. {
  9012. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9013. {
  9014. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9015. goto end;
  9016. }
  9017. }//END FOR AC_QUANTITY
  9018. }//END FOR AvailabilityTypeStr[Operative]
  9019. end:
  9020. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9021. {
  9022. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9023. }
  9024. else
  9025. {
  9026. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9027. }
  9028. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9029. {
  9030. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9031. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9032. }
  9033. else if(gunIndex == 0)
  9034. {
  9035. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9036. {
  9037. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9038. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9039. }
  9040. }
  9041. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9042. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9043. return result;
  9044. }
  9045. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9046. {
  9047. mtrace();
  9048. int valueInvalid = NO;
  9049. int result = FAIL;
  9050. char keystr[40]={0};
  9051. char valuestr[501]={0}; //value should be limited in 500 bytes
  9052. char comfirmstr[20]={0};
  9053. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9054. json_object *ChangeConfiguration;
  9055. ChangeConfiguration = json_tokener_parse(payload);
  9056. if(!is_error(ChangeConfiguration))
  9057. {
  9058. // Required data
  9059. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9060. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9061. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9062. {
  9063. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9064. }
  9065. else
  9066. {
  9067. valueInvalid = YES;
  9068. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9069. }
  9070. }
  9071. json_object_put(ChangeConfiguration);
  9072. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9073. {
  9074. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9075. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9076. }
  9077. else
  9078. {
  9079. int status = setKeyValue(keystr, valuestr);
  9080. switch(status)
  9081. {
  9082. case ConfigurationStatus_Accepted:
  9083. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9084. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9085. StoreConfigurationTable();
  9086. break;
  9087. case RebootRequired:
  9088. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9089. StoreConfigurationTable();
  9090. break;
  9091. case NotSupported:
  9092. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9093. break;
  9094. case ConfigurationStatus_Rejected:
  9095. default:
  9096. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9097. break;
  9098. }
  9099. }
  9100. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9101. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9102. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9103. {
  9104. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9105. SetOcppConnStatus(FALSE);
  9106. }
  9107. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9108. {
  9109. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9110. }
  9111. return result;
  9112. }
  9113. int handleClearCacheRequest(char *uuid, char *payload)
  9114. {
  9115. mtrace();
  9116. int result = FAIL;
  9117. char comfirmstr[20];
  9118. char rmFileCmd[100]={0};
  9119. struct stat stats;
  9120. DEBUG_INFO("handleClearCacheRequest...\n");
  9121. stat("/Storage/OCPP", &stats);
  9122. // Check for directory existence
  9123. if (S_ISDIR(stats.st_mode) == 1)
  9124. {}
  9125. else
  9126. {
  9127. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9128. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9129. system(rmFileCmd);
  9130. }
  9131. if(OCPP_cleanLocalCache())
  9132. {
  9133. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9134. }
  9135. else
  9136. {
  9137. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9138. }
  9139. sendClearCacheConfirmation(uuid, comfirmstr);
  9140. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9141. return result;
  9142. }
  9143. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9144. {
  9145. mtrace();
  9146. int result = FAIL;
  9147. int resultRename;
  9148. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9149. char chargingProfilePurposeStr[26]={0};
  9150. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9151. char tempchargingProfilePurposeStr[26]={0};
  9152. char str[100]={0};
  9153. char fname[200]={0};
  9154. char comfirmstr[20]={0};
  9155. char word[1600]={0};
  9156. int clearflag = FALSE;
  9157. int chargingProfileIdIsNULL = FALSE;
  9158. int connectorIsNULL = FALSE;
  9159. int chargingProfilePurposeIsNULL = FALSE;
  9160. int stackLevelIsNULL = FALSE;
  9161. //int GotoEnd = FALSE;
  9162. FILE *fptr1, *fptr2;
  9163. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9164. int n_chargingProfile=0;
  9165. int isEmptyFile = FALSE;
  9166. char sLineWord[1600]={0};
  9167. char chargingProfiles[10][100]={0};
  9168. int ChargeProfileCount = 0;
  9169. int ch;
  9170. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9171. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9172. json_object *ClearChargingProfile;
  9173. ClearChargingProfile = json_tokener_parse(payload);
  9174. if(!is_error(ClearChargingProfile))
  9175. {
  9176. // Optional data
  9177. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9178. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9179. else
  9180. chargingProfileIdIsNULL = TRUE;
  9181. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9182. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9183. else
  9184. connectorIsNULL = TRUE;
  9185. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9186. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9187. else
  9188. chargingProfilePurposeIsNULL = TRUE;
  9189. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9190. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9191. else
  9192. stackLevelIsNULL = TRUE;
  9193. }
  9194. json_object_put(ClearChargingProfile);
  9195. if(connectorIsNULL == FALSE)
  9196. {
  9197. switch(connectorIdInt)
  9198. {
  9199. case 0:
  9200. if(chargingProfilePurposeIsNULL == TRUE)
  9201. {
  9202. int l = 0;
  9203. strcpy(fname, ChargePointMaxProfile_JSON);
  9204. if((access(fname,F_OK))!=-1)
  9205. {
  9206. strcpy(chargingProfiles[l], fname);
  9207. l = l + 1;
  9208. }
  9209. strcpy(fname, TxDefaultProfile_0_JSON);
  9210. if((access(fname,F_OK))!=-1)
  9211. {
  9212. strcpy(chargingProfiles[l], fname);
  9213. l = l + 1;
  9214. }
  9215. ChargeProfileCount = l;
  9216. }
  9217. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9218. {
  9219. strcpy(fname, ChargePointMaxProfile_JSON);
  9220. if((access(fname,F_OK))!=-1)
  9221. {
  9222. strcpy(chargingProfiles[0], fname);
  9223. ChargeProfileCount = 1;
  9224. }
  9225. }
  9226. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9227. {
  9228. strcpy(fname, TxDefaultProfile_0_JSON);
  9229. if((access(fname,F_OK))!=-1)
  9230. {
  9231. strcpy(chargingProfiles[0], fname);
  9232. ChargeProfileCount = 1;
  9233. }
  9234. }
  9235. break;
  9236. default:
  9237. if(chargingProfilePurposeIsNULL == TRUE)
  9238. {
  9239. int m = 0;
  9240. memset(fname, 0, ARRAY_SIZE(fname));
  9241. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9242. if((access(fname,F_OK))!=-1)
  9243. {
  9244. strcpy(chargingProfiles[m], fname);
  9245. m = m + 1;
  9246. }
  9247. memset(fname, 0, ARRAY_SIZE(fname));
  9248. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9249. if((access(fname,F_OK))!=-1)
  9250. {
  9251. strcpy(chargingProfiles[m], fname);
  9252. m = m + 1;
  9253. }
  9254. ChargeProfileCount = m;
  9255. }
  9256. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9257. {
  9258. //strcpy(fname, TxDefaultProfile_1_JSON);
  9259. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9260. if((access(fname,F_OK))!=-1)
  9261. {
  9262. strcpy(chargingProfiles[0], fname);
  9263. ChargeProfileCount = 1;
  9264. }
  9265. }
  9266. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9267. {
  9268. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9269. if((access(fname,F_OK))!=-1)
  9270. {
  9271. strcpy(chargingProfiles[0], fname);
  9272. ChargeProfileCount = 1;
  9273. }
  9274. //strcpy(fname, TxProfile_1_JSON);
  9275. }
  9276. //strcpy(fname, ChargePointMaxProfile_JSON );
  9277. break;
  9278. }
  9279. }
  9280. else // Check all Charging Profiles
  9281. {
  9282. int i = 0;
  9283. char fnametemp[200]={0};
  9284. ChargeProfileCount = 0;
  9285. //Check ChargePointMaxProfile.json exit
  9286. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9287. {
  9288. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9289. i = i + 1;
  9290. }
  9291. //Check TxDefaultProfile_0.json exit
  9292. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9293. {
  9294. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9295. i = i + 1;
  9296. }
  9297. //Check TxDefaultProfile_%d.json
  9298. for(int j=1; j <= gunTotalNumber; j++)
  9299. {
  9300. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9301. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9302. if((access(fnametemp,F_OK))!=-1)
  9303. {
  9304. strcpy(chargingProfiles[i], fnametemp);
  9305. i = i + 1;
  9306. }
  9307. }
  9308. //Check TxProfile_%d.json
  9309. for(int j=1; j <= gunTotalNumber; j++)
  9310. {
  9311. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9312. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9313. if((access(fnametemp,F_OK))!=-1)
  9314. {
  9315. strcpy(chargingProfiles[i], fnametemp);
  9316. i = i + 1;
  9317. }
  9318. }
  9319. ChargeProfileCount = i;
  9320. }// End connectorIsNULL is TRUE
  9321. if(ChargeProfileCount == 0)
  9322. {
  9323. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9324. goto end;
  9325. }
  9326. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9327. {
  9328. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9329. goto end;
  9330. }
  9331. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9332. {
  9333. memset(str, 0, ARRAY_SIZE(str));
  9334. // clear temp file
  9335. sprintf(str,"rm -f %s",temp);
  9336. system(str);
  9337. for(int k=0; k < ChargeProfileCount; k++)
  9338. {
  9339. memset(str, 0, ARRAY_SIZE(str));
  9340. //clear file in C
  9341. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9342. system(str);
  9343. }
  9344. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9345. goto end;
  9346. }
  9347. else if(connectorIsNULL == TRUE)
  9348. {
  9349. for(int k=0; k < ChargeProfileCount; k++)
  9350. {
  9351. fptr1 = fopen(chargingProfiles[k], "r");
  9352. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9353. //Check Charging Profile Count
  9354. while(fscanf(fptr1, "%s", word) != EOF)
  9355. {
  9356. //DEBUG_INFO("word=%s\n",word);
  9357. if(strstr(word, "chargingProfileId")!= NULL)
  9358. {
  9359. //DEBUG_INFO("test chargingProfileId \n");
  9360. n_chargingProfile = n_chargingProfile + 1;
  9361. //DEBUG_INFO("chargingProfileId Found\n");
  9362. }
  9363. }
  9364. rewind(fptr1);
  9365. //search Charging Profile Element
  9366. //int i= 0;
  9367. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9368. {
  9369. json_object *tmpProfilee;
  9370. tmpProfilee = json_tokener_parse(sLineWord);
  9371. if(!is_error(tmpProfilee))
  9372. {
  9373. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9374. {
  9375. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9376. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9377. }
  9378. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9379. {
  9380. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9381. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9382. }
  9383. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9384. {
  9385. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9386. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9387. }
  9388. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9389. {
  9390. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9391. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9392. }
  9393. }
  9394. json_object_put(tmpProfilee);
  9395. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9396. {
  9397. //------- not write to fptr2-------//
  9398. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9399. //clearflag = TRUE;
  9400. }
  9401. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9402. {
  9403. //------- not write to fptr2-------//
  9404. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9405. }
  9406. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9407. {
  9408. //------- not write to fptr2-------//
  9409. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9410. }
  9411. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9412. {
  9413. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9414. }
  9415. else
  9416. {
  9417. fprintf(fptr2, sLineWord);//writing data into file
  9418. }
  9419. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9420. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9421. if(clearflag == TRUE)
  9422. {
  9423. fclose(fptr1);
  9424. fclose(fptr2);
  9425. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9426. system(str);
  9427. // clear temp file
  9428. sprintf(str,"rm -f %s",temp);
  9429. system(str);
  9430. }
  9431. else
  9432. {
  9433. fclose(fptr1);
  9434. fclose(fptr2);
  9435. memset(str, 0, ARRAY_SIZE(str));
  9436. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9437. system(str);
  9438. resultRename = rename(temp, chargingProfiles[k]);
  9439. if(resultRename == 0)
  9440. {
  9441. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9442. }
  9443. else
  9444. {
  9445. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9446. }
  9447. if(comfirmstr[0]== 0)
  9448. {
  9449. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9450. }
  9451. //Check chargingProfile is empty file
  9452. /*------ Read the file ----------------*/
  9453. fptr1=fopen(chargingProfiles[k],"r");
  9454. ch=fgetc(fptr1);
  9455. rewind(fptr1);
  9456. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9457. if(ch!=EOF)
  9458. {
  9459. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9460. {
  9461. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9462. if(sLineWord[0]=='\0')
  9463. {
  9464. isEmptyFile = TRUE;
  9465. break;
  9466. }
  9467. else
  9468. {
  9469. isEmptyFile = FALSE;
  9470. break;
  9471. }
  9472. }
  9473. }
  9474. else
  9475. isEmptyFile = TRUE;
  9476. fclose(fptr1);
  9477. if(isEmptyFile == TRUE)
  9478. {
  9479. memset(str, 0, ARRAY_SIZE(str));
  9480. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9481. system(str);
  9482. }
  9483. }
  9484. }// End of while(int k=0; k < ChargePointCount; k++)
  9485. }
  9486. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9487. {
  9488. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9489. for(int k=0; k < ChargeProfileCount; k++)
  9490. {
  9491. fptr1 = fopen(chargingProfiles[k], "r");
  9492. fptr2 = fopen(temp, "w+");
  9493. //Check Charging Profile Count
  9494. while(fscanf(fptr1, "%s", word) != EOF)
  9495. {
  9496. //DEBUG_INFO("word=%s\n",word);
  9497. if(strstr(word, "chargingProfileId")!= NULL)
  9498. {
  9499. n_chargingProfile = n_chargingProfile + 1;
  9500. }
  9501. }
  9502. rewind(fptr1);
  9503. //search Charging Profile Element
  9504. //int i= 0;
  9505. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9506. {
  9507. json_object *tmpProfilee;
  9508. tmpProfilee = json_tokener_parse(sLineWord);
  9509. if(!is_error(tmpProfilee))
  9510. {
  9511. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9512. {
  9513. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9514. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9515. }
  9516. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9517. {
  9518. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9519. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9520. }
  9521. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9522. {
  9523. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9524. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9525. }
  9526. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9527. {
  9528. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9529. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9530. }
  9531. }
  9532. json_object_put(tmpProfilee);
  9533. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9534. {
  9535. //------- not write to fptr2-------//
  9536. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9537. //clearflag = TRUE;
  9538. }
  9539. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9540. {
  9541. //------- not write to fptr2-------//
  9542. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9543. }
  9544. else if(stackLevelIsNULL == TRUE)
  9545. {
  9546. //Clear Whole File
  9547. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9548. clearflag = TRUE;
  9549. break;
  9550. }
  9551. else
  9552. {
  9553. fprintf(fptr2, sLineWord);//writing data into file
  9554. }
  9555. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9556. }
  9557. if(clearflag == TRUE)
  9558. {
  9559. fclose(fptr1);
  9560. fclose(fptr2);
  9561. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9562. system(str);
  9563. // clear temp file
  9564. sprintf(str,"rm -f %s",temp);
  9565. system(str);
  9566. }
  9567. else
  9568. {
  9569. fclose(fptr1);
  9570. fclose(fptr2);
  9571. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9572. system(str);
  9573. resultRename = rename(temp, chargingProfiles[k]);
  9574. if(resultRename == 0)
  9575. {
  9576. DEBUG_INFO("File ChargingProfile renamed successfully");
  9577. }
  9578. else
  9579. {
  9580. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9581. }
  9582. if(comfirmstr[0]== 0)
  9583. {
  9584. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9585. }
  9586. //Check chargingProfile is empty file
  9587. /*------ Read the file ----------------*/
  9588. fptr1=fopen(chargingProfiles[k],"r");
  9589. ch=fgetc(fptr1);
  9590. rewind(fptr1);
  9591. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9592. if(ch!=EOF)
  9593. {
  9594. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9595. {
  9596. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9597. if(sLineWord[0]=='\0')
  9598. {
  9599. isEmptyFile = TRUE;
  9600. break;
  9601. }
  9602. else
  9603. {
  9604. isEmptyFile = FALSE;
  9605. break;
  9606. }
  9607. }
  9608. }
  9609. else
  9610. isEmptyFile = TRUE;
  9611. fclose(fptr1);
  9612. if(isEmptyFile == TRUE)
  9613. {
  9614. memset(str, 0, ARRAY_SIZE(str));
  9615. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9616. system(str);
  9617. }
  9618. /*------- End of reading ---------------*/
  9619. }
  9620. } // while(int k=0; k < ChargeProfileCount; k++)
  9621. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9622. end:
  9623. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9624. {
  9625. if(connectorIdInt == 0)
  9626. {
  9627. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9628. {
  9629. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9630. }
  9631. }
  9632. else
  9633. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9634. }
  9635. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9636. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9637. return result;
  9638. }
  9639. void createFirmwareVersionByDataTransfer(void)
  9640. {
  9641. json_object *FirmwareDataTransfer = json_object_new_object();
  9642. // AC & DC model
  9643. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9644. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9645. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9646. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9647. // DC model
  9648. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9649. {
  9650. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9651. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9652. (gunType[3] != GUN_TYPE_UNKNOWN))
  9653. {
  9654. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9655. }
  9656. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9657. {
  9658. // DS DM DW
  9659. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9660. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9661. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9662. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9663. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9664. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9665. }
  9666. else
  9667. {
  9668. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9669. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9670. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9671. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9672. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9673. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9674. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9675. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9676. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9677. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9678. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9679. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9680. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9681. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9682. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9683. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9684. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9685. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9686. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9687. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9688. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9689. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9690. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9691. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9692. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9693. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9694. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9695. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9696. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9697. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9698. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9699. }
  9700. }
  9701. // 4G model
  9702. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9703. {
  9704. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9705. }
  9706. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9707. json_object_put(FirmwareDataTransfer);
  9708. }
  9709. int handleDataTransferRequest(char *uuid, char *payload)
  9710. {
  9711. mtrace();
  9712. json_object *response = json_object_new_object();
  9713. int result = FAIL;
  9714. char tempvendorId[255]={0};
  9715. char tempmessageId[50]={0};
  9716. char tempdata[10240]={0};
  9717. char message[20480]={0};
  9718. DEBUG_INFO("handleDataTransferRequest...\n");
  9719. if((uuid != NULL) && (payload != NULL))
  9720. {
  9721. json_object *DataTransfer;
  9722. DataTransfer = json_tokener_parse(payload);
  9723. if(!is_error(DataTransfer))
  9724. {
  9725. // Required data
  9726. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9727. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9728. // Optional data
  9729. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9730. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9731. if(json_object_object_get(DataTransfer, "data") != NULL)
  9732. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9733. result = PASS;
  9734. }
  9735. json_object_put(DataTransfer);
  9736. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9737. {
  9738. // Send all moudle firmware version on EVSE
  9739. createFirmwareVersionByDataTransfer();
  9740. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9741. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9742. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9743. json_object_put(response);
  9744. }
  9745. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9746. {
  9747. system("/usr/bin/run_tmate_restart.sh &");
  9748. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9749. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9750. json_object_put(response);
  9751. }
  9752. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9753. {
  9754. json_object *data;
  9755. data = json_tokener_parse(tempdata);
  9756. if(!is_error(data))
  9757. {
  9758. 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))
  9759. {
  9760. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9761. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9762. if(json_object_object_get(data, "SOC") != NULL)
  9763. {
  9764. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9765. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9766. }
  9767. if(json_object_object_get(data, "Energy") != NULL)
  9768. {
  9769. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9770. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9771. }
  9772. if(json_object_object_get(data, "Duration") != NULL)
  9773. {
  9774. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9775. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9776. }
  9777. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9778. }
  9779. else
  9780. {
  9781. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9782. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9783. }
  9784. }
  9785. else
  9786. {
  9787. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9788. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9789. }
  9790. json_object_put(data);
  9791. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9792. json_object_put(response);
  9793. }
  9794. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9795. {
  9796. json_object *data;
  9797. data = json_tokener_parse(tempdata);
  9798. if(!is_error(data))
  9799. {
  9800. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9801. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9802. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9803. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9804. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9805. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9806. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9807. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9808. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9809. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9810. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9811. }
  9812. else
  9813. {
  9814. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9815. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9816. }
  9817. json_object_put(data);
  9818. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9819. json_object_put(response);
  9820. }
  9821. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9822. {
  9823. json_object *data;
  9824. data = json_tokener_parse(tempdata);
  9825. if(!is_error(data))
  9826. {
  9827. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9828. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9829. if(json_object_object_get(data, "idToken") != NULL)
  9830. {
  9831. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9832. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9833. }
  9834. else
  9835. {
  9836. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9837. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9838. }
  9839. if(json_object_object_get(data, "price") != NULL) //v1.0
  9840. {
  9841. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9842. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9843. }
  9844. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9845. {
  9846. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9847. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9848. }
  9849. else
  9850. {
  9851. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9852. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9853. }
  9854. }
  9855. else
  9856. {
  9857. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9858. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9859. }
  9860. json_object_put(data);
  9861. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9862. json_object_put(response);
  9863. }
  9864. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9865. {
  9866. json_object *data;
  9867. data = json_tokener_parse(tempdata);
  9868. if(!is_error(data))
  9869. {
  9870. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9871. if(json_object_object_get(data, "txId") != NULL)
  9872. {
  9873. // California pricing V1.0
  9874. DEBUG_INFO("California pricing V1.0\n");
  9875. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9876. sprintf((char*)dmsVersion, "1.0");
  9877. for(int idx = 0;idx<gunTotalNumber;idx++)
  9878. {
  9879. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9880. {
  9881. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9882. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9883. if(json_object_object_get(data, "description") != NULL)
  9884. {
  9885. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9886. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9887. }
  9888. else
  9889. {
  9890. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9891. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9892. }
  9893. }
  9894. }
  9895. }
  9896. else if(json_object_object_get(data, "transactionId") != NULL)
  9897. {
  9898. // California pricing V2.0
  9899. DEBUG_INFO("California pricing V2.0\n");
  9900. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9901. sprintf((char*)dmsVersion, "2.0");
  9902. for(int idx=0;idx<gunTotalNumber;idx++)
  9903. {
  9904. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9905. {
  9906. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9907. if(json_object_object_get(data, "timestamp") != NULL)
  9908. {
  9909. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9910. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9911. }
  9912. else
  9913. {
  9914. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9915. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9916. }
  9917. if(json_object_object_get(data, "meterValue") != NULL)
  9918. {
  9919. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9920. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9921. }
  9922. else
  9923. {
  9924. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9925. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9926. }
  9927. if(json_object_object_get(data, "cost") != NULL)
  9928. {
  9929. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9930. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9931. }
  9932. else
  9933. {
  9934. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9935. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9936. }
  9937. if(json_object_object_get(data, "state") != NULL)
  9938. {
  9939. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9940. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9941. }
  9942. else
  9943. {
  9944. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9945. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9946. }
  9947. if(json_object_object_get(data, "chargingPrice") != NULL)
  9948. {
  9949. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9950. {
  9951. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9952. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9953. }
  9954. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9955. {
  9956. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9957. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9958. }
  9959. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9960. {
  9961. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9962. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9963. }
  9964. }
  9965. else
  9966. {
  9967. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9968. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9969. }
  9970. if(json_object_object_get(data, "idlePrice") != NULL)
  9971. {
  9972. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9973. {
  9974. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9975. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9976. }
  9977. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9978. {
  9979. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9980. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9981. }
  9982. }
  9983. if(json_object_object_get(data, "nextPeriod") != NULL)
  9984. {
  9985. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9986. {
  9987. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9988. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9989. }
  9990. else
  9991. {
  9992. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9993. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9994. }
  9995. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9996. {
  9997. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9998. {
  9999. 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")));
  10000. 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"));
  10001. }
  10002. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  10003. {
  10004. 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")));
  10005. 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"));
  10006. }
  10007. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  10008. {
  10009. 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")));
  10010. 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"));
  10011. }
  10012. }
  10013. else
  10014. {
  10015. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10016. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10017. }
  10018. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10019. {
  10020. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10021. {
  10022. 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")));
  10023. 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"));
  10024. }
  10025. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10026. {
  10027. 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")));
  10028. 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"));
  10029. }
  10030. }
  10031. }
  10032. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10033. {
  10034. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10035. {
  10036. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10037. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10038. }
  10039. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10040. {
  10041. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10042. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10043. }
  10044. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10045. {
  10046. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10047. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10048. }
  10049. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10050. {
  10051. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10052. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10053. }
  10054. }
  10055. }
  10056. }
  10057. }
  10058. else
  10059. {
  10060. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10061. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10062. }
  10063. }
  10064. else
  10065. {
  10066. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10067. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10068. }
  10069. json_object_put(data);
  10070. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10071. json_object_put(response);
  10072. }
  10073. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10074. {
  10075. json_object *data;
  10076. data = json_tokener_parse(tempdata);
  10077. if(!is_error(data))
  10078. {
  10079. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10080. if(json_object_object_get(data, "txId") != NULL)
  10081. {
  10082. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10083. for(int idx = 0;idx<gunTotalNumber;idx++)
  10084. {
  10085. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10086. {
  10087. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10088. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10089. if(json_object_object_get(data, "description") != NULL)
  10090. {
  10091. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10092. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10093. }
  10094. else
  10095. {
  10096. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10097. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10098. }
  10099. }
  10100. }
  10101. }
  10102. else if(json_object_object_get(data, "transactionId") != NULL)
  10103. {
  10104. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10105. for(int idx = 0;idx<gunTotalNumber;idx++)
  10106. {
  10107. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10108. {
  10109. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10110. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10111. if(json_object_object_get(data, "cost") != NULL)
  10112. {
  10113. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10114. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10115. }
  10116. else
  10117. {
  10118. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10119. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10120. }
  10121. if(json_object_object_get(data, "priceText") != NULL)
  10122. {
  10123. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10124. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10125. }
  10126. else
  10127. {
  10128. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10129. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10130. }
  10131. if(json_object_object_get(data, "qrCodeText") != NULL)
  10132. {
  10133. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10134. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10135. }
  10136. }
  10137. }
  10138. }
  10139. else
  10140. {
  10141. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10142. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10143. }
  10144. }
  10145. else
  10146. {
  10147. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10148. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10149. }
  10150. json_object_put(data);
  10151. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10152. json_object_put(response);
  10153. }
  10154. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10155. {
  10156. json_object *data;
  10157. data = json_tokener_parse(tempdata);
  10158. if(!is_error(data))
  10159. {
  10160. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10161. if(json_object_object_get(data, "Content_Type") != NULL)
  10162. {
  10163. 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))
  10164. {
  10165. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10166. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10167. {
  10168. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10169. }
  10170. }
  10171. else
  10172. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10173. }
  10174. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10175. }
  10176. else
  10177. {
  10178. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10179. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10180. }
  10181. json_object_put(data);
  10182. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10183. json_object_put(response);
  10184. }
  10185. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10186. {
  10187. json_object *data;
  10188. data = json_tokener_parse(tempdata);
  10189. if(!is_error(data))
  10190. {
  10191. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10192. if(json_object_object_get(data, "ConnectorId") != NULL)
  10193. {
  10194. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10195. }
  10196. if(json_object_object_get(data, "SerialNo") != NULL)
  10197. {
  10198. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10199. }
  10200. if(json_object_object_get(data, "Page_Index") != NULL)
  10201. {
  10202. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10203. }
  10204. if(json_object_object_get(data, "Duration") != NULL)
  10205. {
  10206. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10207. }
  10208. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10209. }
  10210. else
  10211. {
  10212. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10213. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10214. }
  10215. json_object_put(data);
  10216. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10217. json_object_put(response);
  10218. }
  10219. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10220. {
  10221. json_object *data;
  10222. data = json_tokener_parse(tempdata);
  10223. if(!is_error(data))
  10224. {
  10225. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10226. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10227. {
  10228. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10229. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10230. else
  10231. {
  10232. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10233. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10234. }
  10235. }
  10236. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10237. {
  10238. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10239. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10240. else
  10241. {
  10242. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10243. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10244. }
  10245. }
  10246. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10247. {
  10248. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10249. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10250. else
  10251. {
  10252. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10253. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10254. }
  10255. }
  10256. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10257. {
  10258. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10259. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10260. else
  10261. {
  10262. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10263. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10264. }
  10265. }
  10266. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10267. {
  10268. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10269. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10270. else
  10271. {
  10272. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10273. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10274. }
  10275. }
  10276. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10277. {
  10278. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10279. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10280. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10281. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10282. else
  10283. {
  10284. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10285. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10286. }
  10287. }
  10288. if(json_object_object_get(data, "isAuthentication") != NULL)
  10289. {
  10290. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10291. {
  10292. case 0:
  10293. case 1:
  10294. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10295. break;
  10296. default:
  10297. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10298. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10299. break;
  10300. }
  10301. }
  10302. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10303. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10304. }
  10305. else
  10306. {
  10307. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10308. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10309. }
  10310. json_object_put(data);
  10311. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10312. json_object_put(response);
  10313. }
  10314. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10315. {
  10316. json_object *data;
  10317. data = json_tokener_parse(tempdata);
  10318. if(!is_error(data))
  10319. {
  10320. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10321. {
  10322. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10323. {
  10324. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10325. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10326. }
  10327. else
  10328. {
  10329. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10330. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10331. }
  10332. }
  10333. else
  10334. {
  10335. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10336. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10337. }
  10338. }
  10339. else
  10340. {
  10341. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10342. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10343. }
  10344. json_object_put(data);
  10345. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10346. json_object_put(response);
  10347. }
  10348. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10349. {
  10350. json_object *data;
  10351. data = json_tokener_parse(tempdata);
  10352. if(!is_error(data))
  10353. {
  10354. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10355. if(json_object_object_get(data, "stationName") != NULL)
  10356. {
  10357. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  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("station_name data can not get."));
  10363. }
  10364. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10365. {
  10366. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10367. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10368. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10369. }
  10370. }
  10371. else
  10372. {
  10373. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10374. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10375. }
  10376. json_object_put(data);
  10377. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10378. json_object_put(response);
  10379. }
  10380. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10381. {
  10382. json_object *data;
  10383. data = json_tokener_parse(tempdata);
  10384. if(!is_error(data))
  10385. {
  10386. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10387. if(json_object_object_get(data, "weatherId") != NULL)
  10388. {
  10389. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10390. }
  10391. else
  10392. {
  10393. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10394. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10395. }
  10396. if(json_object_object_get(data, "Temperature") != NULL)
  10397. {
  10398. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  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("temperature data can not get."));
  10404. }
  10405. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10406. {
  10407. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10408. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10409. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10410. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10411. );
  10412. }
  10413. }
  10414. else
  10415. {
  10416. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10417. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10418. }
  10419. json_object_put(data);
  10420. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10421. json_object_put(response);
  10422. }
  10423. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10424. {
  10425. json_object *data;
  10426. data = json_tokener_parse(tempdata);
  10427. if(!is_error(data))
  10428. {
  10429. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10430. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10431. {
  10432. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10433. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10434. }
  10435. else
  10436. {
  10437. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10438. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10439. }
  10440. }
  10441. else
  10442. {
  10443. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10444. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10445. }
  10446. json_object_put(data);
  10447. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10448. json_object_put(response);
  10449. }
  10450. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10451. {
  10452. json_object *data;
  10453. data = json_tokener_parse(tempdata);
  10454. if(!is_error(data))
  10455. {
  10456. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10457. {
  10458. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10459. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10460. if(gun_index < gunTotalNumber)
  10461. {
  10462. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10463. {
  10464. json_object *responsedata = json_object_new_object();
  10465. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10466. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10467. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10468. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10469. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10470. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10471. }
  10472. else
  10473. {
  10474. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10475. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10476. }
  10477. }
  10478. else
  10479. {
  10480. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10481. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10482. }
  10483. }
  10484. else
  10485. {
  10486. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10487. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10488. }
  10489. }
  10490. else
  10491. {
  10492. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10493. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10494. }
  10495. json_object_put(data);
  10496. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10497. json_object_put(response);
  10498. }
  10499. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10500. {
  10501. json_object *data;
  10502. data = json_tokener_parse(tempdata);
  10503. if(!is_error(data))
  10504. {
  10505. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10506. int gun_index = 0;
  10507. if(json_object_object_get(data, "ConnectorId") != NULL)
  10508. {
  10509. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10510. if(json_object_object_get(data, "occupancySN") != NULL)
  10511. {
  10512. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10513. }
  10514. else
  10515. {
  10516. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10517. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10518. }
  10519. if(json_object_object_get(data, "actionId") != NULL)
  10520. {
  10521. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10522. }
  10523. else
  10524. {
  10525. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10526. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10527. }
  10528. }
  10529. else
  10530. {
  10531. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10532. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  10533. }
  10534. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10535. {
  10536. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10537. }
  10538. }
  10539. else
  10540. {
  10541. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10542. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  10543. }
  10544. json_object_put(data);
  10545. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10546. json_object_put(response);
  10547. }
  10548. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10549. {
  10550. json_object *data;
  10551. data = json_tokener_parse(tempdata);
  10552. if(!is_error(data))
  10553. {
  10554. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10555. if(json_object_object_get(data, "price") != NULL)
  10556. {
  10557. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10558. }
  10559. else
  10560. {
  10561. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10562. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  10563. }
  10564. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10565. {
  10566. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10567. }
  10568. }
  10569. else
  10570. {
  10571. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10572. json_object_object_add(response, "data", json_object_new_string("SetOccupancyPrice content got something wrong."));
  10573. }
  10574. json_object_put(data);
  10575. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10576. json_object_put(response);
  10577. }
  10578. // Support ISO-15118 related message
  10579. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10580. {
  10581. char cmdBuf[1024]={0};
  10582. 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);
  10583. system(cmdBuf);
  10584. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10585. json_object *responsedata = json_object_new_object();
  10586. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10587. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10588. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10589. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10590. json_object_put(response);
  10591. }
  10592. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10593. {
  10594. json_object *data;
  10595. data = json_tokener_parse(tempdata);
  10596. if(!is_error(data))
  10597. {
  10598. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10599. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10600. fclose(fp);
  10601. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10602. json_object *responsedata = json_object_new_object();
  10603. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10604. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10605. else
  10606. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10607. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10608. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10609. }
  10610. else
  10611. {
  10612. json_object *responsedata = json_object_new_object();
  10613. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10614. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10615. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10616. }
  10617. json_object_put(data);
  10618. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10619. json_object_put(response);
  10620. }
  10621. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10622. {
  10623. json_object *data;
  10624. data = json_tokener_parse(tempdata);
  10625. DEBUG_INFO("DeleteCertificate processing...\n");
  10626. if(!is_error(data))
  10627. {
  10628. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10629. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10630. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10631. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10632. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10633. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10634. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10635. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10636. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10637. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10638. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10639. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10640. char temp[256] = {0};
  10641. char compareData[256] = {0};
  10642. int isMatch = TRUE;
  10643. // Check certV2G
  10644. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10645. {
  10646. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10647. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10648. isMatch = FALSE;
  10649. if(isMatch == TRUE)
  10650. {
  10651. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10652. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10653. isMatch = FALSE;
  10654. }
  10655. if(isMatch == TRUE)
  10656. {
  10657. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10658. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10659. isMatch = FALSE;
  10660. }
  10661. if(isMatch == TRUE)
  10662. {
  10663. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10664. system(temp);
  10665. json_object *responsedata = json_object_new_object();
  10666. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10667. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10668. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10669. }
  10670. else
  10671. {
  10672. json_object *responsedata = json_object_new_object();
  10673. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10674. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10675. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10676. }
  10677. }
  10678. else
  10679. {
  10680. json_object *responsedata = json_object_new_object();
  10681. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10682. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10683. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10684. }
  10685. }
  10686. else
  10687. {
  10688. json_object *responsedata = json_object_new_object();
  10689. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10690. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10691. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10692. }
  10693. json_object_put(data);
  10694. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10695. json_object_put(response);
  10696. }
  10697. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10698. {
  10699. json_object *data;
  10700. data = json_tokener_parse(tempdata);
  10701. if(!is_error(data))
  10702. {
  10703. /*
  10704. * TODO:
  10705. * 1. Query certificate to response
  10706. */
  10707. json_object *responsedata = json_object_new_object();
  10708. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10709. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10710. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10711. }
  10712. else
  10713. {
  10714. json_object *responsedata = json_object_new_object();
  10715. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10716. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10717. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10718. }
  10719. json_object_put(data);
  10720. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10721. json_object_put(response);
  10722. }
  10723. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10724. {
  10725. json_object *data;
  10726. data = json_tokener_parse(tempdata);
  10727. if(!is_error(data))
  10728. {
  10729. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10730. if(json_object_object_get(data, "certificateType") != NULL)
  10731. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10732. if(json_object_object_get(data, "certificate") != NULL)
  10733. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10734. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10735. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10736. char temp[1024];
  10737. FILE *fp = fopen(tempCert, "w");
  10738. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10739. fclose(fp);
  10740. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10741. char strExpDate[30];
  10742. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10743. fp = popen(temp, "r");
  10744. if(fp)
  10745. {
  10746. while(fgets(temp, sizeof(temp), fp) != NULL)
  10747. {
  10748. if(strstr(temp, "notAfter=") != NULL)
  10749. {
  10750. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10751. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10752. break;
  10753. }
  10754. }
  10755. }
  10756. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10757. struct tm tmExpDate;
  10758. struct timeb tbExpDate;
  10759. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10760. tbExpDate.time = mktime(&tmExpDate);
  10761. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10762. {
  10763. DEBUG_INFO("The enddate is already expired...\n");
  10764. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10765. }
  10766. else
  10767. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10768. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10769. {
  10770. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10771. {
  10772. if(access(ROOTCA_V2G,F_OK) != -1)
  10773. {
  10774. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10775. rename(ROOTCA_V2G, "/Storage/OCPP/rootCaV2g_fallback.pem");
  10776. rename(tempCert, ROOTCA_V2G);
  10777. }
  10778. else
  10779. {
  10780. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10781. rename(tempCert, ROOTCA_V2G);
  10782. }
  10783. json_object *responsedata = json_object_new_object();
  10784. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  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("Accepted"));
  10787. }
  10788. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10789. {
  10790. if(access(ROOTCA_MO,F_OK) != -1)
  10791. {
  10792. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10793. rename(ROOTCA_MO, "/Storage/OCPP/rootCaMo_fallback.pem");
  10794. rename(tempCert, ROOTCA_MO);
  10795. }
  10796. else
  10797. {
  10798. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10799. rename(tempCert, ROOTCA_MO);
  10800. }
  10801. json_object *responsedata = json_object_new_object();
  10802. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10803. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10804. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10805. }
  10806. else
  10807. {
  10808. json_object *responsedata = json_object_new_object();
  10809. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10810. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10811. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10812. }
  10813. }
  10814. else
  10815. {
  10816. json_object *responsedata = json_object_new_object();
  10817. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10818. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10819. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10820. }
  10821. }
  10822. else
  10823. {
  10824. json_object *responsedata = json_object_new_object();
  10825. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10826. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10827. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10828. }
  10829. json_object_put(data);
  10830. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10831. json_object_put(response);
  10832. }
  10833. else
  10834. {
  10835. // Can not find valid message id
  10836. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10837. }
  10838. }
  10839. else
  10840. {
  10841. // Payload is null
  10842. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10843. }
  10844. LWS_Send(message);
  10845. return result;
  10846. }
  10847. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10848. {
  10849. mtrace();
  10850. int result = FAIL;
  10851. int connectorIdInt, durationInt;
  10852. char chargingRateUnitStr[4]={0};
  10853. char comfirmstr[20];
  10854. int confirmPeriods = 0;
  10855. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10856. json_object *GetCompositeSchedule;
  10857. GetCompositeSchedule = json_tokener_parse(payload);
  10858. if(!is_error(GetCompositeSchedule))
  10859. {
  10860. // Required data
  10861. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10862. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10863. else
  10864. connectorIdInt = -1;
  10865. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10866. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10867. else
  10868. durationInt = 86400;
  10869. // Optional data
  10870. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10871. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10872. }
  10873. json_object_put(GetCompositeSchedule);
  10874. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10875. if((connectorIdInt == 0) ||
  10876. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10877. {
  10878. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10879. struct StructChargingProfile tmpProfile[1];
  10880. if(strstr(chargingRateUnitStr, "W") != NULL)
  10881. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10882. else
  10883. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10884. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10885. {
  10886. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10887. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10888. }
  10889. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10890. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10891. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10892. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10893. {
  10894. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10895. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10896. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10897. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10898. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10899. {
  10900. confirmPeriods = idx;
  10901. break;
  10902. }
  10903. }
  10904. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10905. {
  10906. confirmPeriods += 1;
  10907. }
  10908. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10909. }
  10910. else
  10911. {
  10912. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10913. }
  10914. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10915. return result;
  10916. }
  10917. int handleGetConfigurationRequest(char *uuid, char *payload)
  10918. {
  10919. mtrace();
  10920. int result = FAIL;
  10921. int MaxKeySupported = 0;
  10922. int n_keys = 0;
  10923. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10924. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10925. json_object *GetConfiguration;
  10926. GetConfiguration = json_tokener_parse(payload);
  10927. if(!is_error(GetConfiguration))
  10928. {
  10929. // Optional data
  10930. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10931. {
  10932. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10933. {
  10934. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10935. n_keys = idx + 1;
  10936. }
  10937. }
  10938. }
  10939. json_object_put(GetConfiguration);
  10940. UnknownKeynum = 0;
  10941. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10942. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10943. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10944. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10945. if(n_keys != 0)
  10946. {
  10947. for(int i=0;i<n_keys;i++)
  10948. {
  10949. getKeyValue(requestKey[i]);
  10950. }
  10951. }
  10952. else
  10953. {
  10954. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10955. getKeyValue("");
  10956. }
  10957. processUnkownKey();
  10958. sendGetConfigurationConfirmation(uuid);
  10959. return result;
  10960. }
  10961. static char fnamePlusPath[100]={0};
  10962. static char fnamePWithNoPath[60]={0};
  10963. void checkUploadLog(void)
  10964. {
  10965. FILE *fp;
  10966. /* Open the command for reading. */
  10967. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10968. if (fp == NULL) {
  10969. DEBUG_WARN("Failed to run command\n" );
  10970. exit(1);
  10971. }
  10972. int ftppathlen = 0;
  10973. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10974. int i = 0;
  10975. /* Read the output a line at a time - output it. */
  10976. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10977. if(i==0)
  10978. {
  10979. ftppathlen = strlen(fnamePlusPath);
  10980. DEBUG_INFO("%s\n", fnamePlusPath);
  10981. fnamePlusPath[ftppathlen]='\0';
  10982. break;
  10983. }
  10984. i= i+1;
  10985. }
  10986. /* close */
  10987. pclose(fp);
  10988. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10989. {
  10990. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10991. {
  10992. fnamePlusPath[k]='\0';
  10993. }
  10994. }
  10995. i=1;
  10996. //char fname[60]={0};
  10997. while(i < ftppathlen)
  10998. {
  10999. int len=ftppathlen-i;
  11000. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  11001. {
  11002. DEBUG_INFO("compare '/' all right\n");
  11003. break;
  11004. }
  11005. i=i+1;
  11006. }
  11007. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11008. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11009. fnamePWithNoPath[i+1] = '\0';
  11010. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11011. {
  11012. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11013. {
  11014. fnamePWithNoPath[j]='\0';
  11015. }
  11016. }
  11017. FILE* fp1 = fopen(fnamePlusPath, "r");
  11018. if (fp1)
  11019. {
  11020. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11021. // file exists
  11022. fclose(fp1);
  11023. }
  11024. else
  11025. {
  11026. // file doesn't exist
  11027. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11028. }
  11029. }
  11030. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11031. {
  11032. mtrace();
  11033. int result = FAIL;
  11034. time_t CurrentTime;
  11035. struct tm *tm;
  11036. pthread_t th_Status;
  11037. CurrentTime = time(NULL);
  11038. tm = localtime(&CurrentTime);
  11039. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11040. 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);
  11041. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11042. if(!interLock.isGetDiagnosticGoing)
  11043. {
  11044. interLock.isGetDiagnosticGoing = 1;
  11045. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11046. sleep(1);
  11047. }
  11048. else
  11049. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11050. return result;
  11051. }
  11052. void* GetDiagnosticsProcess(void* data)
  11053. {
  11054. pthread_detach(pthread_self());
  11055. mtrace();
  11056. int retriesInt=0, retryIntervalInt=0;
  11057. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11058. 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};
  11059. int port=0;
  11060. int isSuccess = FALSE;
  11061. char cmdBuf[2048];
  11062. struct tm *tmNow;
  11063. time_t CurrentTime;
  11064. struct tm tmStart;
  11065. struct tm tmStop;
  11066. CurrentTime = time(NULL);
  11067. tmNow=localtime(&CurrentTime);
  11068. uint16_t targetYear, targetMonth;
  11069. json_object *GetDiagnostics;
  11070. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11071. GetDiagnostics = json_tokener_parse(data);
  11072. if(!is_error(GetDiagnostics))
  11073. {
  11074. // Required data
  11075. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11076. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11077. // Optional data
  11078. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11079. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11080. else
  11081. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11082. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11083. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11084. else
  11085. retryIntervalInt = 30;
  11086. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11087. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11088. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11089. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11090. }
  11091. json_object_put(GetDiagnostics);
  11092. // Pack log to compress file
  11093. 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) &&
  11094. (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))
  11095. {
  11096. // Pack system log
  11097. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11098. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11099. targetYear = tmStart.tm_year;
  11100. targetMonth = tmStart.tm_mon;
  11101. do
  11102. {
  11103. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11104. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11105. if(targetMonth+1>=13)
  11106. {
  11107. targetYear += 1;
  11108. targetMonth = 1;
  11109. }
  11110. else
  11111. {
  11112. targetMonth += 1;
  11113. }
  11114. }while((targetYear < (tmNow->tm_year+1900)) ||
  11115. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11116. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11117. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11118. system(cmdBuf);
  11119. // Pack charging & event log
  11120. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11121. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11122. targetYear = tmStart.tm_year;
  11123. targetMonth = tmStart.tm_mon;
  11124. do
  11125. {
  11126. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11127. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  11128. if(targetMonth+1>=13)
  11129. {
  11130. targetYear += 1;
  11131. targetMonth = 1;
  11132. }
  11133. else
  11134. {
  11135. targetMonth += 1;
  11136. }
  11137. }while((targetYear < (tmNow->tm_year+1900)) ||
  11138. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11139. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11140. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11141. system(cmdBuf);
  11142. // Combine log file
  11143. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11144. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11145. }
  11146. else
  11147. {
  11148. system("exec /root/logPackTools 'log' 6");
  11149. }
  11150. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11151. system(cmdBuf);
  11152. checkUploadLog();
  11153. //****************location*******************/
  11154. if(strcmp(locationstr,"")==0)
  11155. {
  11156. DEBUG_INFO("location is <Empty>!\n");
  11157. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11158. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11159. goto end;
  11160. }
  11161. memset(protocol, 0, ARRAY_SIZE(protocol));
  11162. memset(user, 0, ARRAY_SIZE(user) );
  11163. memset(password, 0, ARRAY_SIZE(password));
  11164. memset(host, 0, ARRAY_SIZE(host));
  11165. memset(path, 0, ARRAY_SIZE(path));
  11166. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11167. memset(host1, 0, ARRAY_SIZE(host1));
  11168. memset(path1, 0, ARRAY_SIZE(path1));
  11169. /*location: ftp://user:password@host:port/path*/
  11170. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11171. if((access(fnamePlusPath,F_OK))!=-1)
  11172. {
  11173. DEBUG_INFO("fnamePlusPath exist.\n");
  11174. }
  11175. else
  11176. {
  11177. DEBUG_INFO("fnamePlusPath not exist!\n");
  11178. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11179. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11180. goto end;
  11181. }
  11182. if(strchr(locationstr,'@')==NULL)
  11183. {
  11184. sscanf(locationstr,
  11185. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11186. protocol, host, &port, path);
  11187. strcpy(user,"anonymous");
  11188. strcpy(password,"");
  11189. }
  11190. else
  11191. {
  11192. //DEBUG_INFO("pch=%s\n", pch);
  11193. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11194. protocol, user, password, host, &port, path);
  11195. }
  11196. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11197. {
  11198. DEBUG_INFO("protocol is not ftp/http ! \n");
  11199. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11200. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11201. goto end;
  11202. }
  11203. if(strncmp(locationstr,"http", 4) == 0)
  11204. {
  11205. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11206. sprintf(ftppath,"/%s", path);
  11207. do
  11208. {
  11209. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11210. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11211. sleep(3);
  11212. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11213. if(!isSuccess)
  11214. {
  11215. DEBUG_INFO("Diagnostics fail.\n");
  11216. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11217. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11218. sleep(retryIntervalInt);
  11219. }
  11220. else
  11221. {
  11222. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11223. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11224. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11225. }
  11226. retriesInt--;
  11227. }while((isSuccess == 0)&&(retriesInt >= 0));
  11228. }
  11229. else
  11230. {
  11231. sscanf(host,"%[^/]%s",host1, path1);
  11232. if(strlen(path) > 0)
  11233. sprintf(ftppath,"/%s", path);
  11234. else
  11235. sprintf(ftppath,"/%s", path1);
  11236. int ftppathlen=strlen(ftppath);
  11237. int i=1;
  11238. char filenametemp[50];
  11239. while(i < ftppathlen)
  11240. {
  11241. int len=ftppathlen-i;
  11242. if(ftppath[len]== 47) // '/' ascll code: 47
  11243. {
  11244. DEBUG_INFO("find '/' all right\n");
  11245. break;
  11246. }
  11247. i=i+1;
  11248. }
  11249. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11250. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11251. filenametemp[i+1] = 0;
  11252. if(port == 0)
  11253. port = 21;
  11254. do
  11255. {
  11256. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11257. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11258. sleep(3);
  11259. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11260. if(!isSuccess)
  11261. {
  11262. DEBUG_INFO("Diagnostics fail.\n");
  11263. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11264. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11265. sleep(retryIntervalInt);
  11266. }
  11267. else
  11268. {
  11269. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11270. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11271. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11272. }
  11273. retriesInt--;
  11274. }while((!isSuccess)&&(retriesInt >= 0));
  11275. }
  11276. end:
  11277. system("rm -f /mnt/*");
  11278. sleep(5);
  11279. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11280. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11281. interLock.isGetDiagnosticGoing = 0;
  11282. pthread_exit(NULL);
  11283. }
  11284. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11285. {
  11286. mtrace();
  11287. int result = FAIL;
  11288. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11289. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11290. {
  11291. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11292. locallistVersion = -1;
  11293. }
  11294. else
  11295. {
  11296. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11297. locallistVersion = 0;
  11298. OCPP_getListVerion();
  11299. }
  11300. //from db.OCPP_getListVerion
  11301. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11302. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11303. sendGetLocalListVersionConfirmation(uuid,"");
  11304. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11305. return result;
  11306. }
  11307. int handleRemoteStartRequest(char *uuid, char *payload)
  11308. {
  11309. mtrace();
  11310. int result = PASS;
  11311. int connectorIdInt=-1;
  11312. int tempIndex = 0;
  11313. char comfirmstr[20]={0};
  11314. char cmdBuf[512];
  11315. json_object *RemoteStartTransaction;
  11316. FILE *fp;
  11317. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11318. if(server_pending == TRUE)
  11319. {
  11320. result = FAIL;
  11321. }
  11322. RemoteStartTransaction = json_tokener_parse(payload);
  11323. if(!is_error(RemoteStartTransaction))
  11324. {
  11325. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11326. {
  11327. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11328. }
  11329. else
  11330. {
  11331. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11332. {
  11333. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11334. {
  11335. connectorIdInt = (gun_index+1);
  11336. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11337. break;
  11338. }
  11339. }
  11340. }
  11341. if(connectorIdInt == 0)
  11342. {
  11343. DEBUG_WARN("Connector id shall not equal 0.\n");
  11344. result = FAIL;
  11345. }
  11346. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11347. {
  11348. DEBUG_WARN("idTag should not be NULL.\n");
  11349. result = FAIL;
  11350. }
  11351. else if(connectorIdInt == -1)
  11352. {
  11353. DEBUG_INFO("Connector id does not specific.\n");
  11354. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11355. {
  11356. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11357. // Required data
  11358. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11359. // Optional data
  11360. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11361. {
  11362. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11363. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11364. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11365. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11366. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11367. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11368. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11369. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11370. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11371. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11372. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11373. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11374. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11375. {
  11376. 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")));
  11377. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11378. 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"));
  11379. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11380. 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"));
  11381. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11382. 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")));
  11383. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11384. {
  11385. 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++)
  11386. {
  11387. 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"));
  11388. 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"));
  11389. 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)
  11390. 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"));
  11391. }
  11392. }
  11393. }
  11394. }
  11395. else
  11396. {
  11397. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11398. }
  11399. }
  11400. }
  11401. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11402. {
  11403. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11404. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11405. // Required data
  11406. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11407. // Optional data
  11408. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11409. {
  11410. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11411. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11412. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11413. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11414. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11415. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11416. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11417. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11418. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11419. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11420. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11421. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11422. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11423. {
  11424. 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")));
  11425. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11426. 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"));
  11427. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11428. 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"));
  11429. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11430. 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")));
  11431. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11432. {
  11433. 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++)
  11434. {
  11435. 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"));
  11436. 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"));
  11437. 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)
  11438. 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"));
  11439. }
  11440. }
  11441. }
  11442. }
  11443. else
  11444. {
  11445. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11446. }
  11447. }
  11448. else
  11449. {
  11450. DEBUG_WARN("Connector id is over maximun value.\n");
  11451. result = FAIL;
  11452. }
  11453. }
  11454. if(result == PASS)
  11455. {
  11456. if(connectorIdInt > 0)
  11457. {
  11458. //check Transaction active
  11459. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11460. {
  11461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11462. {
  11463. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11464. }
  11465. else
  11466. {
  11467. tempIndex = connectorIdInt -1;
  11468. }
  11469. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11470. {
  11471. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11472. {
  11473. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11474. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11475. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11476. {
  11477. //Reserved
  11478. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11479. }
  11480. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11481. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11482. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11483. {
  11484. //Reserved
  11485. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11486. {
  11487. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11488. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11489. goto end;
  11490. }
  11491. }
  11492. else
  11493. {
  11494. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11495. {
  11496. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11498. goto end;
  11499. }
  11500. }//END FOR ELSE
  11501. }
  11502. }// END FOR CHAdeMO_QUANTITY
  11503. }
  11504. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11505. {
  11506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11507. {
  11508. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11509. }
  11510. else
  11511. {
  11512. tempIndex = connectorIdInt -1;
  11513. }
  11514. for (int index = 0; index < CCS_QUANTITY; index++)
  11515. {
  11516. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11517. {
  11518. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11519. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11520. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11521. {
  11522. //Reserved
  11523. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11524. }
  11525. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11526. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11527. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11528. {
  11529. //Reserved
  11530. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11531. {
  11532. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11533. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11534. goto end;
  11535. }
  11536. }
  11537. else
  11538. {
  11539. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11540. {
  11541. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11542. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11543. goto end;
  11544. }
  11545. }// END FOR ELSE
  11546. }
  11547. }// END FOR CCS_QUANTITY
  11548. }
  11549. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11550. {
  11551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11552. {
  11553. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11554. }
  11555. else
  11556. {
  11557. tempIndex = connectorIdInt -1;
  11558. }
  11559. for (int index = 0; index < GB_QUANTITY; index++)
  11560. {
  11561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11562. {
  11563. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11564. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11565. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11566. {
  11567. //Reserved
  11568. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11569. }
  11570. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11571. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11572. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11573. {
  11574. //Reserved
  11575. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11576. {
  11577. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11578. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11579. goto end;
  11580. }
  11581. }
  11582. else
  11583. {
  11584. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11585. {
  11586. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11587. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11588. goto end;
  11589. }
  11590. }// END FOR ELSE
  11591. }
  11592. } // END FOR GB_QUANTITY
  11593. }
  11594. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11595. {
  11596. tempIndex = connectorIdInt -1;
  11597. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11598. {
  11599. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11600. {
  11601. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11602. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11603. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11604. {
  11605. //Reserved
  11606. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11607. }
  11608. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11609. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11610. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11611. {
  11612. //Reserved
  11613. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11614. {
  11615. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11616. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11617. goto end;
  11618. }
  11619. }
  11620. else
  11621. {
  11622. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11623. {
  11624. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11625. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11626. goto end;
  11627. }
  11628. }// END FOR ELSE
  11629. }
  11630. } // END FOR GB_QUANTITY
  11631. }
  11632. else
  11633. {
  11634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11635. {
  11636. tempIndex = 2;
  11637. }
  11638. else
  11639. {
  11640. tempIndex = connectorIdInt -1;
  11641. }
  11642. for (int index = 0; index < AC_QUANTITY; index++)
  11643. {
  11644. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11645. {
  11646. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11647. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11648. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11649. {
  11650. //Reserved
  11651. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11652. }
  11653. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11654. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11655. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11656. {
  11657. //Reserved
  11658. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11659. {
  11660. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11661. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11662. goto end;
  11663. }
  11664. }
  11665. else
  11666. {
  11667. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11668. {
  11669. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11670. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11671. goto end;
  11672. }
  11673. }//END FOR ELSE
  11674. }
  11675. }// END FOR AC_QUANTITY
  11676. }
  11677. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11678. {
  11679. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11680. {
  11681. // Save profile to file
  11682. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11683. system(cmdBuf);
  11684. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11685. fp = fopen(cmdBuf, "w");
  11686. 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));
  11687. fclose(fp);
  11688. }
  11689. else
  11690. {
  11691. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11692. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11693. goto end;
  11694. }
  11695. }
  11696. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11697. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11698. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11699. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11700. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11701. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11702. }
  11703. else
  11704. {
  11705. uint8_t isHasIdleConnector = FALSE;
  11706. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11707. {
  11708. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11709. {
  11710. isHasIdleConnector = TRUE;
  11711. break;
  11712. }
  11713. }
  11714. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11715. {
  11716. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11717. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11718. {
  11719. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11720. {
  11721. // Save profile to file
  11722. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11723. system(cmdBuf);
  11724. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11725. fp = fopen(cmdBuf, "w");
  11726. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11727. fclose(fp);
  11728. refreshStartTimer(&clientTime.RemoteStartWait);
  11729. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11730. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11731. }
  11732. else
  11733. {
  11734. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11735. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11736. }
  11737. }
  11738. else
  11739. {
  11740. refreshStartTimer(&clientTime.RemoteStartWait);
  11741. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11742. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11743. }
  11744. }
  11745. else
  11746. {
  11747. DEBUG_INFO("There is not any connector is idle.\n");
  11748. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11749. }
  11750. }
  11751. }
  11752. else
  11753. {
  11754. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11755. }
  11756. end:
  11757. json_object_put(RemoteStartTransaction);
  11758. sendRemoteStartConfirmation(uuid, comfirmstr);
  11759. return result;
  11760. }
  11761. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11762. {
  11763. mtrace();
  11764. int result = FAIL;
  11765. int match = FALSE;
  11766. int GunNO = 0;
  11767. int tempIndex = 0;
  11768. int transactionIdInt=0;
  11769. int transactionIdIsNULL= TRUE;
  11770. char comfirmstr[20];
  11771. json_object *RemoteStopTransaction;
  11772. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11773. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11774. if(server_pending == TRUE)
  11775. {
  11776. return 0;
  11777. }
  11778. RemoteStopTransaction = json_tokener_parse(payload);
  11779. if(!is_error(RemoteStopTransaction))
  11780. {
  11781. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11782. {
  11783. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11784. transactionIdIsNULL = FALSE;
  11785. }
  11786. }
  11787. json_object_put(RemoteStopTransaction);
  11788. if(transactionIdIsNULL == FALSE)
  11789. {
  11790. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11791. {
  11792. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11793. {
  11794. //check Transaction active
  11795. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11796. {
  11797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11798. {
  11799. tempIndex = ((gun_index==2) ? 1: 0);
  11800. }
  11801. else
  11802. {
  11803. tempIndex = gun_index;
  11804. }
  11805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11806. {
  11807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11808. {
  11809. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11810. {
  11811. match = TRUE;
  11812. GunNO = gun_index;
  11813. }
  11814. }
  11815. }// END FOR CHAdeMO_QUANTITY
  11816. }
  11817. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11818. {
  11819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11820. {
  11821. tempIndex = ((gun_index==2) ? 1: 0);
  11822. }
  11823. else
  11824. {
  11825. tempIndex = gun_index;
  11826. }
  11827. for (int index = 0; index < CCS_QUANTITY; index++)
  11828. {
  11829. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11830. {
  11831. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11832. {
  11833. match = TRUE;
  11834. GunNO = gun_index;
  11835. }
  11836. }
  11837. }// END FOR CCS_QUANTITY
  11838. }
  11839. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11840. {
  11841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11842. {
  11843. tempIndex = ((gun_index==2) ? 1: 0);
  11844. }
  11845. else
  11846. {
  11847. tempIndex = gun_index;
  11848. }
  11849. for (int index = 0; index < GB_QUANTITY; index++)
  11850. {
  11851. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11852. {
  11853. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11854. {
  11855. match = TRUE;
  11856. GunNO = gun_index;
  11857. }
  11858. }
  11859. }// END FOR GB_QUANTITY
  11860. }
  11861. else if(gunType[gun_index] == GUN_TYPE_DO)
  11862. {
  11863. tempIndex = gun_index;
  11864. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11865. {
  11866. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11867. {
  11868. 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
  11869. {
  11870. match = TRUE;
  11871. GunNO = gun_index;
  11872. }
  11873. }
  11874. }// END FOR GB_QUANTITY
  11875. }
  11876. else
  11877. {
  11878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11879. {
  11880. tempIndex = 2;
  11881. }
  11882. else
  11883. {
  11884. tempIndex = gun_index;
  11885. }
  11886. for (int index = 0; index < AC_QUANTITY; index++)
  11887. {
  11888. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11889. {
  11890. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11891. {
  11892. match = TRUE;
  11893. GunNO = gun_index;
  11894. }
  11895. }
  11896. }// END FOR CHAdeMO_QUANTITY
  11897. } // END FOR AC ELSE
  11898. }// CHECK IF ResponseTransactionId == transactionIdInt
  11899. }//END FOR
  11900. if( match == TRUE)
  11901. {
  11902. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11903. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11904. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11905. }
  11906. else
  11907. {
  11908. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11909. }
  11910. }
  11911. else
  11912. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11913. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11914. return result;
  11915. }
  11916. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11917. {
  11918. mtrace();
  11919. int result = FAIL;
  11920. int connectorIdInt=0, reservationIdInt=0;
  11921. int tempIndex = 0;
  11922. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11923. char comfirmstr[20]={0};
  11924. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11925. int c = 0;
  11926. char *loc;
  11927. //char *ptr;
  11928. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11929. strcpy(sstrtemp, stringtrimspace(payload));
  11930. //***(1)connectorId ****/
  11931. c=0;
  11932. loc = strstr(sstrtemp, "connectorId");
  11933. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11934. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11935. {
  11936. sstr[c] = loc[strlen("connectorId")+2+c];
  11937. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11938. c++;
  11939. }
  11940. sstr[c] = '\0';
  11941. connectorIdInt = atoi(sstr);
  11942. //***(2)expiryDate ****/
  11943. loc = strstr(sstrtemp, "expiryDate");
  11944. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11945. c = 0;
  11946. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11947. {
  11948. sstr[c] = loc[3+strlen("expiryDate")+c];
  11949. c++;
  11950. }
  11951. sstr[c] = '\0';
  11952. strcpy(expiryDatestr, sstr);
  11953. //***(3)idTag ****/
  11954. loc = strstr(sstrtemp, "idTag");
  11955. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11956. c = 0;
  11957. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11958. {
  11959. sstr[c] = loc[3+strlen("idTag")+c];
  11960. c++;
  11961. }
  11962. sstr[c] = '\0';
  11963. strcpy(idTagstr, sstr);
  11964. //***(4)parentIdTag ****/
  11965. loc = strstr(sstrtemp, "parentIdTag");
  11966. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11967. c = 0;
  11968. if(loc == NULL)
  11969. {
  11970. strcpy(parentIdTagstr, "");
  11971. }
  11972. else
  11973. {
  11974. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11975. {
  11976. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11977. c++;
  11978. }
  11979. sstr[c] = '\0';
  11980. strcpy(parentIdTagstr, sstr);
  11981. }
  11982. //***(5)reservationId ****/
  11983. c=0;
  11984. loc = strstr(sstrtemp, "reservationId");
  11985. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11986. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11987. {
  11988. sstr[c] = loc[strlen("reservationId")+2+c];
  11989. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11990. c++;
  11991. }
  11992. sstr[c] = '\0';
  11993. reservationIdInt = atoi(sstr);
  11994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11995. /*
  11996. enum SYSTEM_STATUS
  11997. {
  11998. SYS_MODE_BOOTING = 0,
  11999. SYS_MODE_IDLE = 1,
  12000. SYS_MODE_AUTHORIZING = 2,
  12001. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12002. SYS_MODE_REASSIGN = 4,
  12003. SYS_MODE_PREPARING = 5,
  12004. SYS_MODE_PREPARE_FOR_EV = 6,
  12005. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12006. SYS_MODE_CHARGING = 8,
  12007. SYS_MODE_TERMINATING = 9,
  12008. SYS_MODE_COMPLETE = 10,
  12009. SYS_MODE_ALARM = 11,
  12010. SYS_MODE_FAULT = 12,
  12011. SYS_MODE_RESERVATION = 13,
  12012. SYS_MODE_BOOKING = 14,
  12013. SYS_MODE_MAINTAIN = 15,
  12014. SYS_MODE_DEBUG = 16,
  12015. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12016. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12017. SYS_MODE_UPDATE = 19
  12018. };
  12019. */
  12020. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12021. {
  12022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12023. goto end;
  12024. }
  12025. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12026. {
  12027. //check Transaction active
  12028. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12029. {
  12030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12031. {
  12032. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12033. }
  12034. else
  12035. {
  12036. tempIndex = connectorIdInt -1;
  12037. }
  12038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12039. {
  12040. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12041. {
  12042. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12043. {
  12044. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12045. {
  12046. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12047. {
  12048. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12049. {
  12050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12051. }
  12052. else
  12053. {
  12054. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12056. }
  12057. }
  12058. else if((ShmSysConfigAndInfo->SysInfo.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'))
  12059. {
  12060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12061. }
  12062. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12063. {
  12064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12065. }
  12066. else
  12067. {
  12068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12069. }
  12070. }
  12071. else if((ShmSysConfigAndInfo->SysInfo.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
  12072. {
  12073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12074. }
  12075. }
  12076. else
  12077. {
  12078. //replace reservation
  12079. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12081. }
  12082. }
  12083. } // END FOR CHAdeMO_QUANTITY
  12084. }
  12085. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12086. {
  12087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12088. {
  12089. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12090. }
  12091. else
  12092. {
  12093. tempIndex = connectorIdInt -1;
  12094. }
  12095. for (int index = 0; index < CCS_QUANTITY; index++)
  12096. {
  12097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12098. {
  12099. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12100. {
  12101. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12102. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12103. {
  12104. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12105. {
  12106. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12107. {
  12108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12109. }
  12110. else
  12111. {
  12112. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12114. }
  12115. }
  12116. else if((ShmSysConfigAndInfo->SysInfo.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'))
  12117. {
  12118. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12119. }
  12120. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12121. {
  12122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12123. }
  12124. else
  12125. {
  12126. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12127. }
  12128. }
  12129. else if((ShmSysConfigAndInfo->SysInfo.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
  12130. {
  12131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12132. }
  12133. }
  12134. else
  12135. {
  12136. //replace reservation
  12137. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12139. }
  12140. }
  12141. } // END FOR CCS_QUANTITY
  12142. }
  12143. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12144. {
  12145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12146. {
  12147. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12148. }
  12149. else
  12150. {
  12151. tempIndex = connectorIdInt -1;
  12152. }
  12153. for (int index = 0; index < GB_QUANTITY; index++)
  12154. {
  12155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12156. {
  12157. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12158. {
  12159. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12160. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12161. {
  12162. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12163. {
  12164. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12165. {
  12166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12167. }
  12168. else
  12169. {
  12170. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12171. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12172. }
  12173. }
  12174. 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'))
  12175. {
  12176. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12177. }
  12178. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12179. {
  12180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12181. }
  12182. else
  12183. {
  12184. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12185. }
  12186. }
  12187. 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
  12188. {
  12189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12190. }
  12191. }
  12192. else
  12193. {
  12194. //replace reservation
  12195. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12196. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12197. }
  12198. }
  12199. }// END FOR GB_QUANTITY
  12200. }
  12201. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12202. {
  12203. tempIndex = connectorIdInt -1;
  12204. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12205. {
  12206. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12207. {
  12208. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12209. {
  12210. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12211. 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
  12212. {
  12213. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12214. {
  12215. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12216. {
  12217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12218. }
  12219. else
  12220. {
  12221. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12222. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12223. }
  12224. }
  12225. 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'))
  12226. {
  12227. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12228. }
  12229. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12230. {
  12231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12232. }
  12233. else
  12234. {
  12235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12236. }
  12237. }
  12238. 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
  12239. {
  12240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12241. }
  12242. }
  12243. else
  12244. {
  12245. //replace reservation
  12246. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12247. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12248. }
  12249. }
  12250. }// END FOR GB_QUANTITY
  12251. }
  12252. else
  12253. {
  12254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12255. {
  12256. tempIndex = 2;
  12257. }
  12258. else
  12259. {
  12260. tempIndex = (connectorIdInt -1);
  12261. }
  12262. for (int index = 0; index < AC_QUANTITY; index++)
  12263. {
  12264. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12265. {
  12266. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12267. {
  12268. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12269. {
  12270. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12271. {
  12272. 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))
  12273. {
  12274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12275. }
  12276. else
  12277. {
  12278. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12280. }
  12281. }
  12282. 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'))
  12283. {
  12284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12285. }
  12286. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12287. {
  12288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12289. }
  12290. else
  12291. {
  12292. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12293. }
  12294. }
  12295. 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
  12296. {
  12297. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12298. }
  12299. }
  12300. else
  12301. {
  12302. //replace reservation
  12303. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12304. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12305. }
  12306. }
  12307. } // END FOR AC_QUANTITY
  12308. }
  12309. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12310. }
  12311. else if(connectorIdInt == 0)
  12312. {
  12313. //check Transaction active
  12314. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12315. {
  12316. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12317. {
  12318. 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'))
  12319. {
  12320. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12321. goto end;
  12322. }
  12323. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12324. {
  12325. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12326. goto end;
  12327. }
  12328. 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
  12329. {
  12330. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12331. goto end;
  12332. }
  12333. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12334. {
  12335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12336. goto end;
  12337. }
  12338. }
  12339. }// END FOR CHAdeMO_QUANTITY
  12340. for (int index = 0; index < CCS_QUANTITY; index++)
  12341. {
  12342. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12343. {
  12344. 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'))
  12345. {
  12346. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12347. goto end;
  12348. }
  12349. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12350. {
  12351. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12352. goto end;
  12353. }
  12354. 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
  12355. {
  12356. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12357. goto end;
  12358. }
  12359. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12360. {
  12361. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12362. goto end;
  12363. }
  12364. }
  12365. } // END FOR CCS_QUANTITY
  12366. for (int index = 0; index < GB_QUANTITY; index++)
  12367. {
  12368. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12369. {
  12370. 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'))
  12371. {
  12372. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12373. goto end;
  12374. }
  12375. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12376. {
  12377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12378. goto end;
  12379. }
  12380. 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
  12381. {
  12382. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12383. goto end;
  12384. }
  12385. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12386. {
  12387. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12388. goto end;
  12389. }
  12390. }
  12391. } // END FOR GB_QUANTITY
  12392. for (int index = 0; index < AC_QUANTITY; index++)
  12393. {
  12394. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12395. {
  12396. 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'))
  12397. {
  12398. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12399. goto end;
  12400. }
  12401. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12402. {
  12403. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12404. goto end;
  12405. }
  12406. 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
  12407. {
  12408. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12409. goto end;
  12410. }
  12411. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12412. {
  12413. 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))
  12414. {
  12415. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12416. goto end;
  12417. }
  12418. }
  12419. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12420. {
  12421. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12422. goto end;
  12423. }
  12424. }
  12425. }// END FOR AC_QUANTITY
  12426. //The connectorId is 0
  12427. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12429. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12430. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12431. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12432. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12433. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12434. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12435. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12436. result = TRUE;
  12437. return result;
  12438. }
  12439. else
  12440. {
  12441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12442. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12443. }
  12444. if(strcmp(comfirmstr,"Accepted") == 0)
  12445. {
  12446. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12447. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12448. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12449. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12450. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12451. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12452. result = TRUE;
  12453. return result;
  12454. }
  12455. end:
  12456. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12457. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12458. return result;
  12459. }
  12460. int handleResetRequest(char *uuid, char *payload)
  12461. {
  12462. mtrace();
  12463. int result = FAIL;
  12464. char sstr[10]={0},sstrtemp[30]={ 0 };
  12465. char typestr[10]={0};
  12466. char comfirmstr[20]={0};
  12467. int c = 0;
  12468. char *loc;
  12469. DEBUG_INFO("handleResetRequest...\n");
  12470. strcpy(sstrtemp, stringtrimspace(payload));
  12471. loc = strstr(sstrtemp, "type");
  12472. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12473. c = 0;
  12474. while (loc[3+strlen("type")+c] != '\"')
  12475. {
  12476. sstr[c] = loc[3+strlen("type")+c];
  12477. c++;
  12478. }
  12479. sstr[c] = '\0';
  12480. strcpy(typestr,sstr);
  12481. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12482. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12483. {
  12484. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12485. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12486. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12487. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12488. }
  12489. else
  12490. {
  12491. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12492. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12493. result = PASS;
  12494. }
  12495. sendResetConfirmation(uuid, comfirmstr);
  12496. return result;
  12497. }
  12498. int handleSendLocalListRequest(char *uuid, char *payload)
  12499. {
  12500. mtrace();
  12501. int result = FAIL;
  12502. char comfirmstr[20];
  12503. int checkState_Faulted = FALSE;
  12504. json_object *SendLocalList;
  12505. DEBUG_INFO("handleSendLocalListRequest...\n");
  12506. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12507. {
  12508. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12509. goto end;
  12510. }
  12511. //check Charge Point state
  12512. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12513. {
  12514. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12515. {
  12516. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12517. }
  12518. }
  12519. for (int index = 0; index < CCS_QUANTITY; index++)
  12520. {
  12521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12522. {
  12523. checkState_Faulted = TRUE; //OCPP Status
  12524. }
  12525. }
  12526. for (int index = 0; index < GB_QUANTITY; index++)
  12527. {
  12528. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12529. {
  12530. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12531. }
  12532. }
  12533. //check Charge Point state
  12534. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12535. {
  12536. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12537. {
  12538. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12539. }
  12540. }
  12541. //check Charge Point state
  12542. for (int index = 0; index < AC_QUANTITY; index++)
  12543. {
  12544. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12545. {
  12546. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12547. }
  12548. }
  12549. if(checkState_Faulted == TRUE)
  12550. {
  12551. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12552. goto end;
  12553. }
  12554. // Parsing payload
  12555. SendLocalList = json_tokener_parse(payload);
  12556. if(!is_error(SendLocalList))
  12557. {
  12558. // Required data
  12559. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12560. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12561. // Optional data
  12562. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12563. {
  12564. //Check UpdateType
  12565. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12566. {
  12567. //Local list full update
  12568. DEBUG_INFO("Local list full update.\n");
  12569. locallistVersion = 0;
  12570. OCPP_getListVerion();
  12571. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12572. {
  12573. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12574. goto end;
  12575. }
  12576. OCPP_cleanLocalList();
  12577. }
  12578. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12579. {
  12580. //Local list different update
  12581. DEBUG_INFO("Local list different update.\n");
  12582. locallistVersion = 0;
  12583. OCPP_getListVerion();
  12584. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12585. {
  12586. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12587. goto end;
  12588. }
  12589. }
  12590. else
  12591. {
  12592. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12593. goto end;
  12594. }
  12595. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12596. {
  12597. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12598. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12599. goto end;
  12600. }
  12601. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12602. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12603. {
  12604. 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"))));
  12605. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12606. {
  12607. 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"))));
  12608. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12609. 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"))));
  12610. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12611. 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"))));
  12612. }
  12613. // Add to db
  12614. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12615. {
  12616. //Local list full update
  12617. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12618. idx,
  12619. ShmOCPP16Data->SendLocalList.ListVersion,
  12620. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12621. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12622. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12623. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12624. // update list
  12625. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12626. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12627. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12628. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12629. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12630. }
  12631. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12632. {
  12633. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12634. idx,
  12635. ShmOCPP16Data->SendLocalList.ListVersion,
  12636. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12637. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12638. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12639. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12640. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12641. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12642. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12643. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12644. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12645. }
  12646. }
  12647. }
  12648. else
  12649. {
  12650. //Check UpdateType
  12651. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12652. {
  12653. //Local list full update
  12654. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12655. OCPP_cleanLocalList();
  12656. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12657. goto end;
  12658. }
  12659. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12660. {
  12661. //Local list different update
  12662. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12663. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12664. goto end;
  12665. }
  12666. }
  12667. result = PASS;
  12668. }
  12669. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12670. end:
  12671. json_object_put(SendLocalList);
  12672. sendSendLocalListConfirmation(uuid, comfirmstr);
  12673. return result;
  12674. }
  12675. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12676. {
  12677. mtrace();
  12678. int result = FAIL;
  12679. struct StructSetChargingProfile SetProfileReq = {0};
  12680. int tempchargingProfileIdInt;
  12681. int tempstackLevelInt;
  12682. int chargingSchedulePeriodCount = 0;
  12683. char comfirmstr[20]={0};
  12684. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12685. char rmFileCmd[128]={0};
  12686. int profileQuantity = 0;
  12687. int replaceableProfileCnt = 0;
  12688. json_object *SetChargingProfile;
  12689. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12690. SetChargingProfile = json_tokener_parse(payload);
  12691. if(!is_error(SetChargingProfile))
  12692. {
  12693. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12694. {
  12695. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12696. }
  12697. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12698. {
  12699. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12700. {
  12701. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12702. }
  12703. else
  12704. {
  12705. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12706. DEBUG_WARN("Cannot find chargingProfileId field.");
  12707. goto end;
  12708. }
  12709. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12710. {
  12711. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12712. }
  12713. else
  12714. {
  12715. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12716. DEBUG_WARN("Cannot find stackLevel field.");
  12717. goto end;
  12718. }
  12719. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12720. {
  12721. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12722. }
  12723. else
  12724. {
  12725. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12726. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12727. goto end;
  12728. }
  12729. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12730. {
  12731. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12732. }
  12733. else
  12734. {
  12735. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12736. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12737. goto end;
  12738. }
  12739. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12740. {
  12741. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12742. }
  12743. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12744. {
  12745. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12746. }
  12747. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12748. {
  12749. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12750. }
  12751. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12752. {
  12753. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12754. }
  12755. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12756. {
  12757. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12758. {
  12759. 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")));
  12760. }
  12761. else
  12762. {
  12763. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12764. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12765. goto end;
  12766. }
  12767. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12768. {
  12769. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12770. }
  12771. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12772. {
  12773. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12774. }
  12775. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12776. {
  12777. 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")));
  12778. }
  12779. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12780. {
  12781. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12782. if(chargingSchedulePeriodCount <= 10)
  12783. {
  12784. 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++)
  12785. {
  12786. 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)
  12787. {
  12788. 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"));
  12789. }
  12790. else
  12791. {
  12792. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12793. DEBUG_WARN("Cannot find startPeriod field.");
  12794. goto end;
  12795. }
  12796. 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)
  12797. {
  12798. 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"));
  12799. }
  12800. else
  12801. {
  12802. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12803. DEBUG_WARN("Cannot find limit field.");
  12804. goto end;
  12805. }
  12806. 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)
  12807. {
  12808. 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"));
  12809. }
  12810. }
  12811. }
  12812. }
  12813. else
  12814. {
  12815. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12816. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12817. goto end;
  12818. }
  12819. }
  12820. else
  12821. {
  12822. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12823. DEBUG_WARN("Cannot find chargingSchedule field.");
  12824. goto end;
  12825. }
  12826. }
  12827. }
  12828. // Profile periods quantity check
  12829. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12830. {
  12831. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12832. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12833. goto end;
  12834. }
  12835. // Check invalid limit
  12836. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12837. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12838. {
  12839. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12840. {
  12841. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12842. {
  12843. 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)))) ||
  12844. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12845. {
  12846. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12847. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12848. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12849. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12850. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12851. goto end;
  12852. }
  12853. }
  12854. }
  12855. else
  12856. {
  12857. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12858. {
  12859. 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) ||
  12860. (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)))
  12861. {
  12862. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12863. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12864. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12865. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12866. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12867. goto end;
  12868. }
  12869. }
  12870. }
  12871. }
  12872. // Profile purpose info check
  12873. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12874. {
  12875. FILE *fp;
  12876. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12877. if(SetProfileReq.ConnectorId != 0)
  12878. {
  12879. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12880. DEBUG_WARN("Profile connector id is not 0.\n");
  12881. goto end;
  12882. }
  12883. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12884. if (!fp)
  12885. {
  12886. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12887. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12888. }
  12889. else
  12890. {
  12891. char *line = NULL;
  12892. size_t len = 0;
  12893. while(getline(&line, &len, fp) != -1)
  12894. {
  12895. json_object *obj = NULL;
  12896. obj = json_tokener_parse(line);
  12897. if(is_error(obj))
  12898. {
  12899. DEBUG_ERROR("Parse txProfile from file error.\n");
  12900. }
  12901. else
  12902. {
  12903. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12904. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12905. {
  12906. profileQuantity += 1;
  12907. }
  12908. else
  12909. replaceableProfileCnt += 1;
  12910. }
  12911. }
  12912. }
  12913. fclose(fp);
  12914. }
  12915. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12916. {
  12917. FILE *fp;
  12918. char filename[128]={0};
  12919. int tmpProfileQuantity;
  12920. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12921. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12922. {
  12923. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12924. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12925. goto end;
  12926. }
  12927. if(SetProfileReq.ConnectorId == 0)
  12928. {
  12929. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12930. {
  12931. tmpProfileQuantity = 0;
  12932. memset(filename, 0, ARRAY_SIZE(filename));
  12933. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12934. fp = fopen(filename, "r");
  12935. if (!fp)
  12936. {
  12937. DEBUG_INFO("%s does not create.\n", filename);
  12938. fp = fopen(filename, "w+");
  12939. }
  12940. else
  12941. {
  12942. char *line = NULL;
  12943. size_t len = 0;
  12944. while(getline(&line, &len, fp) != -1)
  12945. {
  12946. json_object *obj = NULL;
  12947. obj = json_tokener_parse(line);
  12948. if(is_error(obj))
  12949. {
  12950. DEBUG_ERROR("Parse txProfile from file error.\n");
  12951. }
  12952. else
  12953. {
  12954. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12955. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12956. {
  12957. tmpProfileQuantity += 1;
  12958. }
  12959. else
  12960. replaceableProfileCnt += 1;
  12961. }
  12962. }
  12963. }
  12964. fclose(fp);
  12965. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12966. }
  12967. }
  12968. else
  12969. {
  12970. memset(filename, 0, ARRAY_SIZE(filename));
  12971. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12972. fp = fopen(filename, "r");
  12973. if (!fp)
  12974. {
  12975. DEBUG_INFO("%s does not create.\n", filename);
  12976. fp = fopen(filename, "w+");
  12977. }
  12978. else
  12979. {
  12980. char *line = NULL;
  12981. size_t len = 0;
  12982. while(getline(&line, &len, fp) != -1)
  12983. {
  12984. json_object *obj = NULL;
  12985. obj = json_tokener_parse(line);
  12986. if(is_error(obj))
  12987. {
  12988. DEBUG_ERROR("Parse txProfile from file error.\n");
  12989. }
  12990. else
  12991. {
  12992. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12993. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12994. {
  12995. profileQuantity += 1;
  12996. }
  12997. else
  12998. replaceableProfileCnt += 1;
  12999. }
  13000. }
  13001. }
  13002. fclose(fp);
  13003. }
  13004. }
  13005. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13006. {
  13007. int isMatchTransactiodId= FALSE;
  13008. FILE *fp;
  13009. char filename[128]={0};
  13010. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13011. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13012. if(SetProfileReq.ConnectorId == 0)
  13013. {
  13014. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13015. DEBUG_WARN("Profile connector id is 0.\n");
  13016. goto end;
  13017. }
  13018. int tempIndex = 0;
  13019. //check Transaction active
  13020. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13021. {
  13022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13023. {
  13024. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13025. }
  13026. else
  13027. {
  13028. tempIndex = SetProfileReq.ConnectorId -1;
  13029. }
  13030. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13031. {
  13032. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13033. {
  13034. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13035. {
  13036. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13037. {
  13038. isMatchTransactiodId = TRUE;
  13039. break;
  13040. }
  13041. }
  13042. }
  13043. }
  13044. }
  13045. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13046. {
  13047. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13048. {
  13049. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13050. }
  13051. else
  13052. {
  13053. tempIndex = SetProfileReq.ConnectorId -1;
  13054. }
  13055. for (int index = 0; index < CCS_QUANTITY; index++)
  13056. {
  13057. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13058. {
  13059. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13060. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13061. {
  13062. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13063. {
  13064. isMatchTransactiodId = TRUE;
  13065. break;
  13066. }
  13067. }
  13068. }
  13069. }
  13070. }
  13071. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13072. {
  13073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13074. {
  13075. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13076. }
  13077. else
  13078. {
  13079. tempIndex = SetProfileReq.ConnectorId -1;
  13080. }
  13081. for (int index = 0; index < GB_QUANTITY; index++)
  13082. {
  13083. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13084. {
  13085. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13086. {
  13087. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13088. {
  13089. isMatchTransactiodId = TRUE;
  13090. break;
  13091. }
  13092. }
  13093. }
  13094. }
  13095. }
  13096. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13097. {
  13098. tempIndex = SetProfileReq.ConnectorId -1;
  13099. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13100. {
  13101. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13102. {
  13103. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13104. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13105. {
  13106. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13107. {
  13108. isMatchTransactiodId = TRUE;
  13109. break;
  13110. }
  13111. }
  13112. }
  13113. }
  13114. }
  13115. else
  13116. {
  13117. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13118. {
  13119. tempIndex = 2;
  13120. }
  13121. else
  13122. {
  13123. tempIndex = (SetProfileReq.ConnectorId -1);
  13124. }
  13125. for (int index = 0; index < AC_QUANTITY; index++)
  13126. {
  13127. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13128. {
  13129. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13130. {
  13131. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13132. {
  13133. isMatchTransactiodId = TRUE;
  13134. break;
  13135. }
  13136. }
  13137. }
  13138. }
  13139. }
  13140. //check Transaction active
  13141. if(isMatchTransactiodId == FALSE)
  13142. {
  13143. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13144. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13145. goto end;
  13146. }
  13147. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13148. {
  13149. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13150. DEBUG_WARN("Connector id is over max gun number.\n");
  13151. goto end;
  13152. }
  13153. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13154. fp = fopen(filename, "r");
  13155. if (!fp)
  13156. {
  13157. DEBUG_INFO("%s does not create.\n", filename);
  13158. fp = fopen(filename, "w+");
  13159. }
  13160. else
  13161. {
  13162. char *line = NULL;
  13163. size_t len = 0;
  13164. while(getline(&line, &len, fp) != -1)
  13165. {
  13166. json_object *obj = NULL;
  13167. obj = json_tokener_parse(line);
  13168. if(is_error(obj))
  13169. {
  13170. DEBUG_ERROR("Parse txProfile from file error.\n");
  13171. }
  13172. else
  13173. {
  13174. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13175. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13176. {
  13177. profileQuantity += 1;
  13178. }
  13179. else
  13180. replaceableProfileCnt += 1;
  13181. }
  13182. }
  13183. }
  13184. fclose(fp);
  13185. }
  13186. // Check ChargeProfileMaxStackLevel
  13187. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13188. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13189. {
  13190. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13191. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13192. goto end;
  13193. }
  13194. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13195. {
  13196. FILE *fp;
  13197. char dataLine[4096]={0};
  13198. char fnametemp[128]={0};
  13199. int tmpProfileQuantity;
  13200. //Check ChargePointMaxProfile.json exit
  13201. profileQuantity = 0;
  13202. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13203. {
  13204. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13205. //Check Charging Profile Count
  13206. tmpProfileQuantity = 0;
  13207. while(fscanf(fp, "%s", dataLine) != EOF)
  13208. {
  13209. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13210. {
  13211. profileQuantity += 1;
  13212. tmpProfileQuantity += 1;
  13213. }
  13214. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13215. }
  13216. fclose(fp);
  13217. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13218. }
  13219. //Check TxDefaultProfile_%d.json
  13220. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13221. {
  13222. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13223. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13224. if((access(fnametemp,F_OK))!=-1)
  13225. {
  13226. fp = fopen(fnametemp, "r");
  13227. //Check Charging Profile Count
  13228. tmpProfileQuantity = 0;
  13229. while(fscanf(fp, "%s", dataLine) != EOF)
  13230. {
  13231. //DEBUG_INFO("word=%s\n",word);
  13232. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13233. {
  13234. profileQuantity += 1;
  13235. tmpProfileQuantity += 1;
  13236. }
  13237. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13238. }
  13239. fclose(fp);
  13240. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13241. }
  13242. }
  13243. //Check TxProfile_%d.json
  13244. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13245. {
  13246. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13247. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13248. if((access(fnametemp,F_OK))!=-1)
  13249. {
  13250. fp = fopen(fnametemp, "r");
  13251. //Check Charging Profile Count
  13252. tmpProfileQuantity = 0;
  13253. while(fscanf(fp, "%s", dataLine) != EOF)
  13254. {
  13255. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13256. {
  13257. profileQuantity += 1;
  13258. tmpProfileQuantity += 1;
  13259. }
  13260. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13261. }
  13262. fclose(fp);
  13263. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13264. }
  13265. }
  13266. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13267. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13268. // To check total Profile quantity
  13269. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13270. {
  13271. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13272. {
  13273. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13274. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13275. goto end;
  13276. }
  13277. }
  13278. else
  13279. {
  13280. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13281. {
  13282. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13283. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13284. goto end;
  13285. }
  13286. }
  13287. }
  13288. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13289. //**********************************Write to File********************************************************/
  13290. {
  13291. FILE *infile;
  13292. FILE *outfile;
  13293. char dataLine[4096]={0};
  13294. char filename[128]={0};
  13295. int chkChar=0;
  13296. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13297. {
  13298. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13299. {
  13300. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13301. }
  13302. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13303. {
  13304. if(SetProfileReq.ConnectorId==0)
  13305. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13306. else
  13307. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13308. }
  13309. else
  13310. {
  13311. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13312. }
  13313. infile = fopen (filename, "r");
  13314. outfile = fopen (tempfile, "w");
  13315. chkChar = fgetc(infile);
  13316. rewind(infile);
  13317. if(chkChar == EOF)
  13318. {
  13319. // Profile is empty
  13320. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13321. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13322. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13323. fclose(infile);
  13324. fclose(outfile);
  13325. sprintf(rmFileCmd,"rm -f %s",filename);
  13326. system(rmFileCmd);
  13327. rename(tempfile, filename);
  13328. }
  13329. else
  13330. {
  13331. // Profile is not empty
  13332. int ChargingProfileAdded = FALSE;
  13333. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13334. {
  13335. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13336. json_object *tmpChargingProfile;
  13337. tmpChargingProfile = json_tokener_parse(dataLine);
  13338. if(!is_error(SetChargingProfile))
  13339. {
  13340. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13341. {
  13342. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13343. {
  13344. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13345. }
  13346. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13347. {
  13348. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13349. }
  13350. }
  13351. }
  13352. json_object_put(tmpChargingProfile);
  13353. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13354. {
  13355. if(ChargingProfileAdded == FALSE)
  13356. {
  13357. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13358. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13359. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13360. ChargingProfileAdded = TRUE;
  13361. }
  13362. }
  13363. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13364. {
  13365. if(ChargingProfileAdded == FALSE)
  13366. {
  13367. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13368. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13369. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13370. ChargingProfileAdded = TRUE;
  13371. }
  13372. }
  13373. else
  13374. {
  13375. fprintf(outfile,"%s\n",dataLine);
  13376. if(ChargingProfileAdded == FALSE)
  13377. {
  13378. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13379. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13380. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13381. ChargingProfileAdded = TRUE;
  13382. }
  13383. }
  13384. } // end of while loop
  13385. fclose(infile);
  13386. fclose(outfile);
  13387. sprintf(rmFileCmd,"rm -f %s",filename);
  13388. system(rmFileCmd);
  13389. rename(tempfile, filename);
  13390. }
  13391. }
  13392. sleep(1);
  13393. result = TRUE;
  13394. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13395. }
  13396. end:
  13397. json_object_put(SetChargingProfile);
  13398. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13399. {
  13400. if(SetProfileReq.ConnectorId == 0)
  13401. {
  13402. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13403. {
  13404. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13405. }
  13406. }
  13407. else
  13408. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13409. }
  13410. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13411. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13412. return result;
  13413. }
  13414. int handleTriggerMessageRequest(char *uuid, char *payload)
  13415. {
  13416. mtrace();
  13417. int result = FAIL;
  13418. int connectorIdIsNULL = FALSE;
  13419. int connectorIdInt =0;
  13420. char sstr[40]={0},sstrtemp[100]={ 0 };
  13421. char requestedMessagestr[40]={0};
  13422. char comfirmstr[20]={0};
  13423. int c = 0;
  13424. char *loc;
  13425. DEBUG_INFO("handleTriggerMessageRequest\n");
  13426. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13427. strcpy(sstrtemp, stringtrimspace(payload));
  13428. c = 0;
  13429. loc = strstr(sstrtemp, "requestedMessage");
  13430. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13431. {
  13432. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13433. c++;
  13434. }
  13435. sstr[c] = '\0';
  13436. strcpy(requestedMessagestr, sstr);
  13437. c = 0;
  13438. loc = strstr(sstrtemp, "connectorId");
  13439. if(loc == NULL)
  13440. {
  13441. connectorIdIsNULL = TRUE;
  13442. }
  13443. else
  13444. {
  13445. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13446. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13447. {
  13448. sstr[c] = loc[strlen("connectorId")+2+c];
  13449. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13450. c++;
  13451. }
  13452. sstr[c] = '\0';
  13453. connectorIdInt = atoi(sstr);
  13454. }
  13455. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13456. {
  13457. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13458. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13459. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13460. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13461. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13462. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13463. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13464. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13465. {
  13466. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13467. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13468. return TRUE;
  13469. }
  13470. else
  13471. {
  13472. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13473. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13474. }
  13475. }
  13476. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13477. {
  13478. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13479. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13480. return TRUE;
  13481. }
  13482. //==========================
  13483. // Trigger message
  13484. //==========================
  13485. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13486. {
  13487. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13488. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13489. {
  13490. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13491. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13492. }
  13493. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13494. }
  13495. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13496. {
  13497. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13498. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13499. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13500. }
  13501. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13502. {
  13503. //sendBootNotificationRequest();
  13504. server_sign = FALSE;
  13505. }
  13506. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13507. {
  13508. refreshStartTimer(&clientTime.Heartbeat);
  13509. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13510. }
  13511. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13512. {
  13513. if(connectorIdIsNULL == FALSE)
  13514. {
  13515. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13516. {
  13517. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13518. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13519. }
  13520. }
  13521. else
  13522. {
  13523. for(int idx=0;idx< gunTotalNumber;idx++)
  13524. {
  13525. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13526. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13527. }
  13528. }
  13529. }
  13530. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13531. {
  13532. if(connectorIdIsNULL == FALSE)
  13533. {
  13534. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13535. {
  13536. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13537. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13538. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13539. }
  13540. }
  13541. else
  13542. {
  13543. for(int idx=0;idx< gunTotalNumber;idx++)
  13544. {
  13545. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13546. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13547. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13548. }
  13549. }
  13550. }
  13551. return result;
  13552. }
  13553. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13554. {
  13555. mtrace();
  13556. int result = FAIL;
  13557. int connectorIdInt =0;
  13558. char comfirmstr[20]={0};
  13559. int tempIndex = 0;
  13560. json_object *UnlockConnector;
  13561. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13562. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13563. UnlockConnector = json_tokener_parse(payload);
  13564. if(!is_error(UnlockConnector))
  13565. {
  13566. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13567. {
  13568. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13569. }
  13570. }
  13571. json_object_put(UnlockConnector);
  13572. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13573. if(gunTotalNumber == 0)
  13574. {
  13575. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13576. goto end;
  13577. }
  13578. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13579. {
  13580. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13581. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13582. goto end;
  13583. }
  13584. else
  13585. {
  13586. //check Transaction active
  13587. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13588. {
  13589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13590. {
  13591. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13592. }
  13593. else
  13594. {
  13595. tempIndex = connectorIdInt -1;
  13596. }
  13597. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13598. {
  13599. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13600. {
  13601. //stop Transaction
  13602. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13603. }
  13604. }
  13605. }
  13606. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13607. {
  13608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13609. {
  13610. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13611. }
  13612. else
  13613. {
  13614. tempIndex = connectorIdInt -1;
  13615. }
  13616. for (int index = 0; index < CCS_QUANTITY; index++)
  13617. {
  13618. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13619. {
  13620. //stop Transaction
  13621. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13622. }
  13623. }
  13624. }
  13625. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13626. {
  13627. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13628. {
  13629. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13630. }
  13631. else
  13632. {
  13633. tempIndex = connectorIdInt -1;
  13634. }
  13635. for (int index = 0; index < GB_QUANTITY; index++)
  13636. {
  13637. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13638. {
  13639. //stop Transaction
  13640. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13641. }
  13642. }
  13643. }
  13644. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13645. {
  13646. tempIndex = connectorIdInt -1;
  13647. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13648. {
  13649. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13650. {
  13651. //stop Transaction
  13652. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13653. }
  13654. }
  13655. }
  13656. else
  13657. {
  13658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13659. {
  13660. tempIndex = 2;
  13661. }
  13662. else
  13663. {
  13664. tempIndex = connectorIdInt-1;
  13665. }
  13666. for (int index = 0; index < AC_QUANTITY; index++)
  13667. {
  13668. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13669. {
  13670. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13671. }
  13672. }
  13673. }
  13674. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13675. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13676. result = TRUE;
  13677. return result;
  13678. }
  13679. end:
  13680. //json_object_put(obj); --- remove temporally
  13681. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13682. return result;
  13683. }
  13684. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13685. {
  13686. mtrace();
  13687. int result = FAIL;
  13688. pthread_t t;
  13689. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13690. sendUpdateFirmwareConfirmation(uuid);
  13691. if(!interLock.isUpdateFirmwareGoing)
  13692. {
  13693. interLock.isUpdateFirmwareGoing = 1;
  13694. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13695. sleep(1);
  13696. }
  13697. else
  13698. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13699. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13700. return result;
  13701. }
  13702. void *UpdateFirmwareProcess(void *data)
  13703. {
  13704. pthread_detach(pthread_self());
  13705. mtrace();
  13706. int retriesInt =0, retryIntervalInt=0;
  13707. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13708. int port=0;
  13709. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13710. int isSuccess = 0;
  13711. char ftpbuf[1024];
  13712. char temp[1024];
  13713. char * pch;
  13714. json_object *UpdateFirmware;
  13715. UpdateFirmware = json_tokener_parse(data);
  13716. if(!is_error(UpdateFirmware))
  13717. {
  13718. // Required data
  13719. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13720. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13721. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13722. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13723. // Optional data
  13724. if(json_object_object_get(UpdateFirmware, "retries"))
  13725. {
  13726. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13727. }
  13728. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13729. {
  13730. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13731. }
  13732. }
  13733. json_object_put(UpdateFirmware);
  13734. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13735. memset(path, 0, ARRAY_SIZE(path));
  13736. // Wait retrieveData
  13737. if(strlen(retrieveDatestr) > 10)
  13738. {
  13739. do
  13740. {
  13741. sleep(1);
  13742. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13743. }
  13744. // Ready to download
  13745. system("rm -f /mnt/*");
  13746. if(strncmp(locationstr,"http", 4) == 0)
  13747. {
  13748. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13749. sprintf(ftppath,"/%s", path);
  13750. DEBUG_INFO("locationstr: %s\n", locationstr);
  13751. DEBUG_INFO("protocol: %s\n",protocol);
  13752. DEBUG_INFO("host: %s\n",host);
  13753. DEBUG_INFO("path: %s\n",path);
  13754. DEBUG_INFO("ftppath: %s\n",ftppath);
  13755. int ftppathlen=strlen(ftppath);
  13756. int i=1;
  13757. char filenametemp[50];
  13758. while(i < ftppathlen)
  13759. {
  13760. int len=ftppathlen-i;
  13761. if(ftppath[len]== 47) // '/' ascll code: 47
  13762. {
  13763. DEBUG_INFO("compare '/' all right\n");
  13764. break;
  13765. }
  13766. i=i+1;
  13767. }
  13768. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13769. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13770. filenametemp[i+1] = 0;
  13771. do
  13772. {
  13773. sleep(1);
  13774. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13775. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13776. sleep(1);
  13777. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13778. if(!isSuccess)
  13779. {
  13780. sleep(1);
  13781. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13782. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13783. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13784. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13785. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13786. }
  13787. else
  13788. {
  13789. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13790. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13791. }
  13792. retriesInt--;
  13793. }while((isSuccess == 0)&&(retriesInt >= 0));
  13794. }
  13795. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13796. {
  13797. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13798. memset(temp, 0, ARRAY_SIZE(temp));
  13799. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13800. strcpy(ftpbuf, locationstr);
  13801. int ftppathlen=strlen(ftpbuf);
  13802. int i=1;
  13803. char filenametemp[50];
  13804. while(i < ftppathlen)
  13805. {
  13806. int len=ftppathlen-i;
  13807. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13808. {
  13809. DEBUG_INFO(" compare '/' all right\n");
  13810. break;
  13811. }
  13812. i=i+1;
  13813. }
  13814. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13815. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13816. filenametemp[i+1] = 0;
  13817. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13818. pch=strchr(temp,'@');
  13819. if(pch==NULL)
  13820. {
  13821. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13822. protocol, host, &port, path);
  13823. strcpy(user,"anonymous");
  13824. strcpy(password,"");
  13825. }
  13826. else
  13827. {
  13828. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13829. protocol, user, host, &port, path);
  13830. }
  13831. sscanf(host,"%[^/]%s",host1, path1);
  13832. sprintf(ftppath,"%s:/%s", host,path);
  13833. if(port == 0)
  13834. {
  13835. port = 21;
  13836. }
  13837. do
  13838. {
  13839. sleep(1);
  13840. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13841. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13842. sleep(1);
  13843. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13844. if(!isSuccess)
  13845. {
  13846. //BulldogUtil.sleepMs(interval*1000);
  13847. DEBUG_INFO("Update firmware request and download file fail.\n");
  13848. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13849. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13850. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13851. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13852. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13853. }
  13854. else
  13855. {
  13856. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13857. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13858. }
  13859. retriesInt--;
  13860. }while((!isSuccess)&&(retriesInt >= 0));
  13861. }
  13862. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13863. {
  13864. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13865. memset(temp, 0, ARRAY_SIZE(temp));
  13866. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13867. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13868. int ftppathlen=strlen(ftpbuf);
  13869. int i=1;
  13870. char filenametemp[50];
  13871. while(i < ftppathlen)
  13872. {
  13873. int len=ftppathlen-i;
  13874. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13875. {
  13876. DEBUG_INFO(" compare '/' all right\n");
  13877. break;
  13878. }
  13879. i=i+1;
  13880. }
  13881. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13882. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13883. filenametemp[i+1] = 0;
  13884. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13885. pch=strchr(temp,'@');
  13886. if(pch==NULL)
  13887. {
  13888. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13889. protocol, host, &port, path);
  13890. strcpy(user,"anonymous");
  13891. strcpy(password,"");
  13892. }
  13893. else
  13894. {
  13895. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13896. protocol, user, password, host, &port, path);
  13897. }
  13898. sscanf(host,"%[^/]%s",host1, path1);
  13899. sprintf(ftppath,"%s", path1);
  13900. //DEBUG_INFO("protocol =%s\n",protocol);
  13901. //DEBUG_INFO("user =%s\n",user);
  13902. //DEBUG_INFO("password =%s\n",password);
  13903. //DEBUG_INFO("host1 =%s\n",host1);
  13904. //DEBUG_INFO("port =%d\n",port);
  13905. //DEBUG_INFO("path1 =%s\n",path1);
  13906. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13907. //ftpFile(host, user, password, port, ftppath, fname);
  13908. //download firmware pthred
  13909. if(port == 0)
  13910. {
  13911. port = 21;
  13912. }
  13913. do
  13914. {
  13915. sleep(1);
  13916. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13917. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13918. sleep(1);
  13919. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13920. if(!isSuccess)
  13921. {
  13922. //BulldogUtil.sleepMs(interval*1000);
  13923. DEBUG_INFO("Update firmware request and download file fail.\n");
  13924. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13925. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13926. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13927. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13928. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13929. }
  13930. else
  13931. {
  13932. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13933. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13934. }
  13935. retriesInt--;
  13936. }while((!isSuccess)&&(retriesInt >= 0));
  13937. }
  13938. else
  13939. {
  13940. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13941. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13942. sleep(1);
  13943. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13944. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13945. }
  13946. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13947. {
  13948. sleep(3);
  13949. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13950. }
  13951. interLock.isUpdateFirmwareGoing = 0;
  13952. pthread_exit(NULL);
  13953. }
  13954. int handleCertificateSignedRequest(char *uuid, char *payload)
  13955. {
  13956. mtrace();
  13957. int result = PASS;
  13958. json_object *CertificateSigned;
  13959. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13960. CertificateSigned = json_tokener_parse(payload);
  13961. if(!is_error(CertificateSigned))
  13962. {
  13963. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13964. }
  13965. json_object_put(CertificateSigned);
  13966. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  13967. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13968. fclose(fp);
  13969. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13970. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13971. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  13972. {
  13973. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13974. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  13975. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  13976. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  13977. }
  13978. else
  13979. {
  13980. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  13981. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  13982. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  13983. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  13984. }
  13985. sendCertificateSignedConfirmation(uuid);
  13986. return result;
  13987. }
  13988. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13989. {
  13990. mtrace();
  13991. int result = PASS;
  13992. json_object *DeleteCertificate;
  13993. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13994. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13995. DeleteCertificate = json_tokener_parse(payload);
  13996. if(!is_error(DeleteCertificate))
  13997. {
  13998. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13999. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14000. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14001. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14002. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14003. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14004. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14005. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14006. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  14007. {
  14008. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  14009. }
  14010. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  14011. {
  14012. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  14013. }
  14014. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  14015. {
  14016. ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  14017. }
  14018. char temp[256] = {0};
  14019. char compareData[256] = {0};
  14020. int isMatch = TRUE;
  14021. // Check CentralSystemRootCertificate
  14022. if(access(ROOTCA_CS,F_OK) != -1)
  14023. {
  14024. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14025. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14026. for(int i = 0; compareData[i]; i++)
  14027. {
  14028. compareData[i] = tolower(compareData[i]);
  14029. }
  14030. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14031. isMatch = FALSE;
  14032. if(isMatch == TRUE)
  14033. {
  14034. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14035. for(int i = 0; compareData[i]; i++)
  14036. {
  14037. compareData[i] = tolower(compareData[i]);
  14038. }
  14039. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14040. isMatch = FALSE;
  14041. }
  14042. if(isMatch == TRUE)
  14043. {
  14044. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14045. for(int i = 0; compareData[i]; i++)
  14046. {
  14047. compareData[i] = tolower(compareData[i]);
  14048. }
  14049. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14050. isMatch = FALSE;
  14051. }
  14052. if(isMatch == TRUE)
  14053. {
  14054. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  14055. sprintf(temp, "rm -f %s", ROOTCA_CS);
  14056. system(temp);
  14057. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14058. goto End;
  14059. }
  14060. }
  14061. // Check ManufacturerRootCertificate
  14062. if(access(ROOTCA_MFG,F_OK) != -1)
  14063. {
  14064. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  14065. isMatch = TRUE;
  14066. parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, compareData);
  14067. for(int i = 0; compareData[i]; i++)
  14068. {
  14069. compareData[i] = tolower(compareData[i]);
  14070. }
  14071. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14072. isMatch = FALSE;
  14073. if(isMatch == TRUE)
  14074. {
  14075. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, compareData);
  14076. for(int i = 0; compareData[i]; i++)
  14077. {
  14078. compareData[i] = tolower(compareData[i]);
  14079. }
  14080. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14081. isMatch = FALSE;
  14082. }
  14083. if(isMatch == TRUE)
  14084. {
  14085. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, compareData);
  14086. for(int i = 0; compareData[i]; i++)
  14087. {
  14088. compareData[i] = tolower(compareData[i]);
  14089. }
  14090. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14091. isMatch = FALSE;
  14092. }
  14093. if(isMatch == TRUE)
  14094. {
  14095. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  14096. sprintf(temp, "rm -f %s", ROOTCA_MFG);
  14097. system(temp);
  14098. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14099. goto End;
  14100. }
  14101. }
  14102. // Check certCP
  14103. if(access(CERTIFICATE_CP,F_OK) != -1)
  14104. {
  14105. DEBUG_INFO("Checking certCP...\n");
  14106. isMatch = TRUE;
  14107. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  14108. for(int i = 0; compareData[i]; i++)
  14109. {
  14110. compareData[i] = tolower(compareData[i]);
  14111. }
  14112. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14113. isMatch = FALSE;
  14114. if(isMatch == TRUE)
  14115. {
  14116. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  14117. for(int i = 0; compareData[i]; i++)
  14118. {
  14119. compareData[i] = tolower(compareData[i]);
  14120. }
  14121. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14122. isMatch = FALSE;
  14123. }
  14124. if(isMatch == TRUE)
  14125. {
  14126. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  14127. for(int i = 0; compareData[i]; i++)
  14128. {
  14129. compareData[i] = tolower(compareData[i]);
  14130. }
  14131. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14132. isMatch = FALSE;
  14133. }
  14134. if(isMatch == TRUE)
  14135. {
  14136. DEBUG_INFO("Deleting certCP...\n");
  14137. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14138. system(temp);
  14139. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14140. goto End;
  14141. }
  14142. }
  14143. }
  14144. End:
  14145. json_object_put(DeleteCertificate);
  14146. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14147. sendDeleteCertificateConfirmation(uuid);
  14148. return result;
  14149. }
  14150. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14151. {
  14152. mtrace();
  14153. int result = PASS;
  14154. json_object *ExtendedTriggerMessage;
  14155. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14156. ExtendedTriggerMessage = json_tokener_parse(payload);
  14157. if(!is_error(ExtendedTriggerMessage))
  14158. {
  14159. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14160. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14161. {
  14162. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14163. }
  14164. else
  14165. {
  14166. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14167. }
  14168. }
  14169. json_object_put(ExtendedTriggerMessage);
  14170. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14171. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14172. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14173. {
  14174. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14175. }
  14176. else
  14177. {
  14178. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14179. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14180. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14181. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14182. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14183. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14184. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14185. {
  14186. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14187. }
  14188. else
  14189. {
  14190. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14191. }
  14192. }
  14193. sendExtendedTriggerMessageConfirmation(uuid);
  14194. //==========================
  14195. // Trigger message
  14196. //==========================
  14197. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14198. {
  14199. //sendBootNotificationRequest();
  14200. server_sign = FALSE;
  14201. }
  14202. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14203. {
  14204. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14205. }
  14206. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14207. {
  14208. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14209. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14210. {
  14211. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14212. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14213. }
  14214. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14215. }
  14216. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14217. {
  14218. refreshStartTimer(&clientTime.Heartbeat);
  14219. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14220. }
  14221. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14222. {
  14223. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14224. {
  14225. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14226. }
  14227. else
  14228. {
  14229. for(int idx=0;idx< gunTotalNumber;idx++)
  14230. {
  14231. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14232. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14233. }
  14234. }
  14235. }
  14236. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14237. {
  14238. char cmdBuf[1024]={0};
  14239. 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);
  14240. system(cmdBuf);
  14241. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14242. }
  14243. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14244. {
  14245. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14246. {
  14247. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14248. }
  14249. else
  14250. {
  14251. for(int idx=0;idx< gunTotalNumber;idx++)
  14252. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14253. }
  14254. }
  14255. return result;
  14256. }
  14257. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14258. {
  14259. mtrace();
  14260. int result = PASS;
  14261. json_object *GetInstalledCertificateIds;
  14262. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14263. GetInstalledCertificateIds = json_tokener_parse(payload);
  14264. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14265. if(!is_error(GetInstalledCertificateIds))
  14266. {
  14267. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14268. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14269. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14270. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  14271. // Check CentralSystemRootCertificate
  14272. if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL)
  14273. {
  14274. if(access(ROOTCA_CS,F_OK) != -1)
  14275. {
  14276. char parseData[512] = {0};
  14277. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14278. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14279. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  14280. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14281. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14282. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14283. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14284. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14285. }
  14286. else
  14287. {
  14288. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  14289. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14290. }
  14291. }
  14292. // Check ManufacturerRootCertificate
  14293. else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
  14294. {
  14295. if(access(ROOTCA_MFG,F_OK) != -1)
  14296. {
  14297. char parseData[512] = {0};
  14298. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14299. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14300. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, parseData) == PASS)
  14301. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14302. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14303. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14304. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14305. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14306. }
  14307. else
  14308. {
  14309. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  14310. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14311. }
  14312. }
  14313. else
  14314. {
  14315. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14316. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14317. }
  14318. }
  14319. json_object_put(GetInstalledCertificateIds);
  14320. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14321. sendGetInstalledCertificateIdsConfirmation(uuid);
  14322. return result;
  14323. }
  14324. void* GetLogProcess(void* data)
  14325. {
  14326. pthread_detach(pthread_self());
  14327. mtrace();
  14328. 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};
  14329. int port=0;
  14330. int isSuccess = FALSE;
  14331. char cmdBuf[2048];
  14332. struct tm *tmNow;
  14333. time_t CurrentTime;
  14334. struct tm tmStart;
  14335. struct tm tmStop;
  14336. CurrentTime = time(NULL);
  14337. tmNow=localtime(&CurrentTime);
  14338. uint16_t targetYear, targetMonth;
  14339. json_object *GetLog;
  14340. DEBUG_INFO("GetLogProcess...\n");
  14341. GetLog = json_tokener_parse(data);
  14342. if(!is_error(GetLog))
  14343. {
  14344. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14345. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14346. if(json_object_object_get(GetLog, "retries") != NULL)
  14347. {
  14348. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14349. }
  14350. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14351. {
  14352. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14353. }
  14354. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14355. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14356. {
  14357. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14358. }
  14359. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14360. {
  14361. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14362. }
  14363. }
  14364. json_object_put(GetLog);
  14365. // Pack log to compress file
  14366. 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) &&
  14367. (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))
  14368. {
  14369. // Pack system log
  14370. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14371. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14372. targetYear = tmStart.tm_year;
  14373. targetMonth = tmStart.tm_mon;
  14374. do
  14375. {
  14376. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14377. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14378. if(targetMonth+1>=13)
  14379. {
  14380. targetYear += 1;
  14381. targetMonth = 1;
  14382. }
  14383. else
  14384. {
  14385. targetMonth += 1;
  14386. }
  14387. }while((targetYear < (tmNow->tm_year+1900)) ||
  14388. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14389. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14390. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14391. system(cmdBuf);
  14392. // Pack charging & event log
  14393. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14394. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14395. targetYear = tmStart.tm_year;
  14396. targetMonth = tmStart.tm_mon;
  14397. do
  14398. {
  14399. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14400. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14401. if(targetMonth+1>=13)
  14402. {
  14403. targetYear += 1;
  14404. targetMonth = 1;
  14405. }
  14406. else
  14407. {
  14408. targetMonth += 1;
  14409. }
  14410. }while((targetYear < (tmNow->tm_year+1900)) ||
  14411. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14412. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14413. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14414. system(cmdBuf);
  14415. // Combine log file
  14416. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14417. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14418. }
  14419. else
  14420. {
  14421. system("exec /root/logPackTools 'log' 6");
  14422. }
  14423. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14424. system(cmdBuf);
  14425. checkUploadLog();
  14426. //****************location*******************/
  14427. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14428. {
  14429. DEBUG_INFO("location is <Empty>!\n");
  14430. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14431. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14432. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14433. goto end;
  14434. }
  14435. memset(protocol, 0, ARRAY_SIZE(protocol));
  14436. memset(user, 0, ARRAY_SIZE(user) );
  14437. memset(password, 0, ARRAY_SIZE(password));
  14438. memset(host, 0, ARRAY_SIZE(host));
  14439. memset(path, 0, ARRAY_SIZE(path));
  14440. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14441. memset(host1, 0, ARRAY_SIZE(host1));
  14442. memset(path1, 0, ARRAY_SIZE(path1));
  14443. /*location: ftp://user:password@host:port/path*/
  14444. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14445. if((access(fnamePlusPath,F_OK))!=-1)
  14446. {
  14447. DEBUG_INFO("fnamePlusPath exist.\n");
  14448. }
  14449. else
  14450. {
  14451. DEBUG_INFO("fnamePlusPath not exist!\n");
  14452. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14453. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14454. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14455. goto end;
  14456. }
  14457. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14458. {
  14459. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14460. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14461. protocol, host, &port, path);
  14462. strcpy(user,"anonymous");
  14463. strcpy(password,"");
  14464. }
  14465. else
  14466. {
  14467. //DEBUG_INFO("pch=%s\n", pch);
  14468. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14469. protocol, user, password, host, &port, path);
  14470. }
  14471. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14472. {
  14473. DEBUG_INFO("protocol is not ftp/http ! \n");
  14474. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14475. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14476. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14477. goto end;
  14478. }
  14479. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14480. {
  14481. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14482. sprintf(ftppath,"/%s", path);
  14483. do
  14484. {
  14485. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14486. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14487. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14488. sleep(3);
  14489. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14490. if(!isSuccess)
  14491. {
  14492. DEBUG_INFO("Diagnostics fail.\n");
  14493. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14494. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14495. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14496. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14497. }
  14498. else
  14499. {
  14500. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14501. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14502. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14503. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14504. }
  14505. ShmOCPP16Data->GetLog.retries--;
  14506. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14507. }
  14508. else
  14509. {
  14510. sscanf(host,"%[^/]%s",host1, path1);
  14511. if(strlen(path) > 0)
  14512. sprintf(ftppath,"/%s", path);
  14513. else
  14514. sprintf(ftppath,"/%s", path1);
  14515. int ftppathlen=strlen(ftppath);
  14516. int i=1;
  14517. char filenametemp[50];
  14518. while(i < ftppathlen)
  14519. {
  14520. int len=ftppathlen-i;
  14521. if(ftppath[len]== 47) // '/' ascll code: 47
  14522. {
  14523. DEBUG_INFO("find '/' all right\n");
  14524. break;
  14525. }
  14526. i=i+1;
  14527. }
  14528. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14529. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14530. filenametemp[i+1] = 0;
  14531. if(port == 0)
  14532. port = 21;
  14533. do
  14534. {
  14535. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14536. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14537. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14538. sleep(3);
  14539. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14540. if(!isSuccess)
  14541. {
  14542. DEBUG_INFO("Diagnostics fail.\n");
  14543. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14544. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14545. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14546. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14547. }
  14548. else
  14549. {
  14550. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14551. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14552. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14553. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14554. }
  14555. ShmOCPP16Data->GetLog.retries--;
  14556. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14557. }
  14558. end:
  14559. system("rm -f /mnt/*");
  14560. sleep(5);
  14561. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14562. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14563. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14564. interLock.isGetDiagnosticGoing = 0;
  14565. pthread_exit(NULL);
  14566. }
  14567. int handleGetLogRequest(char *uuid, char *payload)
  14568. {
  14569. mtrace();
  14570. int result = PASS;
  14571. time_t CurrentTime;
  14572. struct tm *tm;
  14573. DEBUG_INFO("handleGetLogRequest...\n");
  14574. pthread_t th_Status;
  14575. CurrentTime = time(NULL);
  14576. tm = localtime(&CurrentTime);
  14577. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14578. 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);
  14579. if(!interLock.isGetDiagnosticGoing)
  14580. {
  14581. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14582. interLock.isGetDiagnosticGoing = 1;
  14583. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14584. sleep(1);
  14585. }
  14586. else
  14587. {
  14588. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14589. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14590. }
  14591. sendGetLogConfirmation(uuid);
  14592. return result;
  14593. }
  14594. int handleInstallCertificateRequest(char *uuid, char *payload)
  14595. {
  14596. mtrace();
  14597. int result = PASS;
  14598. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14599. json_object *InstallCertificate;
  14600. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14601. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14602. InstallCertificate = json_tokener_parse(payload);
  14603. if(!is_error(InstallCertificate))
  14604. {
  14605. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14606. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14607. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14608. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14609. char temp[1024];
  14610. FILE *fp = fopen(tempCert, "w");
  14611. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14612. fclose(fp);
  14613. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14614. char strExpDate[30];
  14615. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14616. fp = popen(temp, "r");
  14617. if(fp)
  14618. {
  14619. while(fgets(temp, sizeof(temp), fp) != NULL)
  14620. {
  14621. if(strstr(temp, "notAfter=") != NULL)
  14622. {
  14623. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14624. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14625. break;
  14626. }
  14627. }
  14628. }
  14629. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14630. struct tm tmExpDate;
  14631. struct timeb tbExpDate;
  14632. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14633. tbExpDate.time = mktime(&tmExpDate);
  14634. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14635. {
  14636. DEBUG_INFO("The enddate is already expired...\n");
  14637. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14638. goto End;
  14639. }
  14640. // Verify certificate with rootCA
  14641. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14642. fp = popen(temp, "r");
  14643. if(fp)
  14644. {
  14645. while(fgets(temp, sizeof(temp), fp) != NULL)
  14646. {
  14647. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14648. {
  14649. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14650. break;
  14651. }
  14652. else
  14653. {
  14654. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14655. }
  14656. }
  14657. }
  14658. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14659. {
  14660. //=====================================================
  14661. // Verify if the certificate is valid or not. (OCSP?)
  14662. //=====================================================
  14663. /*
  14664. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14665. // Get ocsp url
  14666. char ocspUrl[512];
  14667. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14668. fp = popen(temp, "r");
  14669. if(fp)
  14670. {
  14671. while(fgets(temp, sizeof(temp), fp) != NULL)
  14672. {
  14673. if(strstr(temp, "://") != NULL)
  14674. {
  14675. strcpy(ocspUrl, temp);
  14676. break;
  14677. }
  14678. }
  14679. }
  14680. // Get certificate chain for issuer
  14681. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14682. *
  14683. // Execute OCSP
  14684. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14685. fp = popen(temp, "r");
  14686. if(fp)
  14687. {
  14688. while(fgets(temp, sizeof(temp), fp) != NULL)
  14689. {
  14690. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14691. {
  14692. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14693. break;
  14694. }
  14695. }
  14696. }
  14697. system("rm -f /Storage/OCPP/tempChain.pem");
  14698. pclose(fp);
  14699. */
  14700. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14701. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14702. {
  14703. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14704. goto End;
  14705. }
  14706. else
  14707. DEBUG_INFO("OCSP verifying...PASS.\n");
  14708. }
  14709. else
  14710. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14711. }
  14712. End:
  14713. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14714. {
  14715. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14716. {
  14717. if(access(ROOTCA_CS,F_OK) != -1)
  14718. {
  14719. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14720. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14721. rename(tempCert, ROOTCA_CS);
  14722. }
  14723. else
  14724. {
  14725. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14726. rename(tempCert, ROOTCA_CS);
  14727. }
  14728. }
  14729. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14730. {
  14731. if(access(ROOTCA_MFG,F_OK) != -1)
  14732. {
  14733. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14734. rename(ROOTCA_MFG, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14735. rename(tempCert, ROOTCA_MFG);
  14736. }
  14737. else
  14738. {
  14739. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14740. rename(tempCert, ROOTCA_MFG);
  14741. }
  14742. }
  14743. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14744. }
  14745. sendInstallCertificateConfirmation(uuid);
  14746. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14747. {
  14748. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14749. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14750. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14751. }
  14752. json_object_put(InstallCertificate);
  14753. return result;
  14754. }
  14755. void *SignedUpdateFirmwareProcess(void *data)
  14756. {
  14757. pthread_detach(pthread_self());
  14758. mtrace();
  14759. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14760. int port=0;
  14761. int isSuccess = 0;
  14762. char ftpbuf[1024];
  14763. char temp[1024];
  14764. char * pch;
  14765. char firmwareFileName[50];
  14766. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14767. json_object *SignedUpdateFirmware;
  14768. SignedUpdateFirmware = json_tokener_parse(data);
  14769. if(!is_error(SignedUpdateFirmware))
  14770. {
  14771. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14772. {
  14773. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14774. }
  14775. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14776. {
  14777. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14778. }
  14779. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14780. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14781. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14782. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14783. {
  14784. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14785. }
  14786. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14787. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14788. }
  14789. json_object_put(SignedUpdateFirmware);
  14790. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14791. memset(path, 0, ARRAY_SIZE(path));
  14792. // Wait retrieveData
  14793. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14794. {
  14795. do
  14796. {
  14797. sleep(1);
  14798. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14799. }
  14800. // Ready to download
  14801. system("rm -f /mnt/*");
  14802. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14803. {
  14804. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14805. sprintf(ftppath,"/%s", path);
  14806. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14807. DEBUG_INFO("protocol: %s\n",protocol);
  14808. DEBUG_INFO("host: %s\n",host);
  14809. DEBUG_INFO("path: %s\n",path);
  14810. DEBUG_INFO("ftppath: %s\n",ftppath);
  14811. int ftppathlen=strlen(ftppath);
  14812. int i=1;
  14813. while(i < ftppathlen)
  14814. {
  14815. int len=ftppathlen-i;
  14816. if(ftppath[len]== 47) // '/' ascll code: 47
  14817. {
  14818. DEBUG_INFO("compare '/' all right\n");
  14819. break;
  14820. }
  14821. i=i+1;
  14822. }
  14823. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14824. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14825. firmwareFileName[i+1] = 0;
  14826. do
  14827. {
  14828. sleep(1);
  14829. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14830. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14831. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14832. sleep(1);
  14833. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14834. if(!isSuccess)
  14835. {
  14836. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14837. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14838. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14839. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14840. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14841. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14842. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14843. }
  14844. else
  14845. {
  14846. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14847. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14848. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14849. }
  14850. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14851. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14852. }
  14853. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14854. {
  14855. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14856. memset(temp, 0, ARRAY_SIZE(temp));
  14857. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14858. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14859. int ftppathlen=strlen(ftpbuf);
  14860. int i=1;
  14861. while(i < ftppathlen)
  14862. {
  14863. int len=ftppathlen-i;
  14864. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14865. {
  14866. DEBUG_INFO(" compare '/' all right\n");
  14867. break;
  14868. }
  14869. i=i+1;
  14870. }
  14871. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14872. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14873. firmwareFileName[i+1] = 0;
  14874. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14875. pch=strchr(temp,'@');
  14876. if(pch==NULL)
  14877. {
  14878. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14879. protocol, host, &port, path);
  14880. strcpy(user,"anonymous");
  14881. strcpy(password,"");
  14882. }
  14883. else
  14884. {
  14885. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14886. protocol, user, host, &port, path);
  14887. }
  14888. sscanf(host,"%[^/]%s",host1, path1);
  14889. sprintf(ftppath,"%s:/%s", host,path);
  14890. if(port == 0)
  14891. {
  14892. port = 21;
  14893. }
  14894. do
  14895. {
  14896. sleep(1);
  14897. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14898. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14899. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14900. sleep(1);
  14901. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14902. if(!isSuccess)
  14903. {
  14904. sleep(1);
  14905. DEBUG_INFO("Update firmware request and download file fail.\n");
  14906. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14907. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14908. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14909. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14910. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14911. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14912. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14913. }
  14914. else
  14915. {
  14916. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14917. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14918. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14919. }
  14920. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14921. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14922. }
  14923. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14924. {
  14925. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14926. memset(temp, 0, ARRAY_SIZE(temp));
  14927. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14928. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14929. int ftppathlen=strlen(ftpbuf);
  14930. int i=1;
  14931. while(i < ftppathlen)
  14932. {
  14933. int len=ftppathlen-i;
  14934. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14935. {
  14936. DEBUG_INFO(" compare '/' all right\n");
  14937. break;
  14938. }
  14939. i=i+1;
  14940. }
  14941. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14942. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14943. firmwareFileName[i+1] = 0;
  14944. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14945. pch=strchr(temp,'@');
  14946. if(pch==NULL)
  14947. {
  14948. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14949. protocol, host, &port, path);
  14950. strcpy(user,"anonymous");
  14951. strcpy(password,"");
  14952. }
  14953. else
  14954. {
  14955. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14956. protocol, user, password, host, &port, path);
  14957. }
  14958. sscanf(host,"%[^/]%s",host1, path1);
  14959. sprintf(ftppath,"%s", path1);
  14960. //DEBUG_INFO("protocol =%s\n",protocol);
  14961. //DEBUG_INFO("user =%s\n",user);
  14962. //DEBUG_INFO("password =%s\n",password);
  14963. //DEBUG_INFO("host1 =%s\n",host1);
  14964. //DEBUG_INFO("port =%d\n",port);
  14965. //DEBUG_INFO("path1 =%s\n",path1);
  14966. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14967. //ftpFile(host, user, password, port, ftppath, fname);
  14968. //download firmware pthred
  14969. if(port == 0)
  14970. {
  14971. port = 21;
  14972. }
  14973. do
  14974. {
  14975. sleep(1);
  14976. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14977. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14978. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14979. sleep(1);
  14980. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14981. if(!isSuccess)
  14982. {
  14983. //BulldogUtil.sleepMs(interval*1000);
  14984. DEBUG_INFO("Update firmware request and download file fail.\n");
  14985. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14986. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14987. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14988. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14989. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14990. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14991. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14992. }
  14993. else
  14994. {
  14995. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14996. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14997. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14998. }
  14999. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15000. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15001. }
  15002. else
  15003. {
  15004. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15005. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15006. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15007. sleep(1);
  15008. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15009. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15010. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15011. }
  15012. // Verify firmware image signature
  15013. struct stat st;
  15014. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15015. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15016. fclose(fp);
  15017. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15018. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15019. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15020. fclose(fp);
  15021. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15022. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15023. if(st.st_size == 0)
  15024. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15025. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15026. {
  15027. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15028. fp = popen(temp, "r");
  15029. if(fp)
  15030. {
  15031. while(fgets(temp, sizeof(temp), fp) != NULL)
  15032. {
  15033. if(strstr(temp, "Verified OK") != NULL)
  15034. {
  15035. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15036. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15037. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15038. }
  15039. else
  15040. {
  15041. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15042. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15043. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15044. sleep(1);
  15045. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15046. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15047. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15048. sleep(1);
  15049. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15050. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15051. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15052. }
  15053. break;
  15054. }
  15055. }
  15056. pclose(fp);
  15057. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15058. }
  15059. interLock.isUpdateFirmwareGoing = 0;
  15060. pthread_exit(NULL);
  15061. }
  15062. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15063. {
  15064. mtrace();
  15065. int result = PASS;
  15066. pthread_t t;
  15067. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15068. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15069. sendSignedUpdateFirmwareConfirmation(uuid);
  15070. if(!interLock.isUpdateFirmwareGoing)
  15071. {
  15072. interLock.isUpdateFirmwareGoing = 1;
  15073. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15074. sleep(1);
  15075. }
  15076. else
  15077. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15078. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15079. return result;
  15080. }
  15081. int handleUnknownRequest(char *uuid, char *payload)
  15082. {
  15083. mtrace();
  15084. int result = PASS;
  15085. DEBUG_INFO("handleUnknownRequest...\n");
  15086. sendUnknownConfirmation(uuid);
  15087. return result;
  15088. }
  15089. //==========================================
  15090. // Handle server response routine
  15091. //==========================================
  15092. void handleAuthorizeResponse(char *payload, int gun_index)
  15093. {
  15094. mtrace();
  15095. char expiryDatestr[36]={0};
  15096. char parentIdTagstr[21]={0};
  15097. char statusstr[20]={0};
  15098. int expiryDateISNULL=FALSE;
  15099. int parentIdTagISNULL=FALSE;
  15100. DEBUG_INFO("handleAuthorizeResponse...\n");
  15101. json_object *Authorize;
  15102. Authorize = json_tokener_parse(payload);
  15103. if(!is_error(Authorize))
  15104. {
  15105. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15106. {
  15107. // Required data
  15108. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15109. // Optional data
  15110. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15111. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15112. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15113. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15114. }
  15115. }
  15116. json_object_put(Authorize);
  15117. if(expiryDateISNULL == FALSE)
  15118. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15119. if(parentIdTagISNULL == FALSE)
  15120. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15121. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15122. //Update idTag information to authorization cache if supproted
  15123. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15124. {
  15125. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15126. }
  15127. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15128. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15129. authorizeRetryTimes = 0;
  15130. }
  15131. void handleBootNotificationResponse(char *payload, int gun_index)
  15132. {
  15133. mtrace();
  15134. char statusStr[12]={0};
  15135. char currentTimeStr[30]={0};
  15136. int intervalInt = 0;
  15137. DEBUG_INFO("handleBootNotificationResponse...\n");
  15138. json_object *BootNotification;
  15139. BootNotification = json_tokener_parse(payload);
  15140. if(!is_error(BootNotification))
  15141. {
  15142. // Required data
  15143. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15144. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15145. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15146. }
  15147. json_object_put(BootNotification);
  15148. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15149. BootNotificationInterval = intervalInt;
  15150. //write back to ShmOCPP16Data->BootNotification
  15151. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15152. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15153. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15154. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15155. {
  15156. BootNotificationInterval = 0;
  15157. if((intervalInt == 0) || (intervalInt >= 10))
  15158. {
  15159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15160. HeartBeatWaitTime = intervalInt;
  15161. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15162. }
  15163. server_sign = TRUE;
  15164. server_pending =FALSE;
  15165. }
  15166. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15167. {
  15168. server_pending = TRUE;
  15169. }
  15170. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15171. srand(time(NULL));
  15172. refreshStartTimer(&clientTime.Heartbeat);
  15173. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15174. SetOcppConnStatus(TRUE);
  15175. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15176. }
  15177. void handleDataTransferResponse(char *payload, int gun_index)
  15178. {
  15179. json_object *DataTransfer = json_tokener_parse(payload);
  15180. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15181. if(!is_error(DataTransfer))
  15182. {
  15183. // Required data
  15184. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15185. // Optional data
  15186. if(json_object_object_get(DataTransfer, "data") != NULL)
  15187. {
  15188. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15189. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15190. if(!is_error(Data))
  15191. {
  15192. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15193. {
  15194. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15195. {
  15196. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15197. }
  15198. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15199. {
  15200. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15201. {
  15202. 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")));
  15203. }
  15204. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15205. {
  15206. 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")));
  15207. }
  15208. }
  15209. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15210. }
  15211. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15212. {
  15213. if(json_object_object_get(Data, "status") != NULL)
  15214. {
  15215. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15216. }
  15217. if(json_object_object_get(Data, "exiResponse") != NULL)
  15218. {
  15219. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15220. }
  15221. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15222. }
  15223. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15224. {
  15225. if(json_object_object_get(Data, "status") != NULL)
  15226. {
  15227. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15228. }
  15229. if(json_object_object_get(Data, "ocspResult") != NULL)
  15230. {
  15231. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15232. }
  15233. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15234. }
  15235. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15236. {
  15237. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15238. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15239. }
  15240. else
  15241. {
  15242. if(json_object_object_get(Data, "msgId") != NULL)
  15243. {
  15244. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15245. {
  15246. 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")));
  15247. }
  15248. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15249. {
  15250. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15251. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15252. }
  15253. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_GetOccupancyFee") != NULL)
  15254. {
  15255. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15256. {
  15257. sprintf((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15258. if(json_object_object_get(Data, "occupancySN") != NULL)
  15259. sprintf((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancySN, "%s", json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15260. if(json_object_object_get(Data, "startTime") != NULL)
  15261. sprintf((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_startTime, "%s", json_object_get_string(json_object_object_get(Data, "startTime")));
  15262. if(json_object_object_get(Data, "duration") != NULL)
  15263. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_duration = json_object_get_int(json_object_object_get(Data, "duration"));
  15264. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15265. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancyFee = json_object_get_double(json_object_object_get(Data, "occupancyFee"));
  15266. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].GetOccupancyFeeReq = 0;
  15267. }
  15268. else
  15269. {
  15270. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15271. {
  15272. if(ShmOCPP16Data->TcciCustomData.GetOccupancyFee[idx].GetOccupancyFeeReq)
  15273. {
  15274. strcpy((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[idx].response_status, "Rejected");
  15275. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[idx].GetOccupancyFeeReq = 0;
  15276. }
  15277. }
  15278. }
  15279. }
  15280. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15281. {
  15282. if(json_object_object_get(Data, "occupancySN") != NULL)
  15283. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15284. }
  15285. }
  15286. }
  15287. }
  15288. json_object_put(Data);
  15289. }
  15290. }
  15291. json_object_put(DataTransfer);
  15292. }
  15293. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15294. {
  15295. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15296. //struct json_object *obj;
  15297. // obj = json_tokener_parse(payload);
  15298. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15299. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15300. //No fields are defined.
  15301. }
  15302. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15303. {
  15304. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15305. //struct json_object *obj;
  15306. // obj = json_tokener_parse(payload);
  15307. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15308. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15309. //No fields are defined.
  15310. }
  15311. void handleHeartbeatResponse(char *payload, int gun_index)
  15312. {
  15313. mtrace();
  15314. DEBUG_INFO("handleHeartbeatResponse...\n");
  15315. json_object *Heartbeat;
  15316. Heartbeat = json_tokener_parse(payload);
  15317. if(!is_error(Heartbeat))
  15318. {
  15319. // Required data
  15320. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15321. }
  15322. json_object_put(Heartbeat);
  15323. if(FirstHeartBeat == 0)
  15324. {
  15325. FirstHeartBeat = 1;
  15326. DEBUG_INFO("FirstHeartBeat \n");
  15327. }
  15328. HeartBeatWithNOResponse = 0;
  15329. refreshStartTimer(&clientTime.Heartbeat);
  15330. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15331. }
  15332. void handleMeterValuesResponse(char *payload, int gun_index)
  15333. {
  15334. mtrace();
  15335. DEBUG_INFO("handleMeterValuesResponse...\n");
  15336. isQueueSendable = 1;
  15337. }
  15338. void handleStartTransactionResponse(char *payload, int gun_index)
  15339. {
  15340. mtrace();
  15341. //int transactionIdInt = 0;
  15342. FILE *outfile;
  15343. char data[100]={0};
  15344. DEBUG_INFO("handleStartTransactionResponse...\n");
  15345. json_object *StartTransaction;
  15346. StartTransaction = json_tokener_parse(payload);
  15347. if(!is_error(StartTransaction))
  15348. {
  15349. // Required data
  15350. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15351. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15352. // Optional data
  15353. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15354. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15355. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15356. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15357. }
  15358. json_object_put(StartTransaction);
  15359. OCPP_updatePeriodEnergy(gun_index);
  15360. //-----------Start : write to the Queue TransactionId file -----------------//
  15361. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15362. {}
  15363. else
  15364. {
  15365. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15366. if(log == NULL)
  15367. {
  15368. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15369. return ;
  15370. }
  15371. else
  15372. {
  15373. fclose(log);
  15374. }
  15375. }
  15376. // open file for writing
  15377. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15378. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15379. {
  15380. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15381. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15382. fputs(data, outfile);
  15383. fclose (outfile);
  15384. }
  15385. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15386. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15387. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15388. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15389. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15390. isQueueSendable = 1;
  15391. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15392. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15393. }
  15394. void handleStatusNotificationResponse(char *payload, int gun_index)
  15395. {
  15396. mtrace();
  15397. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15398. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15399. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15400. if(gun_index != 99)
  15401. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15402. }
  15403. void handleStopTransactionnResponse(char *payload, int gun_index)
  15404. {
  15405. mtrace();
  15406. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15407. json_object *StopTransaction;
  15408. StopTransaction = json_tokener_parse(payload);
  15409. if(!is_error(StopTransaction))
  15410. {
  15411. // Optional data
  15412. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15413. {
  15414. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15415. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15416. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15417. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15418. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15419. }
  15420. }
  15421. json_object_put(StopTransaction);
  15422. isQueueSendable = 1;
  15423. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15424. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15425. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15426. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15427. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15428. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15429. }
  15430. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15431. {
  15432. mtrace();
  15433. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15434. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15435. }
  15436. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15437. {
  15438. mtrace();
  15439. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15440. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15441. }
  15442. void handleSignCertificateResponse(char *payload, int gun_index)
  15443. {
  15444. mtrace();
  15445. DEBUG_INFO("handleSignCertificateResponse...\n");
  15446. json_object *SignCertificate;
  15447. SignCertificate = json_tokener_parse(payload);
  15448. if(!is_error(SignCertificate))
  15449. {
  15450. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15451. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15452. }
  15453. json_object_put(SignCertificate);
  15454. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15455. }
  15456. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15457. {
  15458. mtrace();
  15459. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15460. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15461. }
  15462. //==========================================
  15463. // Handle Error routine
  15464. //==========================================
  15465. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15466. {
  15467. mtrace();
  15468. #ifdef SystemLogMessage
  15469. DEBUG_INFO("errorCode: %s\n", errorCode);
  15470. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15471. DEBUG_INFO("errorDetails: %s\n", payload);
  15472. #endif
  15473. }
  15474. //===============================================
  15475. // Common routine
  15476. //===============================================
  15477. int initialConfigurationTable(void)
  15478. {
  15479. //clock_t start_t, end_t, total_t;
  15480. FILE *fp;
  15481. FILE *outfile;
  15482. char str[512]={0};
  15483. char sstr[256]={0};
  15484. int c = 0;
  15485. char *loc;
  15486. int confVersion = 23;
  15487. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15488. //start_t = clock();
  15489. //printf("Starting of the program, start_t = %ld\n", start_t);
  15490. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15491. // Check configuration file size is correct
  15492. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15493. {
  15494. struct stat st;
  15495. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15496. if(st.st_size < 3100)
  15497. {
  15498. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15499. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15500. }
  15501. }
  15502. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15503. {
  15504. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15505. if(outfile == NULL)
  15506. {
  15507. DEBUG_INFO("Error opening file\n");
  15508. return FALSE;
  15509. }
  15510. /*Core Profile*/
  15511. //AllowOfflineTxForUnknownId
  15512. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15516. //AuthorizationCacheEnabled
  15517. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15521. //AuthorizeRemoteTxRequests
  15522. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15526. //BlinkRepeat
  15527. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15531. //ClockAlignedDataInterval
  15532. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15536. //ConnectionTimeOut
  15537. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15539. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15541. else
  15542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15544. //GetConfigurationMaxKeys
  15545. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15549. // HeartbeatInterval
  15550. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15554. // LightIntensity
  15555. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15559. // LocalAuthorizeOffline
  15560. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15564. // LocalPreAuthorize
  15565. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15569. // MaxEnergyOnInvalidId
  15570. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15574. // MeterValuesAlignedData
  15575. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15578. 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" );
  15579. else
  15580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15582. // MeterValuesAlignedDataMaxLength
  15583. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15585. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15587. else
  15588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15590. // MeterValuesSampledData
  15591. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15593. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15594. 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" );
  15595. else
  15596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15598. // MeterValuesSampledDataMaxLength
  15599. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15601. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15603. else
  15604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15606. // MeterValueSampleInterval
  15607. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15611. // MinimumStatusDuration
  15612. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15615. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15617. // NumberOfConnectors
  15618. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15620. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15621. {
  15622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15623. }
  15624. else
  15625. {
  15626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15627. }
  15628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15629. // ResetRetries
  15630. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15634. // ConnectorPhaseRotation
  15635. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15639. // ConnectorPhaseRotationMaxLength
  15640. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15644. // StopTransactionOnEVSideDisconnect
  15645. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15649. // StopTransactionOnInvalidId
  15650. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15654. // StopTxnAlignedData
  15655. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15659. // StopTxnAlignedDataMaxLength
  15660. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15663. {
  15664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 8);
  15665. }
  15666. else
  15667. {
  15668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 10);
  15669. }
  15670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15671. // StopTxnSampledData
  15672. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15676. // StopTxnSampledDataMaxLength
  15677. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15680. {
  15681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 8);
  15682. }
  15683. else
  15684. {
  15685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 10);
  15686. }
  15687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15688. // SupportedFeatureProfiles
  15689. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15693. // SupportedFeatureProfilesMaxLength
  15694. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15698. // TransactionMessageAttempts
  15699. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15702. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15704. // TransactionMessageRetryInterval
  15705. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15708. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15710. // UnlockConnectorOnEVSideDisconnect
  15711. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15715. // WebSocketPingInterval
  15716. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15720. // QueueOffLineMeterValues
  15721. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15725. // AuthorizationKey
  15726. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15730. // SecurityProfile
  15731. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15735. // DefaultPrice
  15736. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15740. // CustomDisplayCostAndPrice
  15741. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15745. // CustomIdleFeeAfterStop
  15746. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15750. // TimeOffset
  15751. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15755. // NextTimeOffsetTransitionDateTime
  15756. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15760. // TimeOffsetNextTransition
  15761. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15765. // SystemUptimeSec
  15766. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15770. // FreeVend
  15771. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15775. // FreeVendIdtag
  15776. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15780. // OcppServer
  15781. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15783. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15785. // MaintainServer
  15786. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15788. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15790. // StatusNotificationPeriodically
  15791. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15795. // StatusNotificationInterval
  15796. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15800. // PreAuthAmount
  15801. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15805. // isEnableLocalPowerSharing
  15806. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15810. // PowerSharingServerIP
  15811. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15813. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15815. // EVCCID_PREFIX
  15816. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15820. // OffLineMaxChargingPower
  15821. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15825. // Configuration Version
  15826. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15830. // Charging profile refresh interval
  15831. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15835. // CpoName
  15836. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15840. // Ocpp Software certificated version
  15841. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15845. //* Local Auth List Management Profile*/
  15846. #if 0
  15847. //For OCTT Test Case
  15848. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15851. #endif
  15852. #if 1
  15853. //LocalAuthListEnabled
  15854. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15858. #endif
  15859. //LocalAuthListMaxLength
  15860. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15864. //SendLocalListMaxLength
  15865. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15869. //ReserveConnectorZeroSupported
  15870. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15874. //* Smart Charging Profile */
  15875. //ChargeProfileMaxStackLevel
  15876. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15880. // ChargingScheduleAllowedChargingRateUnit
  15881. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15885. // ChargingScheduleMaxPeriods
  15886. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15890. // ConnectorSwitch3to1PhaseSupported
  15891. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15895. // MaxChargingProfilesInstalled
  15896. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15900. fclose(outfile);
  15901. }
  15902. else
  15903. {
  15904. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15905. char keystr[60]={0};
  15906. char readonlystr[10]={0};
  15907. char valuestr[256]={0};
  15908. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15909. if(fp == NULL) {
  15910. DEBUG_INFO("Error opening file");
  15911. return FALSE;
  15912. }
  15913. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15914. {
  15915. //DEBUG_INFO("Get Configuration \n");
  15916. if(strlen(str) > 0)
  15917. {
  15918. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15919. //*************************key*********************************/
  15920. if(strstr(str, "key") != NULL)
  15921. {
  15922. loc = strstr(str, "key");
  15923. c = 0;
  15924. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15925. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15926. {
  15927. sstr[c] = loc[strlen("key")+3+c];
  15928. c++;
  15929. }
  15930. sstr[c] = '\0';
  15931. strcpy(keystr,sstr);
  15932. }
  15933. //*************************readonly*********************************/
  15934. if(strstr(str, "readonly") != NULL)
  15935. {
  15936. loc = strstr(str, "readonly");
  15937. c = 0;
  15938. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15939. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  15940. {
  15941. sstr[c] = loc[strlen("readonly")+2+c];
  15942. c++;
  15943. }
  15944. sstr[c] = '\0';
  15945. strcpy(readonlystr,sstr);
  15946. }
  15947. //*************************value*********************************/
  15948. if(strstr(str, "value") != NULL)
  15949. {
  15950. loc = strstr(str, "value");
  15951. c = 0;
  15952. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15953. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15954. {
  15955. sstr[c] = loc[strlen("value")+3+c];
  15956. c++;
  15957. }
  15958. sstr[c] = '\0';
  15959. strcpy(valuestr,sstr);
  15960. }
  15961. // DEBUG_INFO("keystr=%s\n",keystr);
  15962. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15963. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15964. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15965. {
  15966. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15967. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15969. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15970. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15971. }
  15972. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15973. {
  15974. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15975. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  15977. }
  15978. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  15979. {
  15980. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  15982. }
  15983. if(strcmp(keystr, "BlinkRepeat") == 0)
  15984. {
  15985. //Charger.BlinkRepeat = Integer.parseInt(value);
  15986. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  15988. }
  15989. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  15990. {
  15991. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  15993. }
  15994. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  15995. {
  15996. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  15998. }
  15999. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16000. {
  16001. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16003. }
  16004. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16005. {
  16006. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16008. HeartBeatWaitTime = atoi(valuestr);
  16009. }
  16010. if(strcmp(keystr, "LightIntensity") == 0)
  16011. {
  16012. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16014. }
  16015. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16016. {
  16017. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16019. }
  16020. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16021. {
  16022. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16024. }
  16025. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16026. {
  16027. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16029. }
  16030. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16031. {
  16032. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16034. }
  16035. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16036. {
  16037. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16039. }
  16040. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16041. {
  16042. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16044. }
  16045. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16046. {
  16047. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16049. }
  16050. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16051. {
  16052. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16054. }
  16055. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16056. {
  16057. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16059. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16060. }
  16061. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16062. {
  16063. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16065. }
  16066. if(strcmp(keystr, "ResetRetries") == 0)
  16067. {
  16068. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16070. }
  16071. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16072. {
  16073. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16075. }
  16076. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16077. {
  16078. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16080. }
  16081. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16082. {
  16083. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16085. }
  16086. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16087. {
  16088. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16090. }
  16091. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16092. {
  16093. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16095. }
  16096. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16097. {
  16098. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16100. }
  16101. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16102. {
  16103. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16105. }
  16106. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16107. {
  16108. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16110. }
  16111. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16112. {
  16113. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16115. }
  16116. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16117. {
  16118. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16120. }
  16121. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16122. {
  16123. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16125. TransactionMessageAttemptsValue = atoi(valuestr);
  16126. }
  16127. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16128. {
  16129. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16131. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16132. }
  16133. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16134. {
  16135. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16137. }
  16138. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16139. {
  16140. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16142. }
  16143. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16144. {
  16145. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16147. }
  16148. if(strcmp(keystr, "AuthorizationKey") == 0)
  16149. {
  16150. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16151. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16153. }
  16154. if(strcmp(keystr, "SecurityProfile") == 0)
  16155. {
  16156. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16158. }
  16159. if(strcmp(keystr, "DefaultPrice") == 0)
  16160. {
  16161. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16163. }
  16164. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16165. {
  16166. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16168. }
  16169. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16170. {
  16171. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16173. }
  16174. if(strcmp(keystr, "TimeOffset") == 0)
  16175. {
  16176. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16178. }
  16179. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16180. {
  16181. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16183. }
  16184. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16185. {
  16186. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16188. }
  16189. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16190. {
  16191. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16193. }
  16194. if(strcmp(keystr, "FreeVend") == 0)
  16195. {
  16196. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16198. }
  16199. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16200. {
  16201. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16203. }
  16204. if(strcmp(keystr, "OcppServer") == 0)
  16205. {
  16206. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16207. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16208. }
  16209. if(strcmp(keystr, "MaintainServer") == 0)
  16210. {
  16211. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16212. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16213. }
  16214. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16215. {
  16216. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16218. }
  16219. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16220. {
  16221. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16223. }
  16224. if(strcmp(keystr, "PreAuthAmount") == 0)
  16225. {
  16226. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16228. }
  16229. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16230. {
  16231. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16233. }
  16234. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16235. {
  16236. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16237. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16238. }
  16239. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16240. {
  16241. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16243. }
  16244. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16245. {
  16246. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16248. }
  16249. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16250. {
  16251. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16253. }
  16254. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16255. {
  16256. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16258. }
  16259. if(strcmp(keystr, "CpoName") == 0)
  16260. {
  16261. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16263. }
  16264. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16265. {
  16266. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16268. }
  16269. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16270. {
  16271. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16273. }
  16274. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16275. {
  16276. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16278. }
  16279. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16280. {
  16281. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16283. }
  16284. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16285. {
  16286. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16288. }
  16289. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16290. {
  16291. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16293. }
  16294. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16295. {
  16296. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16298. }
  16299. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16300. {
  16301. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16303. }
  16304. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16305. {
  16306. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16308. }
  16309. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16310. {
  16311. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16313. }
  16314. }
  16315. }
  16316. fclose(fp);
  16317. }
  16318. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16319. {
  16320. return PASS;
  16321. }
  16322. else
  16323. {
  16324. return FAIL;
  16325. }
  16326. }
  16327. void StoreConfigurationTable(void)
  16328. {
  16329. FILE *outfile;
  16330. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16331. if(outfile == NULL)
  16332. {
  16333. DEBUG_INFO("Error opening file");
  16334. return ;
  16335. }
  16336. /*Core Profile*/
  16337. //AllowOfflineTxForUnknownId
  16338. /*
  16339. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16340. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16343. */
  16344. //DEBUG_INFO("data=%s\n",data);
  16345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16346. //AuthorizationCacheEnabled
  16347. /*
  16348. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16351. */
  16352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16353. //AuthorizeRemoteTxRequests
  16354. /*
  16355. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16358. */
  16359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16360. //BlinkRepeat
  16361. /*
  16362. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16365. */
  16366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16367. //ClockAlignedDataInterval
  16368. /*
  16369. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16372. */
  16373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16374. //ConnectionTimeOut
  16375. /*
  16376. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16379. */
  16380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16381. //GetConfigurationMaxKeys
  16382. /*
  16383. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16386. */
  16387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16388. // HeartbeatInterval
  16389. /*
  16390. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16393. */
  16394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16395. // LightIntensity
  16396. /*
  16397. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16400. */
  16401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16402. // LocalAuthorizeOffline
  16403. /*
  16404. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16407. */
  16408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16409. // LocalPreAuthorize
  16410. /*
  16411. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16414. */
  16415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16416. // MaxEnergyOnInvalidId
  16417. /*
  16418. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16421. */
  16422. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16424. // MeterValuesAlignedData
  16425. /*
  16426. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16429. */
  16430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16431. // MeterValuesAlignedDataMaxLength
  16432. /*
  16433. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16436. */
  16437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16438. // MeterValuesSampledData
  16439. /*
  16440. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16443. */
  16444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16445. // MeterValuesSampledDataMaxLength
  16446. /*
  16447. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16450. */
  16451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16452. // MeterValueSampleInterval
  16453. /*
  16454. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16457. */
  16458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16459. // MinimumStatusDuration
  16460. /*
  16461. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16464. */
  16465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16466. // NumberOfConnectors
  16467. /*
  16468. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16470. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16471. {
  16472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16473. }
  16474. else
  16475. {
  16476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16477. }
  16478. */
  16479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16480. // ResetRetries
  16481. /*
  16482. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16485. */
  16486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16487. // ConnectorPhaseRotation
  16488. /*
  16489. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16492. */
  16493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16494. // ConnectorPhaseRotationMaxLength
  16495. /*
  16496. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16499. */
  16500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16501. // StopTransactionOnEVSideDisconnect
  16502. /*
  16503. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16506. */
  16507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16508. // StopTransactionOnInvalidId
  16509. /*
  16510. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16513. */
  16514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16515. // StopTxnAlignedData
  16516. /*
  16517. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16520. */
  16521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16522. // StopTxnAlignedDataMaxLength
  16523. /*
  16524. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16527. */
  16528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16529. // StopTxnSampledData
  16530. /*
  16531. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16534. */
  16535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16536. // StopTxnSampledDataMaxLength
  16537. /*
  16538. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16541. */
  16542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16543. // SupportedFeatureProfiles
  16544. /*
  16545. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16548. */
  16549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16550. // SupportedFeatureProfilesMaxLength
  16551. /*
  16552. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16555. */
  16556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16557. // TransactionMessageAttempts
  16558. /*
  16559. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16562. */
  16563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16564. // TransactionMessageRetryInterval
  16565. /*
  16566. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16569. */
  16570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16571. // UnlockConnectorOnEVSideDisconnect
  16572. /*
  16573. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16576. */
  16577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16578. // WebSocketPingInterval
  16579. /*
  16580. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16583. */
  16584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16585. // QueueOffLineMeterValues
  16586. /*
  16587. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16590. */
  16591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16592. // AuthorizationKey
  16593. /*
  16594. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16597. */
  16598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16599. // SecurityProfile
  16600. /*
  16601. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16604. */
  16605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16606. // DefaultPrice
  16607. /*
  16608. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16611. */
  16612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16613. // CustomDisplayCostAndPrice
  16614. /*
  16615. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16618. */
  16619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16620. // CustomIdleFeeAfterStop
  16621. /*
  16622. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16625. */
  16626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16627. // TimeOffset
  16628. /*
  16629. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16632. */
  16633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16634. // NextTimeOffsetTransitionDateTime
  16635. /*
  16636. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16639. */
  16640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16641. // TimeOffsetNextTransition
  16642. /*
  16643. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16646. */
  16647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16648. // SystemUptimeSec
  16649. /*
  16650. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16653. */
  16654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16655. // FreeVend
  16656. /*
  16657. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16660. */
  16661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16662. // FreeVendIdtag
  16663. /*
  16664. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16667. */
  16668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16669. // OcppServer
  16670. /*
  16671. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16674. */
  16675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16676. // MaintainServer
  16677. /*
  16678. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16681. */
  16682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16683. // StatusNotificationPeriodically
  16684. /*
  16685. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16688. */
  16689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16690. // StatusNotificationInterval
  16691. /*
  16692. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16695. */
  16696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16697. // PreAuthAmount
  16698. /*
  16699. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16702. */
  16703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16704. // isEnableLocalPowerSharing
  16705. /*
  16706. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16709. */
  16710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16711. // PowerSharingServerIP
  16712. /*
  16713. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16716. */
  16717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16718. // EVCCID_PREFIX
  16719. /*
  16720. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16723. */
  16724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16725. // OffLineMaxChargingPower
  16726. /*
  16727. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16730. */
  16731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16732. // ConfigurationVersion
  16733. /*
  16734. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16737. */
  16738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16739. // CharingProfileRefreshInterval
  16740. /*
  16741. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16744. */
  16745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16746. // CpoName
  16747. /*
  16748. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16751. */
  16752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16753. // OcppSoftwareVersion
  16754. /*
  16755. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16758. */
  16759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16760. //* Local Auth List Management Profile*/
  16761. //LocalAuthListEnabled
  16762. /*
  16763. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16766. */
  16767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16768. //LocalAuthListMaxLength
  16769. /*
  16770. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16773. */
  16774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16775. //SendLocalListMaxLength
  16776. /*
  16777. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16780. */
  16781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16782. //ReserveConnectorZeroSupported
  16783. /*
  16784. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16787. */
  16788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16789. //* Smart Charging Profile */
  16790. //ChargeProfileMaxStackLevel
  16791. /*
  16792. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16795. */
  16796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16797. // ChargingScheduleAllowedChargingRateUnit
  16798. /*
  16799. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16802. */
  16803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16804. // ChargingScheduleMaxPeriods
  16805. /*
  16806. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16809. */
  16810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16811. // ConnectorSwitch3to1PhaseSupported
  16812. /*
  16813. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16816. */
  16817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16818. // MaxChargingProfilesInstalled
  16819. /*
  16820. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16823. */
  16824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16825. fclose(outfile);
  16826. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16827. }
  16828. void getKeyValue(char *keyReq)
  16829. {
  16830. int isEmpty = FALSE;
  16831. int isKnowKey = FALSE;
  16832. DEBUG_INFO("keyReq = %s\n", keyReq);
  16833. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16834. isEmpty = TRUE;
  16835. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16836. {
  16837. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16839. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16840. {
  16841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16842. }
  16843. else
  16844. {
  16845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16846. }
  16847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16848. isKnowKey = TRUE;
  16849. }
  16850. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16851. {
  16852. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16854. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16855. {
  16856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16857. }
  16858. else
  16859. {
  16860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16861. }
  16862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16863. isKnowKey = TRUE;
  16864. }
  16865. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16866. {
  16867. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16869. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16870. {
  16871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16872. }
  16873. else
  16874. {
  16875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16876. }
  16877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16878. isKnowKey = TRUE;
  16879. }
  16880. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16881. {
  16882. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16885. {
  16886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16887. }
  16888. else
  16889. {
  16890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16891. }
  16892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16893. isKnowKey = TRUE;
  16894. }
  16895. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16896. {
  16897. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16899. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16900. {
  16901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16902. }
  16903. else
  16904. {
  16905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16906. }
  16907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16908. isKnowKey = TRUE;
  16909. }
  16910. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16911. {
  16912. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16914. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16915. {
  16916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  16917. }
  16918. else
  16919. {
  16920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  16921. }
  16922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  16923. isKnowKey = TRUE;
  16924. }
  16925. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  16926. {
  16927. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  16928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  16929. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16930. {
  16931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  16932. }
  16933. else
  16934. {
  16935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  16936. }
  16937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  16938. isKnowKey = TRUE;
  16939. }
  16940. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  16941. {
  16942. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  16943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  16944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16945. {
  16946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  16947. }
  16948. else
  16949. {
  16950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  16951. }
  16952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  16953. isKnowKey = TRUE;
  16954. }
  16955. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  16956. {
  16957. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  16958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  16959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16960. {
  16961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  16962. }
  16963. else
  16964. {
  16965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  16966. }
  16967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  16968. isKnowKey = TRUE;
  16969. }
  16970. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  16971. {
  16972. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  16973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  16974. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16975. {
  16976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  16977. }
  16978. else
  16979. {
  16980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  16981. }
  16982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  16983. isKnowKey = TRUE;
  16984. }
  16985. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  16986. {
  16987. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  16988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  16989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16990. {
  16991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  16992. }
  16993. else
  16994. {
  16995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  16996. }
  16997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  16998. isKnowKey = TRUE;
  16999. }
  17000. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17001. {
  17002. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17005. {
  17006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17007. }
  17008. else
  17009. {
  17010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17011. }
  17012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17013. isKnowKey = TRUE;
  17014. }
  17015. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17016. {
  17017. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17020. {
  17021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17022. }
  17023. else
  17024. {
  17025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17026. }
  17027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17028. isKnowKey = TRUE;
  17029. }
  17030. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17031. {
  17032. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17035. {
  17036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17037. }
  17038. else
  17039. {
  17040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17041. }
  17042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17043. isKnowKey = TRUE;
  17044. }
  17045. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17046. {
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17050. {
  17051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17052. }
  17053. else
  17054. {
  17055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17056. }
  17057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17058. isKnowKey = TRUE;
  17059. }
  17060. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17061. {
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17065. {
  17066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17067. }
  17068. else
  17069. {
  17070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17071. }
  17072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17073. isKnowKey = TRUE;
  17074. }
  17075. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17076. {
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17080. {
  17081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17082. }
  17083. else
  17084. {
  17085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17086. }
  17087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17088. isKnowKey = TRUE;
  17089. }
  17090. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17091. {
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17095. {
  17096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17097. }
  17098. else
  17099. {
  17100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17101. }
  17102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17103. isKnowKey = TRUE;
  17104. }
  17105. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17106. {
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17110. {
  17111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17112. }
  17113. else
  17114. {
  17115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17116. }
  17117. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17119. isKnowKey = TRUE;
  17120. }
  17121. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17122. {
  17123. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17126. {
  17127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17128. }
  17129. else
  17130. {
  17131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17132. }
  17133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17134. isKnowKey = TRUE;
  17135. }
  17136. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17137. {
  17138. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17141. {
  17142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17143. }
  17144. else
  17145. {
  17146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17147. }
  17148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17149. isKnowKey = TRUE;
  17150. }
  17151. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17152. {
  17153. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17156. {
  17157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17158. }
  17159. else
  17160. {
  17161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17162. }
  17163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17164. isKnowKey = TRUE;
  17165. }
  17166. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17167. {
  17168. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17171. {
  17172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17173. }
  17174. else
  17175. {
  17176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17177. }
  17178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17179. isKnowKey = TRUE;
  17180. }
  17181. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17182. {
  17183. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17186. {
  17187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17188. }
  17189. else
  17190. {
  17191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17192. }
  17193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17194. isKnowKey = TRUE;
  17195. }
  17196. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17197. {
  17198. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17200. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17201. {
  17202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17203. }
  17204. else
  17205. {
  17206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17207. }
  17208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17209. isKnowKey = TRUE;
  17210. }
  17211. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17212. {
  17213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17216. {
  17217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17218. }
  17219. else
  17220. {
  17221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17222. }
  17223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17224. isKnowKey = TRUE;
  17225. }
  17226. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17227. {
  17228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17231. {
  17232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17233. }
  17234. else
  17235. {
  17236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17237. }
  17238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17239. isKnowKey = TRUE;
  17240. }
  17241. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17242. {
  17243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17246. {
  17247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17248. }
  17249. else
  17250. {
  17251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17252. }
  17253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17254. isKnowKey = TRUE;
  17255. }
  17256. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17257. {
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17261. {
  17262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17263. }
  17264. else
  17265. {
  17266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17267. }
  17268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17269. isKnowKey = TRUE;
  17270. }
  17271. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17272. {
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17276. {
  17277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17278. }
  17279. else
  17280. {
  17281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17282. }
  17283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17284. isKnowKey = TRUE;
  17285. }
  17286. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17287. {
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17291. {
  17292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17293. }
  17294. else
  17295. {
  17296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17297. }
  17298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17299. isKnowKey = TRUE;
  17300. }
  17301. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17302. {
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17306. {
  17307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17308. }
  17309. else
  17310. {
  17311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17312. }
  17313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17314. isKnowKey = TRUE;
  17315. }
  17316. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17317. {
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17321. {
  17322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17323. }
  17324. else
  17325. {
  17326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17327. }
  17328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17329. isKnowKey = TRUE;
  17330. }
  17331. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17332. {
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17336. {
  17337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17338. }
  17339. else
  17340. {
  17341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17342. }
  17343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17344. isKnowKey = TRUE;
  17345. }
  17346. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17347. {
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17351. {
  17352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17353. }
  17354. else
  17355. {
  17356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17357. }
  17358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17359. isKnowKey = TRUE;
  17360. }
  17361. /*
  17362. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17363. {
  17364. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17367. {
  17368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17369. }
  17370. else
  17371. {
  17372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17373. }
  17374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17375. isKnowKey = TRUE;
  17376. }*/
  17377. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17378. {
  17379. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17382. {
  17383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17384. }
  17385. else
  17386. {
  17387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17388. }
  17389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17390. isKnowKey = TRUE;
  17391. }
  17392. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17393. {
  17394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17397. {
  17398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17399. }
  17400. else
  17401. {
  17402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17403. }
  17404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17405. isKnowKey = TRUE;
  17406. }
  17407. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17408. {
  17409. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17412. {
  17413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17414. }
  17415. else
  17416. {
  17417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17418. }
  17419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17420. isKnowKey = TRUE;
  17421. }
  17422. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17423. {
  17424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17427. {
  17428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17429. }
  17430. else
  17431. {
  17432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17433. }
  17434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17435. isKnowKey = TRUE;
  17436. }
  17437. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17438. {
  17439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17442. {
  17443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17444. }
  17445. else
  17446. {
  17447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17448. }
  17449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17450. isKnowKey = TRUE;
  17451. }
  17452. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17453. {
  17454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17457. {
  17458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17459. }
  17460. else
  17461. {
  17462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17463. }
  17464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17465. isKnowKey = TRUE;
  17466. }
  17467. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17468. {
  17469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17472. {
  17473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17474. }
  17475. else
  17476. {
  17477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17478. }
  17479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17480. isKnowKey = TRUE;
  17481. }
  17482. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17483. {
  17484. struct sysinfo s_info;
  17485. int error = sysinfo(&s_info);
  17486. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17489. {
  17490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17491. }
  17492. else
  17493. {
  17494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17495. }
  17496. if(error != 0)
  17497. {
  17498. DEBUG_WARN("System uptime get error: %d\n", error);
  17499. }
  17500. else
  17501. {
  17502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17503. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17504. }
  17505. isKnowKey = TRUE;
  17506. }
  17507. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17508. {
  17509. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17512. {
  17513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17514. }
  17515. else
  17516. {
  17517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17518. }
  17519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17520. isKnowKey = TRUE;
  17521. }
  17522. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17523. {
  17524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17527. {
  17528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17529. }
  17530. else
  17531. {
  17532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17533. }
  17534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17535. isKnowKey = TRUE;
  17536. }
  17537. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17538. {
  17539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17542. {
  17543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17544. }
  17545. else
  17546. {
  17547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17548. }
  17549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17550. isKnowKey = TRUE;
  17551. }
  17552. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17553. {
  17554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17557. {
  17558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17559. }
  17560. else
  17561. {
  17562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17563. }
  17564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17565. isKnowKey = TRUE;
  17566. }
  17567. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17568. {
  17569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17572. {
  17573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17574. }
  17575. else
  17576. {
  17577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17578. }
  17579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17580. isKnowKey = TRUE;
  17581. }
  17582. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17583. {
  17584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17587. {
  17588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17589. }
  17590. else
  17591. {
  17592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17593. }
  17594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17595. isKnowKey = TRUE;
  17596. }
  17597. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17598. {
  17599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17602. {
  17603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17604. }
  17605. else
  17606. {
  17607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17608. }
  17609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17610. isKnowKey = TRUE;
  17611. }
  17612. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17613. {
  17614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17617. {
  17618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17619. }
  17620. else
  17621. {
  17622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17623. }
  17624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17625. isKnowKey = TRUE;
  17626. }
  17627. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17628. {
  17629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17632. {
  17633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17634. }
  17635. else
  17636. {
  17637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17638. }
  17639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17640. isKnowKey = TRUE;
  17641. }
  17642. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17643. {
  17644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17647. {
  17648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17649. }
  17650. else
  17651. {
  17652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17653. }
  17654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17655. isKnowKey = TRUE;
  17656. }
  17657. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17658. {
  17659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17662. {
  17663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17664. }
  17665. else
  17666. {
  17667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17668. }
  17669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17670. isKnowKey = TRUE;
  17671. }
  17672. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17673. {
  17674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17677. {
  17678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17679. }
  17680. else
  17681. {
  17682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17683. }
  17684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17685. isKnowKey = TRUE;
  17686. }
  17687. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17688. {
  17689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17692. {
  17693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17694. }
  17695. else
  17696. {
  17697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17698. }
  17699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17700. isKnowKey = TRUE;
  17701. }
  17702. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17703. {
  17704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17707. {
  17708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17709. }
  17710. else
  17711. {
  17712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17713. }
  17714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17715. isKnowKey = TRUE;
  17716. }
  17717. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17718. {
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17722. {
  17723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17724. }
  17725. else
  17726. {
  17727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17728. }
  17729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17730. isKnowKey = TRUE;
  17731. }
  17732. #if 1
  17733. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17734. {
  17735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17737. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17738. {
  17739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17740. }
  17741. else
  17742. {
  17743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17744. }
  17745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17746. isKnowKey = TRUE;
  17747. }
  17748. #endif
  17749. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17750. {
  17751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17753. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17754. {
  17755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17756. }
  17757. else
  17758. {
  17759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17760. }
  17761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17762. isKnowKey = TRUE;
  17763. }
  17764. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17765. {
  17766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17768. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17769. {
  17770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17771. }
  17772. else
  17773. {
  17774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17775. }
  17776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17777. isKnowKey = TRUE;
  17778. }
  17779. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17780. {
  17781. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17783. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17784. {
  17785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17786. }
  17787. else
  17788. {
  17789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17790. }
  17791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17792. isKnowKey = TRUE;
  17793. }
  17794. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17795. {
  17796. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17798. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17799. {
  17800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17801. }
  17802. else
  17803. {
  17804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17805. }
  17806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17807. isKnowKey = TRUE;
  17808. }
  17809. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17810. {
  17811. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17813. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17814. {
  17815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17816. }
  17817. else
  17818. {
  17819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17820. }
  17821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17822. isKnowKey = TRUE;
  17823. }
  17824. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17825. {
  17826. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17828. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17829. {
  17830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17831. }
  17832. else
  17833. {
  17834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17835. }
  17836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17837. isKnowKey = TRUE;
  17838. }
  17839. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17840. {
  17841. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17843. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17844. {
  17845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17846. }
  17847. else
  17848. {
  17849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17850. }
  17851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17852. isKnowKey = TRUE;
  17853. }
  17854. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17855. {
  17856. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17858. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17859. {
  17860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17861. }
  17862. else
  17863. {
  17864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17865. }
  17866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17867. isKnowKey = TRUE;
  17868. }
  17869. //=========================================================
  17870. if(!isEmpty && !isKnowKey)
  17871. {
  17872. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17873. strcpy(unknownkey[UnknownKeynum], keyReq);
  17874. UnknownKeynum = UnknownKeynum + 1;
  17875. }
  17876. }
  17877. void processUnkownKey(void)
  17878. {
  17879. DEBUG_INFO("processUnkownKey...\n");
  17880. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17881. for(int index=0; index < UnknownKeynum; index++)
  17882. {
  17883. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17884. {
  17885. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17886. }
  17887. }
  17888. }
  17889. int setKeyValue(char *key, char *value)
  17890. {
  17891. int isSuccess = NotSupported;
  17892. int check_ascii=0;
  17893. char str[501]={0};
  17894. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17895. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17896. {
  17897. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17899. {
  17900. strcpy(str, (const char*)value);
  17901. for(int i = 0; str[i]; i++){
  17902. str[i] = tolower(str[i]);
  17903. }
  17904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17905. isSuccess = ConfigurationStatus_Accepted;
  17906. }
  17907. else
  17908. {
  17909. isSuccess = ConfigurationStatus_Rejected;
  17910. }
  17911. }
  17912. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  17913. {
  17914. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  17915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17916. {
  17917. strcpy(str, (const char*)value);
  17918. for(int i = 0; str[i]; i++){
  17919. str[i] = tolower(str[i]);
  17920. }
  17921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17922. isSuccess = ConfigurationStatus_Accepted;
  17923. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  17924. }
  17925. else
  17926. {
  17927. isSuccess = ConfigurationStatus_Rejected;
  17928. }
  17929. }
  17930. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  17931. {
  17932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17933. {
  17934. strcpy(str, (const char*)value);
  17935. for(int i = 0; str[i]; i++)
  17936. {
  17937. str[i] = tolower(str[i]);
  17938. }
  17939. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  17940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17941. isSuccess = ConfigurationStatus_Accepted;
  17942. }
  17943. else
  17944. {
  17945. isSuccess = ConfigurationStatus_Rejected;
  17946. }
  17947. }
  17948. if(strcmp(key, "BlinkRepeat") == 0)
  17949. {
  17950. //Charger.BlinkRepeat = Integer.parseInt(value);
  17951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17952. {
  17953. check_ascii = value[0];
  17954. if( (check_ascii < 48) || (check_ascii > 57) )
  17955. {
  17956. isSuccess = ConfigurationStatus_Rejected;
  17957. }
  17958. else
  17959. {
  17960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  17961. isSuccess = ConfigurationStatus_Accepted;
  17962. }
  17963. }
  17964. else
  17965. {
  17966. isSuccess = ConfigurationStatus_Rejected;
  17967. }
  17968. }
  17969. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  17970. {
  17971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17972. {
  17973. check_ascii = value[0];
  17974. if( (check_ascii < 48) || (check_ascii > 57) )
  17975. {
  17976. isSuccess = ConfigurationStatus_Rejected;
  17977. }
  17978. else
  17979. {
  17980. if((atoi(value) == 0) || (atoi(value) >= 5))
  17981. {
  17982. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  17983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  17984. isSuccess = ConfigurationStatus_Accepted;
  17985. }
  17986. else
  17987. isSuccess = ConfigurationStatus_Rejected;
  17988. }
  17989. }
  17990. else
  17991. {
  17992. isSuccess = ConfigurationStatus_Rejected;
  17993. }
  17994. }
  17995. if(strcmp(key, "ConnectionTimeOut") == 0 )
  17996. {
  17997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17998. {
  17999. check_ascii = value[0];
  18000. if( (check_ascii < 48) || (check_ascii > 57) )
  18001. {
  18002. isSuccess = ConfigurationStatus_Rejected;
  18003. }
  18004. else
  18005. {
  18006. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18008. isSuccess = ConfigurationStatus_Accepted;
  18009. }
  18010. }
  18011. else
  18012. {
  18013. isSuccess = ConfigurationStatus_Rejected;
  18014. }
  18015. }
  18016. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18017. {
  18018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18019. {
  18020. check_ascii = value[0];
  18021. if( (check_ascii < 48) || (check_ascii > 57) )
  18022. {
  18023. isSuccess = ConfigurationStatus_Rejected;
  18024. }
  18025. else
  18026. {
  18027. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18029. isSuccess = ConfigurationStatus_Accepted;
  18030. }
  18031. }
  18032. else
  18033. {
  18034. isSuccess = ConfigurationStatus_Rejected;
  18035. }
  18036. }
  18037. if(strcmp(key, "HeartbeatInterval") == 0)
  18038. {
  18039. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18040. {
  18041. check_ascii = value[0];
  18042. if( (check_ascii < 48) || (check_ascii > 57) )
  18043. {
  18044. isSuccess = ConfigurationStatus_Rejected;
  18045. }
  18046. else
  18047. {
  18048. if((atoi(value) == 0) || (atoi(value) >= 10))
  18049. {
  18050. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18052. HeartBeatWaitTime = atoi(value);
  18053. isSuccess = ConfigurationStatus_Accepted;
  18054. }
  18055. else
  18056. {
  18057. isSuccess = ConfigurationStatus_Rejected;
  18058. }
  18059. }
  18060. }
  18061. else
  18062. {
  18063. isSuccess = ConfigurationStatus_Rejected;
  18064. }
  18065. }
  18066. if(strcmp(key, "LightIntensity") == 0)
  18067. {
  18068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18069. {
  18070. check_ascii = value[0];
  18071. if( (check_ascii < 48) || (check_ascii > 57) )
  18072. {
  18073. isSuccess = ConfigurationStatus_Rejected;
  18074. }
  18075. else
  18076. {
  18077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18078. isSuccess = ConfigurationStatus_Accepted;
  18079. }
  18080. }
  18081. else
  18082. {
  18083. isSuccess = ConfigurationStatus_Rejected;
  18084. }
  18085. }
  18086. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18087. {
  18088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18089. {
  18090. strcpy(str, (const char*)value);
  18091. for(int i = 0; str[i]; i++)
  18092. {
  18093. str[i] = tolower(str[i]);
  18094. }
  18095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18096. isSuccess = ConfigurationStatus_Accepted;
  18097. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18098. }
  18099. else
  18100. {
  18101. isSuccess = ConfigurationStatus_Rejected;
  18102. }
  18103. }
  18104. if(strcmp(key, "LocalPreAuthorize") == 0)
  18105. {
  18106. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18107. {
  18108. strcpy(str, (const char*)value);
  18109. for(int i = 0; str[i]; i++)
  18110. {
  18111. str[i] = tolower(str[i]);
  18112. }
  18113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18114. isSuccess = ConfigurationStatus_Accepted;
  18115. }
  18116. else
  18117. {
  18118. isSuccess = ConfigurationStatus_Rejected;
  18119. }
  18120. }
  18121. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18122. {
  18123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18124. {
  18125. check_ascii = value[0];
  18126. if( (check_ascii < 48) || (check_ascii > 57) )
  18127. {
  18128. isSuccess = ConfigurationStatus_Rejected;
  18129. }
  18130. else
  18131. {
  18132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18133. isSuccess = ConfigurationStatus_Accepted;
  18134. }
  18135. }
  18136. else
  18137. {
  18138. isSuccess = ConfigurationStatus_Rejected;
  18139. }
  18140. }
  18141. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18142. {
  18143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18144. {
  18145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18146. isSuccess = ConfigurationStatus_Accepted;
  18147. }
  18148. else
  18149. {
  18150. isSuccess = ConfigurationStatus_Rejected;
  18151. }
  18152. }
  18153. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18154. {
  18155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18156. {
  18157. check_ascii = value[0];
  18158. if( (check_ascii < 48) || (check_ascii > 57) )
  18159. {
  18160. isSuccess = ConfigurationStatus_Rejected;
  18161. }
  18162. else
  18163. {
  18164. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18166. isSuccess = ConfigurationStatus_Accepted;
  18167. }
  18168. }
  18169. else
  18170. {
  18171. isSuccess = ConfigurationStatus_Rejected;
  18172. }
  18173. }
  18174. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18175. {
  18176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18177. {
  18178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18179. isSuccess = ConfigurationStatus_Accepted;
  18180. }
  18181. else
  18182. {
  18183. isSuccess = ConfigurationStatus_Rejected;
  18184. }
  18185. }
  18186. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18187. {
  18188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18189. {
  18190. check_ascii = value[0];
  18191. if( (check_ascii < 48) || (check_ascii > 57) )
  18192. {
  18193. isSuccess = ConfigurationStatus_Rejected;
  18194. }
  18195. else
  18196. {
  18197. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18199. isSuccess = ConfigurationStatus_Accepted;
  18200. }
  18201. }
  18202. else
  18203. {
  18204. isSuccess = ConfigurationStatus_Rejected;
  18205. }
  18206. }
  18207. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18208. {
  18209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18210. {
  18211. check_ascii = value[0];
  18212. if( (check_ascii < 48) || (check_ascii > 57) )
  18213. {
  18214. isSuccess = ConfigurationStatus_Rejected;
  18215. }
  18216. else
  18217. {
  18218. if((atoi(value) == 0) || (atoi(value) >= 3))
  18219. {
  18220. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18222. isSuccess = ConfigurationStatus_Accepted;
  18223. }
  18224. else
  18225. {
  18226. isSuccess = ConfigurationStatus_Rejected;
  18227. }
  18228. }
  18229. }
  18230. else
  18231. {
  18232. isSuccess = ConfigurationStatus_Rejected;
  18233. }
  18234. }
  18235. if(strcmp(key, "MinimumStatusDuration") == 0)
  18236. {
  18237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18238. {
  18239. check_ascii = value[0];
  18240. if( (check_ascii < 48) || (check_ascii > 57) )
  18241. {
  18242. isSuccess = ConfigurationStatus_Rejected;
  18243. }
  18244. else
  18245. {
  18246. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18247. {
  18248. isSuccess = ConfigurationStatus_Rejected;
  18249. }
  18250. else
  18251. {
  18252. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18254. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18255. isSuccess = ConfigurationStatus_Accepted;
  18256. }
  18257. }
  18258. }
  18259. else
  18260. {
  18261. isSuccess = ConfigurationStatus_Rejected;
  18262. }
  18263. }
  18264. if(strcmp(key, "NumberOfConnectors") == 0)
  18265. {
  18266. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18267. {
  18268. check_ascii = value[0];
  18269. if( (check_ascii < 48) || (check_ascii > 57) )
  18270. {
  18271. isSuccess = ConfigurationStatus_Rejected;
  18272. }
  18273. else
  18274. {
  18275. //Charger.ResetRetries = Integer.parseInt(value);
  18276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18277. isSuccess = ConfigurationStatus_Accepted;
  18278. }
  18279. }
  18280. else
  18281. {
  18282. isSuccess = ConfigurationStatus_Rejected;
  18283. }
  18284. }
  18285. if(strcmp(key, "ResetRetries") == 0)
  18286. {
  18287. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18288. {
  18289. check_ascii = value[0];
  18290. if( (check_ascii < 48) || (check_ascii > 57) )
  18291. {
  18292. isSuccess = ConfigurationStatus_Rejected;
  18293. }
  18294. else
  18295. {
  18296. //Charger.ResetRetries = Integer.parseInt(value);
  18297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18298. isSuccess = ConfigurationStatus_Accepted;
  18299. }
  18300. }
  18301. else
  18302. {
  18303. isSuccess = ConfigurationStatus_Rejected;
  18304. }
  18305. }
  18306. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18307. {
  18308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18309. {
  18310. strcpy(str, (const char*)value);
  18311. for(int i = 0; str[i]; i++)
  18312. {
  18313. str[i] = tolower(str[i]);
  18314. }
  18315. if(strcmp(str, "notapplicable")== 0)
  18316. {
  18317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18318. isSuccess = ConfigurationStatus_Accepted;
  18319. }
  18320. else if(strcmp(str, "unknown")== 0)
  18321. {
  18322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18323. isSuccess = ConfigurationStatus_Accepted;
  18324. }
  18325. else if(strcmp(str, "rst")== 0)
  18326. {
  18327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18328. isSuccess = ConfigurationStatus_Accepted;
  18329. }
  18330. else if(strcmp(str, "rts")== 0)
  18331. {
  18332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18333. isSuccess = ConfigurationStatus_Accepted;
  18334. }
  18335. else if(strcmp(str, "srt")== 0)
  18336. {
  18337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18338. isSuccess = ConfigurationStatus_Accepted;
  18339. }
  18340. else if(strcmp(str, "str")== 0)
  18341. {
  18342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18343. isSuccess = ConfigurationStatus_Accepted;
  18344. }
  18345. else if(strcmp(str, "trs")== 0)
  18346. {
  18347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18348. isSuccess = ConfigurationStatus_Accepted;
  18349. }
  18350. else if(strcmp(str, "tsr")== 0)
  18351. {
  18352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18353. isSuccess = ConfigurationStatus_Accepted;
  18354. }
  18355. else
  18356. {
  18357. isSuccess = ConfigurationStatus_Rejected;
  18358. }
  18359. }
  18360. else
  18361. {
  18362. isSuccess = ConfigurationStatus_Rejected;
  18363. }
  18364. }
  18365. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18366. {
  18367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18368. {
  18369. check_ascii = value[0];
  18370. if( (check_ascii < 48) || (check_ascii > 57) )
  18371. {
  18372. isSuccess = ConfigurationStatus_Rejected;
  18373. }
  18374. else
  18375. {
  18376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18377. isSuccess = ConfigurationStatus_Accepted;
  18378. }
  18379. }
  18380. else
  18381. {
  18382. isSuccess = ConfigurationStatus_Rejected;
  18383. }
  18384. }
  18385. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18386. {
  18387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18388. {
  18389. strcpy(str, (const char*)value);
  18390. for(int i = 0; str[i]; i++)
  18391. {
  18392. str[i] = tolower(str[i]);
  18393. }
  18394. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18396. isSuccess = ConfigurationStatus_Accepted;
  18397. }
  18398. else
  18399. {
  18400. isSuccess = ConfigurationStatus_Rejected;
  18401. }
  18402. }
  18403. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18404. {
  18405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18406. {
  18407. strcpy(str, (const char*)value);
  18408. for(int i = 0; str[i]; i++)
  18409. {
  18410. str[i] = tolower(str[i]);
  18411. }
  18412. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18414. isSuccess = ConfigurationStatus_Accepted;
  18415. }
  18416. else
  18417. {
  18418. isSuccess = ConfigurationStatus_Rejected;
  18419. }
  18420. }
  18421. if(strcmp(key, "StopTxnAlignedData") == 0)
  18422. {
  18423. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18424. {
  18425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18426. isSuccess = ConfigurationStatus_Accepted;
  18427. }
  18428. else
  18429. {
  18430. isSuccess = ConfigurationStatus_Rejected;
  18431. }
  18432. }
  18433. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18434. {
  18435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18436. {
  18437. check_ascii = value[0];
  18438. if( (check_ascii < 48) || (check_ascii > 57) )
  18439. {
  18440. isSuccess = ConfigurationStatus_Rejected;
  18441. }
  18442. else
  18443. {
  18444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18445. isSuccess = ConfigurationStatus_Accepted;
  18446. }
  18447. }
  18448. else
  18449. {
  18450. isSuccess = ConfigurationStatus_Rejected;
  18451. }
  18452. }
  18453. if(strcmp(key, "StopTxnSampledData") == 0)
  18454. {
  18455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18456. {
  18457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18458. isSuccess = ConfigurationStatus_Accepted;
  18459. }
  18460. else
  18461. {
  18462. isSuccess = ConfigurationStatus_Rejected;
  18463. }
  18464. }
  18465. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18466. {
  18467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18468. {
  18469. check_ascii = value[0];
  18470. if( (check_ascii < 48) || (check_ascii > 57) )
  18471. {
  18472. isSuccess = ConfigurationStatus_Rejected;
  18473. }
  18474. else
  18475. {
  18476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18477. isSuccess = ConfigurationStatus_Accepted;
  18478. }
  18479. }
  18480. else
  18481. {
  18482. isSuccess = ConfigurationStatus_Rejected;
  18483. }
  18484. }
  18485. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18486. {
  18487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18488. {
  18489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18490. isSuccess = ConfigurationStatus_Accepted;
  18491. }
  18492. else
  18493. {
  18494. isSuccess = ConfigurationStatus_Rejected;
  18495. }
  18496. }
  18497. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18498. {
  18499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18500. {
  18501. check_ascii = value[0];
  18502. if( (check_ascii < 48) || (check_ascii > 57) )
  18503. {
  18504. isSuccess = ConfigurationStatus_Rejected;
  18505. }
  18506. else
  18507. {
  18508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18509. isSuccess = ConfigurationStatus_Accepted;
  18510. }
  18511. }
  18512. else
  18513. {
  18514. isSuccess = ConfigurationStatus_Rejected;
  18515. }
  18516. }
  18517. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18518. {
  18519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18520. {
  18521. check_ascii = value[0];
  18522. if( (check_ascii < 48) || (check_ascii > 57) )
  18523. {
  18524. isSuccess = ConfigurationStatus_Rejected;
  18525. }
  18526. else
  18527. {
  18528. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18530. TransactionMessageAttemptsValue = atoi(value);
  18531. isSuccess = ConfigurationStatus_Accepted;
  18532. }
  18533. }
  18534. else
  18535. {
  18536. isSuccess = ConfigurationStatus_Rejected;
  18537. }
  18538. }
  18539. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18540. {
  18541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18542. {
  18543. check_ascii = value[0];
  18544. if( (check_ascii < 48) || (check_ascii > 57) )
  18545. {
  18546. isSuccess = ConfigurationStatus_Rejected;
  18547. }
  18548. else
  18549. {
  18550. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18552. TransactionMessageRetryIntervalValue = atoi(value);
  18553. isSuccess = ConfigurationStatus_Accepted;
  18554. }
  18555. }
  18556. else
  18557. {
  18558. isSuccess = ConfigurationStatus_Rejected;
  18559. }
  18560. }
  18561. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18562. {
  18563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18564. {
  18565. strcpy(str, (const char*)value);
  18566. for(int i = 0; str[i]; i++)
  18567. {
  18568. str[i] = tolower(str[i]);
  18569. }
  18570. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18572. isSuccess = ConfigurationStatus_Accepted;
  18573. }
  18574. else
  18575. {
  18576. isSuccess = ConfigurationStatus_Rejected;
  18577. }
  18578. }
  18579. if(strcmp(key, "WebSocketPingInterval") == 0)
  18580. {
  18581. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18582. {
  18583. check_ascii = value[0];
  18584. if( (check_ascii < 48) || (check_ascii > 57) )
  18585. {
  18586. isSuccess = ConfigurationStatus_Rejected;
  18587. }
  18588. else
  18589. {
  18590. if((atoi(value) == 0) || (atoi(value) >= 10))
  18591. {
  18592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18593. isSuccess = ConfigurationStatus_Accepted;
  18594. }
  18595. else
  18596. isSuccess = ConfigurationStatus_Rejected;
  18597. }
  18598. }
  18599. else
  18600. {
  18601. isSuccess = ConfigurationStatus_Rejected;
  18602. }
  18603. }
  18604. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18605. {
  18606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18607. {
  18608. strcpy(str, (const char*)value);
  18609. for(int i = 0; str[i]; i++)
  18610. {
  18611. str[i] = tolower(str[i]);
  18612. }
  18613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18614. isSuccess = ConfigurationStatus_Accepted;
  18615. }
  18616. else
  18617. {
  18618. isSuccess = ConfigurationStatus_Rejected;
  18619. }
  18620. }
  18621. if(strcmp(key, "AuthorizationKey") == 0)
  18622. {
  18623. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18624. {
  18625. strcpy(str, (const char*)value);
  18626. int strlength = strlen(str);
  18627. char capture[3];
  18628. char stackItem = 0;
  18629. char password[21] = {0};
  18630. printf("String length: %d\n", strlength);
  18631. for(int idx=0; idx<(strlength/2); idx++)
  18632. {
  18633. capture[0] = str[(idx*2)];
  18634. capture[1] = str[(idx*2)+1];
  18635. capture[2] = 0;
  18636. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18637. sprintf(password,"%s%c", password, stackItem);
  18638. }
  18639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  18640. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18641. isSuccess = ConfigurationStatus_Accepted;
  18642. }
  18643. else
  18644. {
  18645. isSuccess = ConfigurationStatus_Rejected;
  18646. }
  18647. }
  18648. if(strcmp(key, "SecurityProfile") == 0)
  18649. {
  18650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18651. {
  18652. check_ascii = value[0];
  18653. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18654. {
  18655. isSuccess = ConfigurationStatus_Rejected;
  18656. }
  18657. else if(check_ascii == 0x33)
  18658. {
  18659. isSuccess = NotSupported;
  18660. }
  18661. else
  18662. {
  18663. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18664. {
  18665. if(((check_ascii - 0x30) == 1) ||
  18666. ((check_ascii - 0x30) == 2) ||
  18667. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18668. {
  18669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18670. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18671. isSuccess = ConfigurationStatus_Accepted;
  18672. }
  18673. else
  18674. isSuccess = ConfigurationStatus_Rejected;
  18675. }
  18676. else
  18677. isSuccess = ConfigurationStatus_Rejected;
  18678. }
  18679. }
  18680. else
  18681. {
  18682. isSuccess = ConfigurationStatus_Rejected;
  18683. }
  18684. }
  18685. if(strcmp(key, "DefaultPrice") == 0)
  18686. {
  18687. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18688. {
  18689. strcpy(str, (const char*)value);
  18690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18691. isSuccess = ConfigurationStatus_Accepted;
  18692. }
  18693. else
  18694. {
  18695. isSuccess = ConfigurationStatus_Rejected;
  18696. }
  18697. }
  18698. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18699. {
  18700. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18701. {
  18702. strcpy(str, (const char*)value);
  18703. for(int i = 0; str[i]; i++)
  18704. {
  18705. str[i] = tolower(str[i]);
  18706. }
  18707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18708. isSuccess = ConfigurationStatus_Accepted;
  18709. }
  18710. else
  18711. {
  18712. isSuccess = ConfigurationStatus_Rejected;
  18713. }
  18714. }
  18715. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18716. {
  18717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18718. {
  18719. strcpy(str, (const char*)value);
  18720. for(int i = 0; str[i]; i++)
  18721. {
  18722. str[i] = tolower(str[i]);
  18723. }
  18724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18725. isSuccess = ConfigurationStatus_Accepted;
  18726. }
  18727. else
  18728. {
  18729. isSuccess = ConfigurationStatus_Rejected;
  18730. }
  18731. }
  18732. if(strcmp(key, "TimeOffset") == 0)
  18733. {
  18734. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18735. {
  18736. strcpy(str, (const char*)value);
  18737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18738. isSuccess = ConfigurationStatus_Accepted;
  18739. }
  18740. else
  18741. {
  18742. isSuccess = ConfigurationStatus_Rejected;
  18743. }
  18744. }
  18745. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18746. {
  18747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18748. {
  18749. strcpy(str, (const char*)value);
  18750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18751. isSuccess = ConfigurationStatus_Accepted;
  18752. }
  18753. else
  18754. {
  18755. isSuccess = ConfigurationStatus_Rejected;
  18756. }
  18757. }
  18758. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18759. {
  18760. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18761. {
  18762. strcpy(str, (const char*)value);
  18763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18764. isSuccess = ConfigurationStatus_Accepted;
  18765. }
  18766. else
  18767. {
  18768. isSuccess = ConfigurationStatus_Rejected;
  18769. }
  18770. }
  18771. if(strcmp(key, "SystemUptimeSec") == 0)
  18772. {
  18773. isSuccess = NotSupported;
  18774. }
  18775. if(strcmp(key, "FreeVend") == 0)
  18776. {
  18777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18778. {
  18779. strcpy(str, (const char*)value);
  18780. for(int i = 0; str[i]; i++)
  18781. {
  18782. str[i] = tolower(str[i]);
  18783. }
  18784. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18786. isSuccess = ConfigurationStatus_Accepted;
  18787. }
  18788. else
  18789. {
  18790. isSuccess = ConfigurationStatus_Rejected;
  18791. }
  18792. }
  18793. if(strcmp(key, "FreeVendIdtag") == 0)
  18794. {
  18795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18796. {
  18797. strcpy(str, (const char*)value);
  18798. if(strlen(str) <= 20)
  18799. {
  18800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18801. isSuccess = ConfigurationStatus_Accepted;
  18802. }
  18803. else
  18804. {
  18805. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18806. isSuccess = ConfigurationStatus_Rejected;
  18807. }
  18808. }
  18809. else
  18810. {
  18811. isSuccess = ConfigurationStatus_Rejected;
  18812. }
  18813. }
  18814. if(strcmp(key, "OcppServer") == 0)
  18815. {
  18816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18817. {
  18818. strcpy(str, (const char*)value);
  18819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18820. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18821. isSuccess = ConfigurationStatus_Accepted;
  18822. }
  18823. else
  18824. {
  18825. isSuccess = ConfigurationStatus_Rejected;
  18826. }
  18827. }
  18828. if(strcmp(key, "MaintainServer") == 0)
  18829. {
  18830. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18831. {
  18832. strcpy(str, (const char*)value);
  18833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18834. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18835. isSuccess = ConfigurationStatus_Accepted;
  18836. }
  18837. else
  18838. {
  18839. isSuccess = ConfigurationStatus_Rejected;
  18840. }
  18841. }
  18842. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18843. {
  18844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18845. {
  18846. strcpy(str, (const char*)value);
  18847. for(int i = 0; str[i]; i++)
  18848. {
  18849. str[i] = tolower(str[i]);
  18850. }
  18851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18852. isSuccess = ConfigurationStatus_Accepted;
  18853. }
  18854. else
  18855. {
  18856. isSuccess = ConfigurationStatus_Rejected;
  18857. }
  18858. }
  18859. if(strcmp(key, "StatusNotificationInterval") == 0)
  18860. {
  18861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18862. {
  18863. check_ascii = value[0];
  18864. if( (check_ascii < 48) || (check_ascii > 57) )
  18865. {
  18866. isSuccess = ConfigurationStatus_Rejected;
  18867. }
  18868. else
  18869. {
  18870. if((atoi(value) == 0) || (atoi(value) >= 10))
  18871. {
  18872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18873. isSuccess = ConfigurationStatus_Accepted;
  18874. }
  18875. else
  18876. isSuccess = ConfigurationStatus_Rejected;
  18877. }
  18878. }
  18879. else
  18880. {
  18881. isSuccess = ConfigurationStatus_Rejected;
  18882. }
  18883. }
  18884. if(strcmp(key, "PreAuthAmount") == 0)
  18885. {
  18886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18887. {
  18888. check_ascii = value[0];
  18889. if( (check_ascii < 48) || (check_ascii > 57) )
  18890. {
  18891. isSuccess = ConfigurationStatus_Rejected;
  18892. }
  18893. else
  18894. {
  18895. if(atof(value) >= 0)
  18896. {
  18897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18898. isSuccess = ConfigurationStatus_Accepted;
  18899. }
  18900. else
  18901. isSuccess = ConfigurationStatus_Rejected;
  18902. }
  18903. }
  18904. else
  18905. {
  18906. isSuccess = ConfigurationStatus_Rejected;
  18907. }
  18908. }
  18909. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  18910. {
  18911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  18912. {
  18913. check_ascii = value[0];
  18914. if( (check_ascii < 48) || (check_ascii > 57) )
  18915. {
  18916. isSuccess = ConfigurationStatus_Rejected;
  18917. }
  18918. else
  18919. {
  18920. if(atoi(value) >= 0)
  18921. {
  18922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  18923. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  18924. isSuccess = ConfigurationStatus_Accepted;
  18925. }
  18926. else
  18927. isSuccess = ConfigurationStatus_Rejected;
  18928. }
  18929. }
  18930. else
  18931. {
  18932. isSuccess = ConfigurationStatus_Rejected;
  18933. }
  18934. }
  18935. if(strcmp(key, "PowerSharingServerIP") == 0)
  18936. {
  18937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  18938. {
  18939. strcpy(str, (const char*)value);
  18940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  18941. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  18942. isSuccess = ConfigurationStatus_Accepted;
  18943. }
  18944. else
  18945. {
  18946. isSuccess = ConfigurationStatus_Rejected;
  18947. }
  18948. }
  18949. if(strcmp(key, "EVCCID_PREFIX") == 0)
  18950. {
  18951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  18952. {
  18953. strcpy(str, (const char*)value);
  18954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  18955. isSuccess = ConfigurationStatus_Accepted;
  18956. }
  18957. else
  18958. {
  18959. isSuccess = ConfigurationStatus_Rejected;
  18960. }
  18961. }
  18962. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  18963. {
  18964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  18965. {
  18966. if(atoi(value) > modelnameInfo.ratedPower)
  18967. {
  18968. isSuccess = ConfigurationStatus_Rejected;
  18969. }
  18970. else{
  18971. strcpy(str, (const char*)value);
  18972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  18973. isSuccess = ConfigurationStatus_Accepted;
  18974. }
  18975. }
  18976. else
  18977. {
  18978. isSuccess = ConfigurationStatus_Rejected;
  18979. }
  18980. }
  18981. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  18982. {
  18983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  18984. {
  18985. if((atoi(value) != 0) && (atoi(value) < 5))
  18986. {
  18987. isSuccess = ConfigurationStatus_Rejected;
  18988. }
  18989. else{
  18990. strcpy(str, (const char*)value);
  18991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  18992. isSuccess = ConfigurationStatus_Accepted;
  18993. }
  18994. }
  18995. else
  18996. {
  18997. isSuccess = ConfigurationStatus_Rejected;
  18998. }
  18999. }
  19000. if(strcmp(key, "CpoName") == 0)
  19001. {
  19002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19003. {
  19004. strcpy(str, (const char*)value);
  19005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19006. isSuccess = ConfigurationStatus_Accepted;
  19007. }
  19008. else
  19009. {
  19010. isSuccess = ConfigurationStatus_Rejected;
  19011. }
  19012. }
  19013. #if 0
  19014. //For OCPP Test Case
  19015. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19016. {
  19017. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19018. {
  19019. strcpy(str, (const char*)value);
  19020. for(int i = 0; str[i]; i++)
  19021. {
  19022. str[i] = tolower(str[i]);
  19023. }
  19024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19025. isSuccess = ConfigurationStatus_Accepted;
  19026. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19027. }
  19028. else
  19029. {
  19030. isSuccess = ConfigurationStatus_Rejected;
  19031. }
  19032. }
  19033. #endif
  19034. #if 1
  19035. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19036. {
  19037. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19038. {
  19039. strcpy(str, (const char*)value);
  19040. for(int i = 0; str[i]; i++)
  19041. {
  19042. str[i] = tolower(str[i]);
  19043. }
  19044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19045. isSuccess = ConfigurationStatus_Accepted;
  19046. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19047. }
  19048. else
  19049. {
  19050. isSuccess = ConfigurationStatus_Rejected;
  19051. }
  19052. }
  19053. #endif
  19054. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19055. {
  19056. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19057. {
  19058. check_ascii = value[0];
  19059. if( (check_ascii < 48) || (check_ascii > 57) )
  19060. {
  19061. isSuccess = ConfigurationStatus_Rejected;
  19062. }
  19063. else
  19064. {
  19065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19066. isSuccess = ConfigurationStatus_Accepted;
  19067. }
  19068. }
  19069. else
  19070. {
  19071. isSuccess = ConfigurationStatus_Rejected;
  19072. }
  19073. }
  19074. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19075. {
  19076. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19077. {
  19078. check_ascii = value[0];
  19079. if( (check_ascii < 48) || (check_ascii > 57) )
  19080. {
  19081. isSuccess = ConfigurationStatus_Rejected;
  19082. }
  19083. else
  19084. {
  19085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19086. isSuccess = ConfigurationStatus_Accepted;
  19087. }
  19088. }
  19089. else
  19090. {
  19091. isSuccess = ConfigurationStatus_Rejected;
  19092. }
  19093. }
  19094. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19095. {
  19096. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19097. {
  19098. strcpy(str, (const char*)value);
  19099. for(int i = 0; str[i]; i++)
  19100. {
  19101. str[i] = tolower(str[i]);
  19102. }
  19103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19104. isSuccess = ConfigurationStatus_Accepted;
  19105. }
  19106. else
  19107. {
  19108. isSuccess = ConfigurationStatus_Rejected;
  19109. }
  19110. }
  19111. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19112. {
  19113. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19114. {
  19115. check_ascii = value[0];
  19116. if( (check_ascii < 48) || (check_ascii > 57) )
  19117. {
  19118. isSuccess = ConfigurationStatus_Rejected;
  19119. }
  19120. else
  19121. {
  19122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19123. isSuccess = ConfigurationStatus_Accepted;
  19124. }
  19125. }
  19126. else
  19127. {
  19128. isSuccess = ConfigurationStatus_Rejected;
  19129. }
  19130. }
  19131. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19132. {
  19133. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19134. {
  19135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19136. isSuccess = ConfigurationStatus_Accepted;
  19137. }
  19138. else
  19139. {
  19140. isSuccess = ConfigurationStatus_Rejected;
  19141. }
  19142. }
  19143. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19144. {
  19145. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19146. {
  19147. check_ascii = value[0];
  19148. if( (check_ascii < 48) || (check_ascii > 57) )
  19149. {
  19150. isSuccess = ConfigurationStatus_Rejected;
  19151. }
  19152. else
  19153. {
  19154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19155. isSuccess = ConfigurationStatus_Accepted;
  19156. }
  19157. }
  19158. else
  19159. {
  19160. isSuccess = ConfigurationStatus_Rejected;
  19161. }
  19162. }
  19163. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19164. {
  19165. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19166. {
  19167. strcpy(str, (const char*)value);
  19168. for(int i = 0; str[i]; i++)
  19169. {
  19170. str[i] = tolower(str[i]);
  19171. }
  19172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19173. isSuccess = ConfigurationStatus_Accepted;
  19174. }
  19175. else
  19176. {
  19177. isSuccess = ConfigurationStatus_Rejected;
  19178. }
  19179. }
  19180. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19181. {
  19182. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19183. {
  19184. check_ascii = value[0];
  19185. if( (check_ascii < 48) || (check_ascii > 57) )
  19186. {
  19187. isSuccess = ConfigurationStatus_Rejected;
  19188. }
  19189. else
  19190. {
  19191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19192. isSuccess = ConfigurationStatus_Accepted;
  19193. }
  19194. }
  19195. else
  19196. {
  19197. isSuccess = ConfigurationStatus_Rejected;
  19198. }
  19199. }
  19200. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19201. return isSuccess;
  19202. }
  19203. int TransactionMessageAttemptsGet(void)
  19204. {
  19205. return TransactionMessageAttemptsValue;
  19206. }
  19207. int FirstHeartBeatResponse(void)
  19208. {
  19209. return FirstHeartBeat;
  19210. }
  19211. int TransactionMessageRetryIntervalGet(void)
  19212. {
  19213. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19214. }
  19215. int ReadHttpStatus(int sock)
  19216. {
  19217. //char c;
  19218. char buff[1024]="",*ptr=buff+1;
  19219. int bytes_received, status;
  19220. DEBUG_INFO("Begin Response ..\n");
  19221. while((bytes_received = recv(sock, ptr, 1, 0))){
  19222. if(bytes_received==-1){
  19223. perror("ReadHttpStatus");
  19224. exit(1);
  19225. }
  19226. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19227. ptr++;
  19228. }
  19229. *ptr=0;
  19230. ptr=buff+1;
  19231. sscanf(ptr,"%*s %d ", &status);
  19232. DEBUG_INFO("%s\n",ptr);
  19233. DEBUG_INFO("status=%d\n",status);
  19234. DEBUG_INFO("End Response ..\n");
  19235. return (bytes_received>0)?status:0;
  19236. }
  19237. //the only filed that it parsed is 'Content-Length'
  19238. int ParseHeader(int sock)
  19239. {
  19240. //char c;
  19241. char buff[1024]="",*ptr=buff+4;
  19242. int bytes_received;
  19243. DEBUG_INFO("Begin HEADER ..\n");
  19244. while((bytes_received = recv(sock, ptr, 1, 0))){
  19245. if(bytes_received==-1){
  19246. perror("Parse Header");
  19247. exit(1);
  19248. }
  19249. if(
  19250. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19251. (ptr[-1]=='\r') && (*ptr=='\n' )
  19252. ) break;
  19253. ptr++;
  19254. }
  19255. *ptr=0;
  19256. ptr=buff+4;
  19257. //printf("%s",ptr);
  19258. if(bytes_received){
  19259. ptr=strstr(ptr,"Content-Length:");
  19260. if(ptr){
  19261. sscanf(ptr,"%*s %d",&bytes_received);
  19262. }else
  19263. bytes_received=-1; //unknown size
  19264. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19265. }
  19266. DEBUG_INFO("End HEADER ..\n");
  19267. return bytes_received ;
  19268. }
  19269. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19270. {
  19271. int result = TRUE;
  19272. char rmFileCmd[100]={0};
  19273. char FilePath[100]={0};
  19274. char ftpbuf[200];
  19275. int systemresult;
  19276. sprintf(FilePath,"/mnt/%s",filename);
  19277. system("ping 8.8.8.8 &");
  19278. if((access(FilePath,F_OK))!=-1)
  19279. {
  19280. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19281. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19282. system(rmFileCmd);
  19283. }
  19284. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19285. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19286. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19287. systemresult = system(ftpbuf);
  19288. if(systemresult != 0)
  19289. {
  19290. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19291. result = FALSE;
  19292. }
  19293. system("pkill ping");
  19294. return result;
  19295. }
  19296. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19297. {
  19298. int result = TRUE;
  19299. char rmFileCmd[100]={0};
  19300. char FilePath[100]={0};
  19301. char ftpbuf[200];
  19302. int systemresult;
  19303. sprintf(FilePath,"/mnt/%s",filename);
  19304. system("ping 8.8.8.8 &");
  19305. if((access(FilePath,F_OK))!=-1)
  19306. {
  19307. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19308. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19309. system(rmFileCmd);
  19310. }
  19311. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19312. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19313. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19314. systemresult = system(ftpbuf);
  19315. if(systemresult != 0)
  19316. {
  19317. DEBUG_WARN("scp error!\n");
  19318. result = FALSE;
  19319. }
  19320. system("pkill ping");
  19321. return result;
  19322. }
  19323. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19324. {
  19325. int result = TRUE;
  19326. char rmFileCmd[100]={0};
  19327. char FilePath[100]={0};
  19328. char ftpbuf[200];
  19329. int systemresult;
  19330. sprintf(FilePath,"/mnt/%s",filename);
  19331. system("ping 8.8.8.8 &");
  19332. if((access(FilePath,F_OK))!=-1)
  19333. {
  19334. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19335. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19336. system(rmFileCmd);
  19337. }
  19338. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19339. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  19340. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19341. systemresult = system(ftpbuf);
  19342. if(systemresult != 0)
  19343. {
  19344. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  19345. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19346. systemresult = system(ftpbuf);
  19347. if(systemresult != 0)
  19348. {
  19349. DEBUG_WARN("FTP download fail!\n");
  19350. result = FALSE;
  19351. }
  19352. }
  19353. system("pkill ping");
  19354. return result;
  19355. }
  19356. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19357. {
  19358. char rmFileCmd[100]={0};
  19359. char FilePath[100]={0};
  19360. char buf[512];
  19361. int systemresult = 0;
  19362. //DEBUG_INFO("filename=%s\n",filename);
  19363. //DEBUG_INFO("url=%s\n",url);
  19364. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19365. if((access(FilePath,F_OK))!=-1)
  19366. {
  19367. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19368. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19369. system(rmFileCmd);
  19370. }
  19371. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19372. if(fp == NULL)
  19373. {
  19374. DEBUG_INFO("log is NULL\n");
  19375. return FALSE;
  19376. }
  19377. else
  19378. {
  19379. fprintf(fp, "%s\n", url);
  19380. fprintf(fp, "%s\n", filename);
  19381. fclose(fp);
  19382. }
  19383. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19384. if(phpFP == NULL)
  19385. {
  19386. DEBUG_INFO("PHP upload fail.\n");
  19387. return FALSE;
  19388. }
  19389. else
  19390. {
  19391. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19392. {
  19393. if(strstr(buf, "result") != NULL)
  19394. {
  19395. sscanf(buf, "result: %d", &systemresult);
  19396. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19397. }
  19398. }
  19399. pclose(phpFP);
  19400. }
  19401. if(systemresult != 1)
  19402. {
  19403. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19404. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19405. if(phpFP == NULL)
  19406. {
  19407. DEBUG_WARN("PHP PUT upload fail.\n");
  19408. return FALSE;
  19409. }
  19410. else
  19411. {
  19412. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19413. {
  19414. if(strstr(buf, "result") != NULL)
  19415. {
  19416. sscanf(buf, "result: %d", &systemresult);
  19417. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19418. }
  19419. }
  19420. pclose(phpFP);
  19421. }
  19422. }
  19423. if(systemresult != 1)
  19424. {
  19425. DEBUG_WARN("PHP PUT upload fail.\n");
  19426. return FALSE;
  19427. }
  19428. return TRUE;
  19429. }
  19430. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19431. {
  19432. int result = FALSE;
  19433. char ftpbuf[200];
  19434. int systemresult;
  19435. /*
  19436. // Domaind name transfer to IP address
  19437. struct hostent* server;
  19438. char *IPbuffer;
  19439. server = gethostbyname(location);
  19440. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19441. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19442. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19443. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19444. systemresult = system(ftpbuf);
  19445. if(systemresult != 0)
  19446. {
  19447. DEBUG_INFO("ftpput error!\n");
  19448. }
  19449. else
  19450. {
  19451. result = TRUE;
  19452. DEBUG_INFO("ftpput OK!\n");
  19453. }
  19454. return result;
  19455. }
  19456. int GetOcppServerURL()
  19457. {
  19458. int result = FALSE;
  19459. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19460. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19461. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19462. struct yuarel url;
  19463. char urlStr[512];
  19464. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19465. {
  19466. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19467. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19468. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19469. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19470. if(yuarel_parse(&url, urlStr) != -1)
  19471. {
  19472. sprintf(OcppProtocol, "%s", url.scheme);
  19473. sprintf(OcppHost, "%s", url.host);
  19474. if(url.path == NULL)
  19475. OcppTempPath[0] = '\0';
  19476. else
  19477. {
  19478. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19479. {
  19480. sprintf(OcppTempPath, "%s/", url.path);
  19481. }
  19482. else
  19483. {
  19484. sprintf(OcppTempPath, "%s", url.path);
  19485. }
  19486. }
  19487. if(url.port == 0)
  19488. {
  19489. if(strcmp(OcppProtocol, "wss") == 0)
  19490. OcppPort = 443;
  19491. else
  19492. OcppPort = 80;
  19493. }
  19494. else
  19495. OcppPort = url.port;
  19496. result = TRUE;
  19497. }
  19498. }
  19499. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19500. {
  19501. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19502. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19503. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19504. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19505. if(yuarel_parse(&url, urlStr) != -1)
  19506. {
  19507. sprintf(OcppProtocol, "%s", url.scheme);
  19508. sprintf(OcppHost, "%s", url.host);
  19509. if(url.path == NULL)
  19510. OcppTempPath[0] = '\0';
  19511. else
  19512. sprintf(OcppTempPath, "%s", url.path);
  19513. if(url.port == 0)
  19514. {
  19515. if(strcmp(OcppProtocol, "wss") == 0)
  19516. OcppPort = 443;
  19517. else
  19518. OcppPort = 80;
  19519. }
  19520. else
  19521. OcppPort = url.port;
  19522. result = TRUE;
  19523. }
  19524. }
  19525. else
  19526. {
  19527. strcpy(OcppHost,"");
  19528. }
  19529. return result;
  19530. }
  19531. int GetOcppPath()
  19532. {
  19533. int result = FALSE;
  19534. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19535. {
  19536. if(OcppTempPath == NULL)
  19537. {
  19538. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19539. }
  19540. else
  19541. {
  19542. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19543. }
  19544. result = TRUE;
  19545. goto End;
  19546. }
  19547. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19548. {
  19549. if(OcppTempPath == NULL)
  19550. {
  19551. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19552. }
  19553. else
  19554. {
  19555. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19556. }
  19557. result = TRUE;
  19558. goto End;
  19559. }
  19560. else
  19561. {
  19562. strcpy(OcppPath,"");
  19563. }
  19564. End:
  19565. return result;
  19566. }
  19567. int GetOcppPort()
  19568. {
  19569. return OcppPort;
  19570. }
  19571. int GetOcppConnStatus(void)
  19572. {
  19573. return ShmOCPP16Data->OcppConnStatus;
  19574. }
  19575. void SetOcppConnStatus(uint8_t status)
  19576. {
  19577. ShmOCPP16Data->OcppConnStatus = status;
  19578. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19579. }
  19580. int GetHeartBeatWithNOResponse(void)
  19581. {
  19582. return HeartBeatWithNOResponse;
  19583. }
  19584. void SetHeartBeatWithNOResponse(void)
  19585. {
  19586. HeartBeatWithNOResponse = 0;
  19587. }
  19588. void GetStartTransactionIdTag(int gun_index)
  19589. {
  19590. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19591. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19592. }
  19593. int GetStartTransactionId(int gun_index)
  19594. {
  19595. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19596. }
  19597. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19598. {
  19599. char ch;
  19600. FILE *fptr1;
  19601. int temptransactionId;
  19602. char str[100]={0};
  19603. temptransactionId = 0;
  19604. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19605. {
  19606. DEBUG_INFO("IdTag is empty.\n");
  19607. return temptransactionId;
  19608. }
  19609. /*------ Read the file ----------------*/
  19610. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19611. if (!fptr1)
  19612. {
  19613. DEBUG_INFO("QueueTransactionId file open error.\n");
  19614. //printf(" File not found or unable to open the input file!!\n");
  19615. return temptransactionId;
  19616. }
  19617. ch=fgetc(fptr1);
  19618. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19619. rewind(fptr1);
  19620. if(ch!=EOF)
  19621. {
  19622. // printf("%c",ch);
  19623. while (fgets(str, 100, fptr1) != NULL)
  19624. {
  19625. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19626. if(str[0]=='\0')
  19627. {
  19628. break;
  19629. }
  19630. char *revbuf[8] = {0}; // Variable store string split
  19631. int num = 0;// Quantity after string split
  19632. DEBUG_INFO("Transaction queue data= %s\n", str);
  19633. splitstring(str,",",revbuf,&num); // String split
  19634. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19635. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19636. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19637. DEBUG_INFO("------------------------------\n");
  19638. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19639. {
  19640. if(isStopTransaction)
  19641. {
  19642. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19643. {
  19644. temptransactionId = atoi(revbuf[2]);
  19645. //break;
  19646. }
  19647. }
  19648. else
  19649. {
  19650. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19651. {
  19652. temptransactionId = atoi(revbuf[2]);
  19653. //break;
  19654. }
  19655. }
  19656. }
  19657. }
  19658. }
  19659. else
  19660. DEBUG_INFO("EOF\n");
  19661. fclose(fptr1);
  19662. /*------- End of reading ---------------*/
  19663. return temptransactionId;
  19664. }
  19665. void SetTransactionIdZero(int transactionId)
  19666. {
  19667. char ch;
  19668. FILE *fptr1, *fptr2;
  19669. int temptransactionId = 0;
  19670. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19671. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19672. if (!fptr1)
  19673. {
  19674. //printf(" File not found or unable to open the input file!!\n");
  19675. return ;
  19676. }
  19677. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19678. if (!fptr2)
  19679. {
  19680. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19681. fclose(fptr1);
  19682. return ;
  19683. }
  19684. ch=fgetc(fptr1);
  19685. rewind(fptr1);
  19686. if(ch!=EOF)
  19687. {
  19688. // copy all contents to the temporary file except the specific line
  19689. while (fgets(str, 100, fptr1) != NULL)
  19690. {
  19691. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19692. if(str[0]=='\0')
  19693. {
  19694. break;
  19695. }
  19696. char *revbuf[8] = {0};
  19697. int num = 0;
  19698. strcpy(strtemp, str);
  19699. splitstring(str,",",revbuf,&num);
  19700. if(revbuf[2][0] != '\0')
  19701. {
  19702. temptransactionId = atoi(revbuf[2]);
  19703. if(transactionId != temptransactionId)
  19704. {
  19705. fprintf(fptr2, "%s\n", strtemp);
  19706. }
  19707. }
  19708. }
  19709. }
  19710. fclose(fptr1);
  19711. fclose(fptr2);
  19712. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19713. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19714. /*------ Read the file ----------------*/
  19715. }
  19716. int InternetDisconnect(void)
  19717. {
  19718. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19719. }
  19720. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19721. void storeTempStopTransaction(int gun_index)
  19722. {
  19723. char guid[37]={0};
  19724. int tempIndex = 0;
  19725. char TempStopTransaction[256];
  19726. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19727. DEBUG_INFO("storeTempStopTransaction...\n");
  19728. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19729. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19730. //=========================== Stop Transaction Time ===============================================
  19731. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  19732. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19733. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19734. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19735. {
  19736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19737. {
  19738. tempIndex = ((gun_index==2) ? 1: 0);
  19739. }
  19740. else
  19741. {
  19742. tempIndex = gun_index;
  19743. }
  19744. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19745. {
  19746. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19747. {
  19748. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19749. }
  19750. }// END OF CHAdeMO_QUANTITY
  19751. }
  19752. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19753. {
  19754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19755. {
  19756. tempIndex = ((gun_index==2) ? 1: 0);
  19757. }
  19758. else
  19759. {
  19760. tempIndex = gun_index;
  19761. }
  19762. for (int index = 0; index < CCS_QUANTITY; index++)
  19763. {
  19764. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19765. {
  19766. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19767. }
  19768. }// END OF CCS_QUANTITY
  19769. }
  19770. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19771. {
  19772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19773. {
  19774. tempIndex = ((gun_index==2) ? 1: 0);
  19775. }
  19776. else
  19777. {
  19778. tempIndex = gun_index;
  19779. }
  19780. for (int index = 0; index < GB_QUANTITY; index++)
  19781. {
  19782. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19783. {
  19784. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19785. }
  19786. }// END OF GB_QUANTITY
  19787. }
  19788. else if(gunType[gun_index] == GUN_TYPE_DO)
  19789. {
  19790. tempIndex = gun_index;
  19791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19792. {
  19793. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19794. {
  19795. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19796. }
  19797. }
  19798. }
  19799. else
  19800. {
  19801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19802. {
  19803. tempIndex = 2;
  19804. }
  19805. else
  19806. {
  19807. tempIndex = gun_index;
  19808. }
  19809. for (int index = 0; index < AC_QUANTITY; index++)
  19810. {
  19811. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19812. {
  19813. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19814. }
  19815. }// END OF AC_QUANTITY
  19816. }
  19817. //======================================== Message create ==============================================
  19818. json_object *StopTransaction = json_object_new_object();
  19819. json_object *transactionDatas = json_object_new_array();
  19820. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19821. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19822. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19823. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19824. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19825. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19826. meterValueBufferQuery(gun_index, transactionDatas);
  19827. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19828. random_uuid(guid);
  19829. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19830. ,MESSAGE_TYPE_CALL
  19831. ,guid
  19832. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19833. json_object_put(StopTransaction);
  19834. // Check File "TempStopTransaction" Exist
  19835. if((access(TempStopTransaction,F_OK))!=-1)
  19836. {
  19837. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19838. fclose(fopen(TempStopTransaction, "w"));
  19839. }
  19840. else
  19841. {
  19842. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19843. FILE *log = fopen(TempStopTransaction, "w+");
  19844. if(log == NULL)
  19845. {
  19846. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19847. return ;
  19848. }
  19849. else
  19850. {
  19851. fclose(log);
  19852. }
  19853. }
  19854. //Add TempStopTransaction | Update TempStopTransaction
  19855. // open file for writing
  19856. FILE *outfile;
  19857. outfile = fopen (TempStopTransaction, "a");
  19858. //DEBUG_INFO("data = %s\n", queuedata);
  19859. fputs(queuedata, outfile);
  19860. fputs("\n", outfile);
  19861. fclose (outfile);
  19862. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19863. OCPP_updatePeriodEnergy(gun_index);
  19864. }
  19865. void checkTempStopTransaction(int gun_index)
  19866. {
  19867. FILE *fptr1;
  19868. char ch;
  19869. char str[QUEUE_MESSAGE_LENGTH]={0};
  19870. char guid[37]={0};
  19871. char tempdata[65]={0};
  19872. char connectorStr[2]={0};
  19873. char TempStopTransaction[256];
  19874. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19875. fptr1 = fopen(TempStopTransaction, "r");
  19876. //TempStopTransaction格式: 槍號,StopTransaction封包
  19877. if (!fptr1)
  19878. {
  19879. //printf(" File not found or unable to open the input file!!\n");
  19880. return ;
  19881. }
  19882. ch=fgetc(fptr1);
  19883. //printf(" Now the content of the file %s is : \n",fname);
  19884. rewind(fptr1);
  19885. if(ch!=EOF)
  19886. {
  19887. // copy all contents to the temporary file except the specific line
  19888. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19889. {
  19890. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19891. if(str[0]=='\0')
  19892. {
  19893. break;
  19894. }
  19895. //TempStopTransaction格式: 槍號,StopTransaction封包
  19896. strncpy(connectorStr, str, 1);
  19897. if(atoi(connectorStr) != (gun_index+1))
  19898. {
  19899. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19900. fclose(fptr1);
  19901. return ;
  19902. }
  19903. //random_uuid(guid);
  19904. strncpy(guid, str+6, 36); //copy guid
  19905. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19906. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19907. {
  19908. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19909. }
  19910. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19911. OCPP_insert_transaction_msg(NO, str);
  19912. memset(str,0,ARRAY_SIZE(str));
  19913. }
  19914. }
  19915. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19916. fclose(fptr1);
  19917. remove(TempStopTransaction); // remove the original file
  19918. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19919. }
  19920. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19921. {
  19922. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19923. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19924. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19925. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19926. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19927. }
  19928. void FillTransactionId(int ConnectorId, int TransactionId)
  19929. {
  19930. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19931. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  19932. }
  19933. int GetWebSocketPingInterval(void)
  19934. {
  19935. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19936. }
  19937. int GetServerSign(void)
  19938. {
  19939. return server_sign;
  19940. }
  19941. uint8_t GetOcppSecurityProfile()
  19942. {
  19943. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19944. }
  19945. void MergeCertificates()
  19946. {
  19947. char cmdBuf[2048]={0};
  19948. if(access(ROOTCA_CS,F_OK) != -1)
  19949. {
  19950. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  19951. }
  19952. else
  19953. {
  19954. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  19955. }
  19956. system(cmdBuf);
  19957. }
  19958. void GetOcppChargerBoxId(uint8_t *data)
  19959. {
  19960. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19961. }
  19962. void GetOcppSecurityPassword(uint8_t *data)
  19963. {
  19964. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19965. }
  19966. void SetOcppVersion(uint8_t *version)
  19967. {
  19968. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19969. DEBUG_INFO("ocpp version: %s\n", version);
  19970. if(strstr((char*)version, "ocpp1.6") != NULL)
  19971. {
  19972. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19973. }
  19974. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19975. {
  19976. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19977. system("pkill OcppBackend");
  19978. }
  19979. }
  19980. void SetServerSign(int value)
  19981. {
  19982. server_sign = value;
  19983. }
  19984. int GetBootNotificationInterval(void)
  19985. {
  19986. return BootNotificationInterval;
  19987. }
  19988. int GetInternetConn(void)
  19989. {
  19990. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19991. }
  19992. int GetBackendConnectionTimeout(void)
  19993. {
  19994. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19995. }
  19996. int isConnectorInitMode(int gun_index)
  19997. {
  19998. int tempIndex = 0;
  19999. int result = TRUE;
  20000. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20001. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20002. {
  20003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20004. {
  20005. tempIndex = ((gun_index==2) ? 1: 0);
  20006. }
  20007. else
  20008. {
  20009. tempIndex = gun_index;
  20010. }
  20011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20012. {
  20013. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20014. {
  20015. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20016. } //end of the same index
  20017. }//end of for CHAdeMO_QUANTITY
  20018. }
  20019. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20020. {
  20021. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20022. {
  20023. tempIndex = ((gun_index==2) ? 1: 0);
  20024. }
  20025. else
  20026. {
  20027. tempIndex = gun_index;
  20028. }
  20029. for (int index = 0; index < CCS_QUANTITY; index++)
  20030. {
  20031. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20032. {
  20033. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20034. } //end of the same index
  20035. } // end of for CCS_QUANTITY
  20036. }
  20037. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20038. {
  20039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20040. {
  20041. tempIndex = ((gun_index==2) ? 1: 0);
  20042. }
  20043. else
  20044. {
  20045. tempIndex = gun_index;
  20046. }
  20047. for (int index = 0; index < GB_QUANTITY; index++)
  20048. {
  20049. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20050. {
  20051. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20052. } //end of the same index
  20053. } // end of for GB_QUANTITY
  20054. }
  20055. else if(gunType[gun_index] == GUN_TYPE_DO)
  20056. {
  20057. tempIndex = gun_index;
  20058. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20059. {
  20060. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20061. {
  20062. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20063. } //end of the same index
  20064. }
  20065. }
  20066. else
  20067. {
  20068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20069. {
  20070. tempIndex = 2;
  20071. }
  20072. else
  20073. {
  20074. tempIndex = gun_index;
  20075. }
  20076. for (int index = 0; index < AC_QUANTITY; index++)
  20077. {
  20078. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20079. {
  20080. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20081. }//end of the same index
  20082. }//end of for AC_QUANTITY
  20083. }
  20084. return result;
  20085. }
  20086. void refreshProcDogTimer()
  20087. {
  20088. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20089. }
  20090. void InitialSystemValue(void)
  20091. {
  20092. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20093. locallistVersion=0;
  20094. BootNotificationInterval = 0;
  20095. authorizeRetryTimes = 0;
  20096. GunStatusInterval = 10;
  20097. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20098. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20099. //Hear Beat
  20100. HeartBeatWithNOResponse = 0;
  20101. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20102. FirstHeartBeat = 0;
  20103. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20104. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20105. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20106. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20107. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20108. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20109. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20110. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20111. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20112. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20113. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20114. //Status && ConnectorPlugIn Setting
  20115. Connector0PreviousSystemStatus = 99;
  20116. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20117. {
  20118. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20119. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20120. }
  20121. for (int index = 0; index < CCS_QUANTITY; index++)
  20122. {
  20123. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20124. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20125. }
  20126. for (int index = 0; index < GB_QUANTITY; index++)
  20127. {
  20128. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20129. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20130. }
  20131. for (int index = 0; index < AC_QUANTITY; index++)
  20132. {
  20133. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20134. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20135. }
  20136. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20137. {
  20138. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20139. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20140. }
  20141. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20142. {
  20143. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20144. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20145. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20146. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20147. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20148. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20149. }
  20150. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20151. refreshStartTimer(&clientTime.Heartbeat);
  20152. sleep(1);
  20153. }
  20154. void LWS_Send(char *str)
  20155. {
  20156. //=====================================================
  20157. // Check InternetConn 0: disconnected, 1: connected
  20158. //====================================================
  20159. if(GetOcppConnStatus() == 0)
  20160. {
  20161. DEBUG_INFO("offline now !!!\n");
  20162. return;
  20163. }
  20164. // Only disable isWebsocketSendable operation initiated by charger
  20165. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20166. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20167. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20168. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20169. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20170. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20171. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20172. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20173. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20174. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20175. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20176. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20177. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20178. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20179. {
  20180. isWebsocketSendable = 0;
  20181. }
  20182. pthread_mutex_lock(&lock_send);
  20183. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20184. sprintf((char *)SendBuffer, "%s", str);
  20185. SendBufLen = strlen(str);
  20186. pthread_mutex_unlock(&lock_send);
  20187. lws_callback_on_writable(wsi_client);
  20188. //lws_service(context, 0);
  20189. //sleep(1);
  20190. }
  20191. void LWS_SendNow(char *str)
  20192. {
  20193. //=====================================================
  20194. // Check InternetConn 0: disconnected, 1: connected
  20195. //====================================================
  20196. if(GetOcppConnStatus() == 0)
  20197. {
  20198. DEBUG_INFO("offline now !!!\n");
  20199. return;
  20200. }
  20201. // Only disable isWebsocketSendable operation initiated by charger
  20202. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20203. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20204. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20205. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20206. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20207. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20208. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20209. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20210. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20211. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20212. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20213. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20214. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20215. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20216. {
  20217. isWebsocketSendable = 0;
  20218. }
  20219. pthread_mutex_lock(&lock_send);
  20220. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20221. sprintf((char *)SendBuffer, "%s", str);
  20222. SendBufLen = strlen(str);
  20223. pthread_mutex_unlock(&lock_send);
  20224. lws_callback_on_writable(wsi_client);
  20225. lws_service(context, 0);
  20226. //sleep(1);
  20227. }